| | |
| | | json = IOSPushFactory.createURLPush(shortUrl, info.getTitle(), info.getContent());
|
| | | } else if (type == PushController.ZNX) {
|
| | | json = IOSPushFactory.createZNXPush(info.getTitle(), info.getContent());
|
| | | } else if (type == PushController.WEEX) {
|
| | | String shortUrl = HttpUtil.getShortLink(url);
|
| | | if (StringUtil.isNullOrEmpty(shortUrl))
|
| | | throw new Exception("获取短链出错");
|
| | | json = IOSPushFactory.createWEEXPush(shortUrl, info.getTitle(), info.getContent());
|
| | | } else if (type == PushController.BAICHUAN) {
|
| | | String shortUrl = HttpUtil.getShortLink(url);
|
| | | 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;
|
| | |
| | | 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);
|
| | | }
|
| | |
|
| | | }
|
| | |
| | | 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");
|
| | |
| | |
|
| | | PushNotificationManager pushManager = new PushNotificationManager();
|
| | | // true:表示的是产品线上发布推送服务 false:表示的是产品测试推送服务
|
| | | if(Constant.IS_TEST)
|
| | | pushManager.initializeConnection(new AppleNotificationServerBasicImpl(certificate, certificatePassword, false));
|
| | | if (Constant.IS_TEST)
|
| | | pushManager.initializeConnection(
|
| | | new AppleNotificationServerBasicImpl(certificate, certificatePWD, false));
|
| | | else
|
| | | pushManager.initializeConnection(new AppleNotificationServerBasicImpl(certificate, certificatePassword, true));
|
| | | pushManager
|
| | | .initializeConnection(new AppleNotificationServerBasicImpl(certificate, certificatePWD, true));
|
| | |
|
| | | List<Device> deviceList = new ArrayList<Device>();
|
| | | for (String token : tokenList) {
|
| | |
| | | return 4;
|
| | | }
|
| | | }
|
| | | |
| | | |
| | |
|
| | | /**
|
| | | * 执行推送
|
| | | * |
| | | * @param tokenList
|
| | | * @param json
|
| | | * @throws Exception
|
| | | */
|
| | | public static void executePushIOS(List<String> tokenList, JSONObject json) throws Exception{
|
| | | pushIOS(tokenList, json);
|
| | | public static void executePushIOS(List<String> tokenList, JSONObject json) throws Exception {
|
| | | InputStream certificate = IOSPushUtil.class.getClassLoader()
|
| | | .getResourceAsStream("certificate/pushCertificate.p12"); // 读取.p12文件
|
| | | String certificatePassword = Constant.systemCommonConfig.getIosPushCertificatePwd();
|
| | | pushIOS(tokenList, json,certificate,certificatePassword);
|
| | | }
|
| | | |
| | | |
| | |
|
| | | /**
|
| | | *
|
| | | * 方法说明: IOS 多推
|
| | |
| | | * @return
|
| | | * @throws Exception
|
| | | */
|
| | | public static JSONObject getJSONObject(MessageInfo info, String url, int type)
|
| | | throws Exception {
|
| | | public static JSONObject getJSONObject(MessageInfo info, String url, int type) throws Exception {
|
| | |
|
| | | // json自定义传值
|
| | | JSONObject json = null;
|
| | |
| | | json = IOSPushFactory.createURLPush(shortUrl, info.getTitle(), info.getContent());
|
| | | } else if (type == PushController.ZNX) {
|
| | | json = IOSPushFactory.createZNXPush(info.getTitle(), info.getContent());
|
| | | } else if (type == PushController.WEEX) {
|
| | | String shortUrl = HttpUtil.getShortLink(url);
|
| | | if (StringUtil.isNullOrEmpty(shortUrl))
|
| | | shortUrl = url;
|
| | | json = IOSPushFactory.createWEEXPush(shortUrl, info.getTitle(), info.getContent());
|
| | | } else if (type == PushController.BAICHUAN) {
|
| | | String shortUrl = HttpUtil.getShortLink(url);
|
| | | if (StringUtil.isNullOrEmpty(shortUrl))
|
| | | shortUrl = url;
|
| | | json = IOSPushFactory.createBaiChuanPush(shortUrl, info.getTitle(), info.getContent());
|
| | | }
|
| | |
|
| | | return json;
|