• 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());
    }
     
     
     
     
     
  • 相关阅读:
    Jmeter索引贴
    Jenkins Jmeter Tomcat Html实施方案
    转载:几种方法来实现scp拷贝时无需输入密码
    Jenkins Jmeter Ant Email Html实施方案
    zabbix3.4 zabbix-server zabbix-agent zabbix-java-gateway安装 配置
    shell () {}
    Vuser中常用的C语言函数
    loadrunner C语言循环for while do...while
    loadrunner C语言switch case
    linux系统扫描技术及安全防范--------待补全
  • 原文地址:https://www.cnblogs.com/java-xz/p/9238207.html
Copyright © 2020-2023  润新知