| | |
| | | package com.yeshi.fanli.util.push;
|
| | |
|
| | | import java.io.IOException;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import javax.annotation.PostConstruct;
|
| | |
| | | * @return
|
| | | */
|
| | | public static String allPushAndroidForXM(MessageInfo info, Map<String, Object> map) {
|
| | | if (Constant.IS_TEST)
|
| | | return null;
|
| | |
|
| | | String name = info.getPackageName();
|
| | | if (!Constant.systemCommonConfig.getAndroidPackageName().equalsIgnoreCase(name)
|
| | | && !Constant.systemCommonConfig.getIosBundleId().equalsIgnoreCase(name)) {
|
| | |
| | | message = builder.build();
|
| | | try {
|
| | | Result result = sender.broadcastAll(message, 3);
|
| | | return result.getMessageId();// 成功 返回消息的Id, 失败返回null
|
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | | } catch (ParseException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 批量推送
|
| | | * |
| | | * @param info
|
| | | * @param map
|
| | | * @param regList
|
| | | * 最大个数为1000
|
| | | * @return
|
| | | */
|
| | | public static String pushBatchAndroidForXM(MessageInfo info, Map<String, Object> map, List<String> regList) {
|
| | | if (Constant.IS_TEST)
|
| | | return null;
|
| | | if (regList == null || regList.size() == 0)
|
| | | return "";
|
| | |
|
| | | String name = info.getPackageName();
|
| | | if (!Constant.systemCommonConfig.getAndroidPackageName().equalsIgnoreCase(name)
|
| | | && !Constant.systemCommonConfig.getIosBundleId().equalsIgnoreCase(name)) {
|
| | | return null;
|
| | | }
|
| | |
|
| | | // 从info中取页面传来的值
|
| | | Constants.useOfficial(); // 启动推送方法
|
| | | String PackageName = info.getPackageName();
|
| | | Sender sender = new Sender(XIAOMI_F_ANDROID_APP_SECERT); // 申请的AppSecert
|
| | | String title = info.getTitle();
|
| | | String payload = info.getContent();
|
| | | String description = info.getContent();
|
| | |
|
| | | Message message = null; // 做循环传来的key
|
| | | Builder builder = new Message.Builder().restrictedPackageName(PackageName).title(title).payload(payload)
|
| | | .description(description).passThrough(0) // 设置消息是否通过透传方式至App,
|
| | | // 1表示透传,0表示通知栏消息(默认)
|
| | | .notifyType(1); // 设置通知类型, type类型(1-默认提示音, 2-使用默认震动提示,
|
| | | // 3-使用默认led灯光提示)
|
| | | // 将extra放入MessageInfo对象中, 循环遍历extra中的key 和 value
|
| | | if (map != null) {
|
| | | for (String key : map.keySet()) {
|
| | | builder.extra(key, map.get(key).toString());
|
| | | }
|
| | | }
|
| | | message = builder.build();
|
| | | try {
|
| | | Result result = sender.send(message, regList, 3);
|
| | | return result.getMessageId();// 成功 返回消息的Id, 失败返回null
|
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | |
| | | XiaoMiPushUtil.singlePushAndroidForXM(info, JsonUtil.parseData(jsonObject), system);
|
| | | }
|
| | |
|
| | |
|
| | | /**
|
| | | *
|
| | | * @param info
|
| | |
| | | // jsonXm 转换为 map
|
| | | JSONObject mapXm = JSONObject.fromObject(json);
|
| | | String android = allPushAndroidForXM(info, mapXm);
|
| | | LogHelper.userInfo("安卓推送测试:" + android);
|
| | | LogHelper.userInfo("小米推送:" + android);
|
| | | pushRecord.setAndroidPushId(android);
|
| | | if (android != null) {
|
| | | return 1;
|