| | |
| | | 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 message = null; // 做循环传来的key
|
| | | Builder builder = new Message.Builder().restrictedPackageName(PackageName).title(title).payload(payload)
|
| | | .notifyId((int) (Math.random() * Integer.MAX_VALUE))
|
| | | .description(description).passThrough(0) // 设置消息是否通过透传方式至App,
|
| | | // 1表示透传,0表示通知栏消息(默认)
|
| | | .notifyType(1); // 设置通知类型, type类型(1-默认提示音, 2-使用默认震动提示,
|
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * 批量推送
|
| | | * |
| | | * @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)
|
| | | .notifyId((int) (Math.random() * Integer.MAX_VALUE))
|
| | | .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();
|
| | | } catch (ParseException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | /**
|
| | | *
|
| | | * 方法说明: 小米推送安卓(单推)
|
| | | *
|
| | |
| | | * @param system
|
| | | * @return
|
| | | */
|
| | | public static String singlePushAndroidForXM(MessageInfo info, Map<String, Object> map, System system) {
|
| | | public static String singlePushAndroidForXM(MessageInfo info, Map<String, Object> map, List<String> regIds,
|
| | | System system) {
|
| | | String name = info.getPackageName();
|
| | | if (!Constant.systemCommonConfig.getAndroidPackageName().equalsIgnoreCase(name)
|
| | | && !Constant.systemCommonConfig.getIosBundleId().equalsIgnoreCase(name)) {
|
| | |
| | | Message message = null; // 做循环传来的key
|
| | | Builder builder = new Message.Builder().restrictedPackageName(PackageName).title(title).description(content)
|
| | | .passThrough(0) // 设置消息是否通过透传方式至App, 1表示透传,0表示通知栏消息(默认)
|
| | | .notifyType(1); // 设置通知类型, type类型(1-默认提示音, 2-使用默认震动提示,
|
| | | // 3-使用默认led灯光提示)
|
| | | .notifyId((int) (Math.random() * Integer.MAX_VALUE)).notifyType(1); // 设置通知类型,
|
| | | // type类型(1-默认提示音,
|
| | | // 2-使用默认震动提示,
|
| | | // 3-使用默认led灯光提示)
|
| | | // 将extra放入MessageInfo对象中, 循环遍历extra中的key 和 value
|
| | | if (map != null) {
|
| | | for (String key : map.keySet()) {
|
| | |
| | | }
|
| | | message = builder.build();
|
| | | try {
|
| | | Result result = sender.sendToAlias(message, uId, 3);
|
| | | Result result = sender.send(message, regIds, 3); // sender.sendToAlias(message,
|
| | | // uId, 3);
|
| | | PushLogHelper.xmInfo("推送结果:" + result.getReason());
|
| | | return result.getMessageId();
|
| | | } catch (IOException e) {
|
| | |
| | | * @author mawurui createTime 2018年3月8日 上午9:55:14
|
| | | * @param info
|
| | | */
|
| | | public static void pushByHongBao(String alias, System system) {
|
| | | public static void pushByHongBao(List<String> regIds, System system) {
|
| | | MessageInfo info = new MessageInfo();
|
| | | info.setAlias(alias);
|
| | | info.setTitle("新到红包");
|
| | | info.setDescription("红包到来了...");
|
| | | JSONObject jsonObject = new JSONObject();
|
| | | jsonObject.put("type", "hongbao");
|
| | | XiaoMiPushUtil.singlePushAndroidForXM(info, JsonUtil.parseData(jsonObject), system);
|
| | | XiaoMiPushUtil.singlePushAndroidForXM(info, JsonUtil.parseData(jsonObject), regIds, system);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | * @author mawurui createTime 2018年3月8日 上午10:00:16
|
| | | * @param info
|
| | | */
|
| | | public static void pushByApply(String alias, System system) {
|
| | | public static void pushByApply(List<String> regIds, System system) {
|
| | | MessageInfo info = new MessageInfo();
|
| | | info.setAlias(alias);
|
| | | info.setTitle("提现申请");
|
| | | info.setDescription("提现审核中...");
|
| | | JSONObject jsonObject = new JSONObject();
|
| | | jsonObject.put("type", "cash");
|
| | | XiaoMiPushUtil.singlePushAndroidForXM(info, JsonUtil.parseData(jsonObject), system);
|
| | | XiaoMiPushUtil.singlePushAndroidForXM(info, JsonUtil.parseData(jsonObject), regIds, system);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | * @param state
|
| | | * @param system
|
| | | */
|
| | | public static void pushByExtract(String alias, int state, System system) {
|
| | | public static void pushByExtract(List<String> regIds, int state, System system) {
|
| | | MessageInfo info = new MessageInfo();
|
| | | info.setAlias(alias);
|
| | | if (state == 0) {
|
| | | info.setTitle("提现成功");
|
| | | info.setDescription("您有一笔交易,已提现成功!");
|
| | |
| | | }
|
| | | JSONObject jsonObject = new JSONObject();
|
| | | jsonObject.put("type", "cash");
|
| | | XiaoMiPushUtil.singlePushAndroidForXM(info, JsonUtil.parseData(jsonObject), system);
|
| | | XiaoMiPushUtil.singlePushAndroidForXM(info, JsonUtil.parseData(jsonObject), regIds, system);
|
| | | }
|
| | |
|
| | |
|
| | | /**
|
| | | *
|
| | |
| | | // 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;
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | public static void pushZNX(Long uid, String title, String content, String msgId) {
|
| | | public static void pushZNX(List<String> regIds, String title, String content, String msgId) {
|
| | | // 小米开始推送
|
| | | MessageInfo info = new MessageInfo();
|
| | | info.setActivty(
|
| | | String.format("%s.ui.BrowserActivity", Constant.systemCommonConfig.getAndroidBaseactivityName()));
|
| | | info.setAlias(uid + "");
|
| | | info.setTitle(title);
|
| | | info.setContent(content);
|
| | | info.setPackageName(Constant.systemCommonConfig.getAndroidPackageName());
|
| | |
| | | contentJson.put("createTime", java.lang.System.currentTimeMillis());
|
| | | json.put("content", contentJson);
|
| | | JSONObject mapXm = JSONObject.fromObject(json);
|
| | | XiaoMiPushUtil.singlePushAndroidForXM(info, mapXm, null);
|
| | | XiaoMiPushUtil.singlePushAndroidForXM(info, mapXm, regIds, null);
|
| | | }
|
| | |
|
| | | }
|