zoukankan      html  css  js  c++  java
  • Jpush极光推送的一些心得

     在集成极光推送的时候,test完全正常。部署到服务器后只发送一条推送之后推送不继续发送。经排查:

    • 2018-06-28 10:24:26.394 [ThreadPoolTaskExecutor-4] INFO c.j.c.connection.NettyHttpClient - - Created instance with connectionTimeout 5,000, readTimeout 30,000, maxRetryTimes 3, SSL Version TLS

    因为JPUSH在3.12.15以后的版本需要显示的调用jpushClient.close() 来关闭NettyHttpClient 

    //消息gradle推送
    compile 'cn.jpush.api:jpush-client:3.2.17'
    /**
    * 自定义按别名推送信息
    * @param days
    * @param extras
    * @param alias
    * @return
    */
    public static PushPayload sendAndroidAndAlias(String days,Map<String, String> extras, String... alias) {
    Builder builder = PushPayload.newBuilder();
    return builder
    .setPlatform(Platform.android_ios())
    .setAudience(Audience.alias(alias))
    .setMessage(Message.newBuilder()
    .setTitle(extras.get("title"))
    .setMsgContent(extras.get("msg"))
    .addExtras(extras)
    .build())
    .setOptions(Options.newBuilder()
    .setApnsProduction(false)
    .setTimeToLive(Long.valueOf(Integer.valueOf(days)*86400))
    .build())
    .setNotification(Notification.android(extras.get("msg"), extras.get("title"), extras))//后端推送。如果前端推送可以去掉
    .build();
    }
     
     
    public static PushResult sendPush(PushPayload payload) throws APIConnectionException, APIRequestException{
    JPushClient jPushClient = new JPushClient(MASTER_SECRET, APP_KEY);//定义的Jpushkey等
    System.out.print("jPushClient 开始调用!!!!!!!!!!!!!"+payload.toString());
    PushResult pushResult = jPushClient.sendPush(payload);
    jPushClient.close();
    System.out.print("jPushClient 调用完毕并且关闭NativeHttpClient");
    return pushResult;
    }




      //推送别名推送
    @Test
    public void sendAndroidAndAlias() {
            Map<String,String> parms = new HashMap<>();
    parms.put("id","test");
    parms.put("type","test");
    parms.put("msg","test");
    parms.put("title","test");
        //jPush用户推送
        String[] toId = new String[1];
        toId[0] = userId.toString();
            try {
    PushPayload data = MsgPushUtils.
    sendAndroidAndAlias("1",parms,userIDs);
    //                MsgPushUtils.sendPushTryCatch(data,log);
    MsgPushUtils.sendPush(data);
    } catch (APIConnectionException e) {
    log.error("Connection error. Should retry later. ", e);
    } catch (APIRequestException e) {
    log.error("Error response from JPush server. Should review and fix it. ", e);
    log.info("HTTP Status: " + e.getStatus());
    log.info("Error Code: " + e.getErrorCode());
    log.info("Error Message: " + e.getErrorMessage());
    }
     
     
     
     
     
  • 相关阅读:
    [CodeForces]Codeforces Round #429 (Div. 2) ABC(待补)
    About Me
    2018-06-14
    Codeforces Codeforces Round #484 (Div. 2) E. Billiard
    Codeforces Codeforces Round #484 (Div. 2) D. Shark
    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes
    Codeforces Avito Code Challenge 2018 D. Bookshelves
    Codeforces Round #485 (Div. 2) D. Fair
    Codeforces Round #485 (Div. 2) F. AND Graph
  • 原文地址:https://www.cnblogs.com/java-xz/p/9238207.html
Copyright © 2011-2022 走看看