diff --git a/src/main/java/com/ifish7/mq/push/AliyunPushApi.java b/src/main/java/com/ifish7/mq/push/AliyunPushApi.java index a58763c..11c72a8 100644 --- a/src/main/java/com/ifish7/mq/push/AliyunPushApi.java +++ b/src/main/java/com/ifish7/mq/push/AliyunPushApi.java @@ -46,7 +46,7 @@ public class AliyunPushApi { private final DefaultAcsClient client; - public AliyunPushApi(String regionId,String accessKeyId,String accessKeySecret){ + public AliyunPushApi(String regionId, String accessKeyId, String accessKeySecret) { client = new DefaultAcsClient(DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret)); } @@ -82,7 +82,7 @@ public class AliyunPushApi { @Autowired private ITblAliyunDeviceInfoService aliyunDeviceInfoService; - public void advancedPush(TblPushList pushList){ + public void advancedPush(TblPushList pushList) { //根据Target来设定,多个值使用逗号分隔 //此处应该查询出用户所对应的deviceId ★★★★★ @@ -90,9 +90,9 @@ public class AliyunPushApi { //查询所有 LambdaQueryWrapper allQuary = new QueryWrapper().lambda().eq(TblAliyunDeviceInfo::getUserId, pushList.getUserId()); if ("IOS".equalsIgnoreCase(pushList.getPhoneType())) { - allQuary.eq(TblAliyunDeviceInfo::getPhoneType,"iOS"); - } else if("ANDROID".equalsIgnoreCase(pushList.getPhoneType())) { - allQuary.eq(TblAliyunDeviceInfo::getPhoneType,"ANDROID"); + allQuary.eq(TblAliyunDeviceInfo::getPhoneType, "iOS"); + } else if ("ANDROID".equalsIgnoreCase(pushList.getPhoneType())) { + allQuary.eq(TblAliyunDeviceInfo::getPhoneType, "ANDROID"); } List pushUserDevices = aliyunDeviceInfoService.list(allQuary); pushUserDevices.forEach(aliyunDeviceInfo -> { @@ -147,15 +147,17 @@ public class AliyunPushApi { try { PushResponse response = client.getAcsResponse(pushRequest); + log.info("阿里云推送\t" + aliyunDeviceInfo.getUserId() + "\t" + aliyunDeviceInfo.getAliyunDeviceId() + "\t" + JSONObject.toJSONString(response)); pushList.setReportId(response.getMessageId()); - pushList.setDeviceId((pushList.getDeviceId() == null || pushList.getDeviceId() == 0)? null : pushList.getDeviceId()); + pushList.setDeviceId((pushList.getDeviceId() == null || pushList.getDeviceId() == 0) ? null : pushList.getDeviceId()); } catch (ClientException e) { - log.error(e.getMessage(),e); + log.error(e.getMessage(), e); } } public static ApiHelper apiHelper = null; - public static PushApi pushApi = null; + public static PushApi pushApi = null; + static { System.setProperty("http.maxConnections", "200"); GtApiConfiguration apiConfiguration = new GtApiConfiguration(); @@ -205,6 +207,8 @@ public class AliyunPushApi { options.put("XM", XM); Map OP = new HashMap<>(); OP.put("/channel_id", "push_oplus_category_content"); + OP.put("/category", "DEVICE_REMINDER"); + OP.put("/notify_level", 2); options.put("OP", OP); ups.setOptions(options); androidDTO.setUps(ups); @@ -214,12 +218,57 @@ public class AliyunPushApi { audience.addCid(aliyunDeviceInfo.getAliyunDeviceId()); // 进行cid单推 ApiResult>> apiResult = pushApi.pushToSingleByCid(pushDTO); - log.info("gtPush request : " + aliyunDeviceInfo.getAliyunDeviceId() + " , response : " + JSONObject.toJSONString(apiResult)); + log.info("个推推送\t" + "\t" + aliyunDeviceInfo.getUserId() + aliyunDeviceInfo.getAliyunDeviceId() + "\t" + JSONObject.toJSONString(apiResult)); } public static void main(String[] args) { +//根据cid进行单推 + PushDTO pushDTO = new PushDTO<>(); + // 设置推送参数 + pushDTO.setRequestId(System.currentTimeMillis() + ""); + PushMessage pushMessage = new PushMessage(); + pushDTO.setPushMessage(pushMessage); + GTNotification notification = new GTNotification(); + pushMessage.setNotification(notification); + notification.setTitle("测试"); + notification.setBody("测试"); + notification.setClickType("startapp"); + PushChannel pushChannel = new PushChannel(); + pushDTO.setPushChannel(pushChannel); + /*配置安卓厂商参数*/ + AndroidDTO androidDTO = new AndroidDTO(); + Ups ups = new Ups(); + ThirdNotification thirdNotification = new ThirdNotification(); + thirdNotification.setTitle("测试"); + thirdNotification.setBody("测试"); + thirdNotification.setClickType("startapp"); + ups.setNotification(thirdNotification); + Map> options = new HashMap<>(); + Map HO = new HashMap<>(); + HO.put("/android/notification/importance", "NORMAL"); + options.put("HO", HO); + Map HW = new HashMap<>(); + HW.put("/message/android/category", "WORK"); + options.put("HW", HW); + Map XM = new HashMap<>(); + XM.put("/extra.channel_id", "131247"); + options.put("XM", XM); + Map OP = new HashMap<>(); + OP.put("/channel_id", "push_oplus_category_service"); + OP.put("/category", "DEVICE_REMINDER"); + OP.put("/notify_level", 2); + options.put("OP", OP); + ups.setOptions(options); + androidDTO.setUps(ups); + pushChannel.setAndroid(androidDTO); + Audience audience = new Audience(); + pushDTO.setAudience(audience); + audience.addCid("0de17157d2fbfdc1cc53b705f810ce44"); + // 进行cid单推 + ApiResult>> apiResult = pushApi.pushToSingleByCid(pushDTO); + log.info("gtPush request : 0de17157d2fbfdc1cc53b705f810ce44 , response : " + JSONObject.toJSONString(apiResult)); } /*public static void main(String[] args) { @@ -300,6 +349,7 @@ public class AliyunPushApi { /** * 随机生成字母与数字组合 + * * @param length * @return */ @@ -350,6 +400,7 @@ public class AliyunPushApi { } return buf.toString(); } - private static final char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; + + private static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; }