admin
2019-03-13 69bee82b81626b82b7f39f0e459e4f56b1699b51
fanli/src/main/java/com/yeshi/fanli/util/push/IOSPushUtil.java
@@ -98,9 +98,14 @@
         if (StringUtil.isNullOrEmpty(shortUrl))
            throw new Exception("获取短链出错");
         json = IOSPushFactory.createBaiChuanPush(shortUrl, info.getTitle(), info.getContent());
      } else if (type == PushController.WELFARE_CENTER) {
         json = IOSPushFactory.createWelfarePush(info.getTitle(), info.getContent());
      }
      // 分组推送 每50个设备为一组
      InputStream certificate = IOSPushUtil.class.getClassLoader()
            .getResourceAsStream("certificate/pushCertificate.p12"); // 读取.p12文件
      String certificatePassword = Constant.systemCommonConfig.getIosPushCertificatePwd();
      if (tokenList != null && tokenList.size() > 0) {
         int pageSize = 50;
         int page = tokenList.size() % pageSize == 0 ? tokenList.size() / pageSize : tokenList.size() / pageSize + 1;
@@ -109,7 +114,7 @@
            int end = start + pageSize;
            if (end > tokenList.size())
               end = tokenList.size();
            pushIOS(tokenList.subList(start, end), json);
            pushIOS(tokenList.subList(start, end), json,certificate,certificatePassword);
         }
      }
@@ -117,14 +122,11 @@
      return null;
   }
   private static String pushIOS(List<String> deviceTokenList, JSONObject json) throws Exception {
   public static String pushIOS(List<String> deviceTokenList, JSONObject json,InputStream certificate,String certificatePWD) throws Exception {
      List<String> tokenList = new ArrayList<String>();
      for (String deviceToken : deviceTokenList) {
         tokenList.add(deviceToken);
      }
      InputStream certificate = IOSPushUtil.class.getClassLoader()
            .getResourceAsStream("certificate/pushCertificate.p12"); // 读取.p12文件
      String certificatePassword = Constant.systemCommonConfig.getIosPushCertificatePwd();// 此处注意导出的证书密码不能为空因为空密码会报错
      while (json.toString().getBytes().length > 256) {
         // 首先削减内容,然后削减标题
         String title = json.optJSONObject("aps").optJSONObject("alert").optString("title");
@@ -150,10 +152,10 @@
      // true:表示的是产品线上发布推送服务 false:表示的是产品测试推送服务
      if (Constant.IS_TEST)
         pushManager.initializeConnection(
               new AppleNotificationServerBasicImpl(certificate, certificatePassword, false));
               new AppleNotificationServerBasicImpl(certificate, certificatePWD, false));
      else
         pushManager
               .initializeConnection(new AppleNotificationServerBasicImpl(certificate, certificatePassword, true));
               .initializeConnection(new AppleNotificationServerBasicImpl(certificate, certificatePWD, true));
      List<Device> deviceList = new ArrayList<Device>();
      for (String token : tokenList) {
@@ -217,7 +219,10 @@
    * @throws Exception
    */
   public static void executePushIOS(List<String> tokenList, JSONObject json) throws Exception {
      pushIOS(tokenList, json);
      InputStream certificate = IOSPushUtil.class.getClassLoader()
            .getResourceAsStream("certificate/pushCertificate.p12"); // 读取.p12文件
      String certificatePassword = Constant.systemCommonConfig.getIosPushCertificatePwd();
      pushIOS(tokenList, json,certificate,certificatePassword);
   }
   /**