From 22aa3953922432c2d023927fce3db703439e2d8d Mon Sep 17 00:00:00 2001 From: yiyan Date: Sun, 26 May 2019 15:30:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E5=AD=98=E4=BF=A1=E6=81=AF=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 + .../mq/business/user/entity/TblPushList.java | 6 +- .../user/entity/TblPushUserDevice.java | 50 ++++++++ .../mq/business/user/entity/TblUser.java | 2 - .../user/mapper/TblPushUserDeviceMapper.java | 16 +++ .../service/ITblPushUserDeviceService.java | 16 +++ .../com/ifish7/mq/push/AliyunPushApi.java | 108 +++++++++++------- .../mq/queues/event/PushNotifcationEvent.java | 12 +- ...ataEventSupport.java => EventSupport.java} | 16 +-- .../event/support/PushEventSupport.java | 36 ------ .../IfishDataQueueMessageListener.java | 6 +- .../IfishPushQueueMessageListener.java | 6 +- .../ifish7/mq/utils/MybatisCodeGenerator.java | 4 +- src/main/resources/log4j.properties | 11 +- .../mapper/user/TblPushUserDeviceMapper.xml | 5 + src/main/resources/mq.properties | 5 +- src/main/resources/push.properties | 2 +- src/main/resources/spring/spring-mq.xml | 62 +++++----- src/main/resources/spring/spring-mybatis.xml | 2 +- .../com/ifish7/mq/push/AliyunPushApiTest.java | 12 +- 20 files changed, 235 insertions(+), 148 deletions(-) create mode 100644 src/main/java/com/ifish7/mq/business/user/entity/TblPushUserDevice.java create mode 100644 src/main/java/com/ifish7/mq/business/user/mapper/TblPushUserDeviceMapper.java create mode 100644 src/main/java/com/ifish7/mq/business/user/service/ITblPushUserDeviceService.java rename src/main/java/com/ifish7/mq/queues/event/support/{DataEventSupport.java => EventSupport.java} (84%) delete mode 100644 src/main/java/com/ifish7/mq/queues/event/support/PushEventSupport.java create mode 100644 src/main/resources/mapper/user/TblPushUserDeviceMapper.xml diff --git a/pom.xml b/pom.xml index ac263fc..6f28712 100644 --- a/pom.xml +++ b/pom.xml @@ -155,6 +155,12 @@ ${mybatis-spring.version} + + org.apache.commons + commons-pool2 + 2.6.2 + + commons-logging commons-logging diff --git a/src/main/java/com/ifish7/mq/business/user/entity/TblPushList.java b/src/main/java/com/ifish7/mq/business/user/entity/TblPushList.java index 896a173..67e8f75 100644 --- a/src/main/java/com/ifish7/mq/business/user/entity/TblPushList.java +++ b/src/main/java/com/ifish7/mq/business/user/entity/TblPushList.java @@ -38,13 +38,13 @@ public class TblPushList { private String pushContext; - private LocalDateTime createTime; + private LocalDateTime createTime = LocalDateTime.now(); private String pushLink; private String jpushStatus; - private String neteaseStatus; + private String neteaseStatus = "1"; private Integer reportId; @@ -58,5 +58,5 @@ public class TblPushList { private Integer number5; - + private Integer isRead; } diff --git a/src/main/java/com/ifish7/mq/business/user/entity/TblPushUserDevice.java b/src/main/java/com/ifish7/mq/business/user/entity/TblPushUserDevice.java new file mode 100644 index 0000000..6568280 --- /dev/null +++ b/src/main/java/com/ifish7/mq/business/user/entity/TblPushUserDevice.java @@ -0,0 +1,50 @@ +package com.ifish7.mq.business.user.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.time.LocalTime; + +/** + *

+ * + *

+ * + * @author yan.y + * @since 2019-04-13 + */ +@Data +@Accessors(chain = true) +@TableName("tbl_push_user_device") +public class TblPushUserDevice { + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + private Integer pushId; + + /** + * 用户ID + */ + private Integer pushUserId; + + /** + * 设备ID + */ + private String pushDeviceId; + + /** + * 设备绑定时间 + */ + private LocalTime pushBindTime; + + /** + * 设备绑定类型 + */ + private String pushBindType; + + +} diff --git a/src/main/java/com/ifish7/mq/business/user/entity/TblUser.java b/src/main/java/com/ifish7/mq/business/user/entity/TblUser.java index ca2e109..be0a2ff 100644 --- a/src/main/java/com/ifish7/mq/business/user/entity/TblUser.java +++ b/src/main/java/com/ifish7/mq/business/user/entity/TblUser.java @@ -75,6 +75,4 @@ public class TblUser { private Double latitude; private Double longitude; - - } diff --git a/src/main/java/com/ifish7/mq/business/user/mapper/TblPushUserDeviceMapper.java b/src/main/java/com/ifish7/mq/business/user/mapper/TblPushUserDeviceMapper.java new file mode 100644 index 0000000..e948614 --- /dev/null +++ b/src/main/java/com/ifish7/mq/business/user/mapper/TblPushUserDeviceMapper.java @@ -0,0 +1,16 @@ +package com.ifish7.mq.business.user.mapper; + +import com.ifish7.mq.business.user.entity.TblPushUserDevice; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author yan.y + * @since 2019-04-13 + */ +public interface TblPushUserDeviceMapper extends BaseMapper { + +} diff --git a/src/main/java/com/ifish7/mq/business/user/service/ITblPushUserDeviceService.java b/src/main/java/com/ifish7/mq/business/user/service/ITblPushUserDeviceService.java new file mode 100644 index 0000000..cb93595 --- /dev/null +++ b/src/main/java/com/ifish7/mq/business/user/service/ITblPushUserDeviceService.java @@ -0,0 +1,16 @@ +package com.ifish7.mq.business.user.service; + +import com.ifish7.mq.business.user.entity.TblPushUserDevice; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author yan.y + * @since 2019-04-13 + */ +public interface ITblPushUserDeviceService extends IService { + +} diff --git a/src/main/java/com/ifish7/mq/push/AliyunPushApi.java b/src/main/java/com/ifish7/mq/push/AliyunPushApi.java index 99f042a..6ff0b56 100644 --- a/src/main/java/com/ifish7/mq/push/AliyunPushApi.java +++ b/src/main/java/com/ifish7/mq/push/AliyunPushApi.java @@ -1,18 +1,23 @@ package com.ifish7.mq.push; -import com.alibaba.fastjson.JSONObject; import com.aliyuncs.DefaultAcsClient; import com.aliyuncs.exceptions.ClientException; import com.aliyuncs.http.FormatType; import com.aliyuncs.profile.DefaultProfile; import com.aliyuncs.push.model.v20160801.PushRequest; import com.aliyuncs.push.model.v20160801.PushResponse; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.ifish7.mq.business.user.entity.TblPushList; +import com.ifish7.mq.business.user.entity.TblPushUserDevice; +import com.ifish7.mq.business.user.entity.TblUser; import com.ifish7.mq.business.user.service.ITblPushListService; +import com.ifish7.mq.business.user.service.ITblPushUserDeviceService; +import com.ifish7.mq.business.user.service.ITblUserService; import lombok.extern.log4j.Log4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import java.time.LocalDateTime; +import java.util.List; /** * @author: yan.y @@ -31,7 +36,9 @@ public class AliyunPushApi { //推送target类型 private static final String TARGET_TYPE = "DEVICE"; //推送类型 - private static final String PUSH_TYPE = "MESSAGE"; + private static final String PUSH_TYPE = "NOTICE"; + //推送类型 ALL + private static final String PHONE_TYPE = "ALL"; @Autowired private PushRequest pushRequest; @@ -39,54 +46,67 @@ public class AliyunPushApi { @Autowired private ITblPushListService pushListService; - public void advancedPush(JSONObject json){ + @Autowired + private ITblUserService userService; - //推送目标: - //DEVICE:根据设备推送 - //ACCOUNT:根据账号推送 - //ALIAS:根据别名推送 - //TAG:根据标签推送 - //ALL:推送给全部设备 - pushRequest.setTarget(TARGET_TYPE); + @Autowired + private ITblPushUserDeviceService pushUserDeviceService; + + public void advancedPush(TblPushList pushList){ - pushRequest.setAcceptFormat(FormatType.JSON); //根据Target来设定,多个值使用逗号分隔 //此处应该查询出用户所对应的deviceId ★★★★★ - pushRequest.setTargetValue(json.getString("deviceId")); - //推送类型 - pushRequest.setPushType(PUSH_TYPE); - //推送设备类型 - pushRequest.setDeviceType(json.getString("phoneType")); - // 消息的标题 - pushRequest.setTitle(json.getString("title")); - // 消息的内容 - pushRequest.setBody(json.getString("body")); - // 离线消息是否保存,若保存, 在推送时候,用户即使不在线,下一次上线则会收到 - pushRequest.setStoreOffline(true); + String deviceIds = getUserDevices(String.valueOf(pushList.getUserId())); + //如果次用户未绑定设备 不推送 + if (StringUtils.isNotBlank(deviceIds)) { + //推送目标: + //DEVICE:根据设备推送 + //ACCOUNT:根据账号推送 + //ALIAS:根据别名推送 + //TAG:根据标签推送 + //ALL:推送给全部设备 + pushRequest.setTarget(TARGET_TYPE); + //响应数据 + pushRequest.setAcceptFormat(FormatType.JSON); + pushRequest.setTargetValue(deviceIds); + //推送类型 + pushRequest.setPushType(PUSH_TYPE); + //推送设备类型 + pushRequest.setDeviceType(PHONE_TYPE); + // 消息的标题 + pushRequest.setTitle(pushList.getPushTitle()); + // 消息的内容 + pushRequest.setBody(pushList.getPushContext()); + // 离线消息是否保存,若保存, 在推送时候,用户即使不在线,下一次上线则会收到 + pushRequest.setStoreOffline(true); - try { - PushResponse response = client.getAcsResponse(pushRequest); - TblPushList pushList = new TblPushList(); - pushList.setUserId(json.getInteger("userId")); - pushList.setDeviceId(json.getInteger("deviceId")); - pushList.setShowName(json.getString("showName")); - pushList.setPhoneType(json.getString("phoneType")); - pushList.setPushType(json.getString("pushType")); - pushList.setPushTitle(json.getString("title")); - pushList.setPushContext(json.getString("body")); - pushList.setJpushStatus(response.getMessageId()); - pushList.setNeteaseStatus("1"); - pushList.setCreateTime(LocalDateTime.now()); - pushList.setNumber1(json.getInteger("number1")); - pushList.setNumber2(json.getInteger("number2")); - pushList.setNumber3(json.getInteger("number3")); - pushList.setNumber4(json.getInteger("number4")); - pushList.setNumber5(json.getInteger("number5")); - pushListService.save(pushList); - } catch (ClientException e) { - log.error(e.getMessage(),e); + //android通知设置 + pushRequest.setAndroidOpenType("APPLICATION"); + pushRequest.setAndroidNotifyType("BOTH"); + pushRequest.setAndroidNotificationChannel("1"); + + try { + PushResponse response = client.getAcsResponse(pushRequest); + pushList.setReportId(Integer.parseInt(response.getMessageId())); + //未读 + pushList.setIsRead(1); + pushListService.save(pushList); + } catch (ClientException e) { + log.error(e.getMessage(),e); + } + } else { + log.info(String.format("user : '%s' not bind device ",pushList.getUserId())); } + } + private String getUserDevices(String userId){ + //查询出userId所对应的所有的deviceId + List pushUserDevices = pushUserDeviceService.list(new QueryWrapper().lambda().eq(TblPushUserDevice::getPushUserId, userId)); + StringBuilder deviceIds = new StringBuilder(); + for (TblPushUserDevice pushUserDevice : pushUserDevices) { + deviceIds.append(pushUserDevice.getPushDeviceId()).append(","); + } + return deviceIds.toString(); } } diff --git a/src/main/java/com/ifish7/mq/queues/event/PushNotifcationEvent.java b/src/main/java/com/ifish7/mq/queues/event/PushNotifcationEvent.java index 91f6e8d..8d58645 100644 --- a/src/main/java/com/ifish7/mq/queues/event/PushNotifcationEvent.java +++ b/src/main/java/com/ifish7/mq/queues/event/PushNotifcationEvent.java @@ -1,8 +1,9 @@ package com.ifish7.mq.queues.event; -import com.alibaba.fastjson.JSONObject; +import com.ifish7.mq.business.user.entity.TblPushList; import com.ifish7.mq.push.AliyunPushApi; import com.ifish7.mq.utils.AppBeans; +import lombok.extern.log4j.Log4j; /** * @author: yan.y @@ -10,14 +11,17 @@ import com.ifish7.mq.utils.AppBeans; * @Date: Created in 15:23 2019-04-10 * @Modified by: */ +@Log4j public class PushNotifcationEvent { /** * 设备通知增强版 - * @param eventBody 事件体 + * @param eventEntity 事件体 */ - private void deviceNotifcationPlus(JSONObject eventBody){ + private void deviceNotifcationPlus(Object eventEntity){ + log.info("deviceNotifcationPlus eventEntity : " + eventEntity); + TblPushList pushList= (TblPushList) eventEntity; AliyunPushApi aliyunPushApi = AppBeans.getBean(AliyunPushApi.class); - aliyunPushApi.advancedPush(eventBody); + aliyunPushApi.advancedPush(pushList); } } diff --git a/src/main/java/com/ifish7/mq/queues/event/support/DataEventSupport.java b/src/main/java/com/ifish7/mq/queues/event/support/EventSupport.java similarity index 84% rename from src/main/java/com/ifish7/mq/queues/event/support/DataEventSupport.java rename to src/main/java/com/ifish7/mq/queues/event/support/EventSupport.java index d87ef45..b4ce43e 100644 --- a/src/main/java/com/ifish7/mq/queues/event/support/DataEventSupport.java +++ b/src/main/java/com/ifish7/mq/queues/event/support/EventSupport.java @@ -2,28 +2,30 @@ package com.ifish7.mq.queues.event.support; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import lombok.Data; import lombok.extern.log4j.Log4j; import java.lang.reflect.Method; /** * @author: yan.y - * @Description: 数据事件总线处理 + * @Description: 事件总线处理 * @Date: Created in 22:15 2019/4/9 */ @Log4j -public class DataEventSupport { +@Data +public class EventSupport { //事件处理类型 - protected String eventProcess; + private String eventProcess; //事件名称 - protected String eventName; + private String eventName; //事件体 - protected String eventBody; + private String eventBody; //事件体对象 - protected Object eventEntity; + private Object eventEntity; //事件处理 public void process() { @@ -46,8 +48,6 @@ public class DataEventSupport { } catch (Exception e) { log.error(e.getMessage(),e); } - - } } diff --git a/src/main/java/com/ifish7/mq/queues/event/support/PushEventSupport.java b/src/main/java/com/ifish7/mq/queues/event/support/PushEventSupport.java deleted file mode 100644 index cd6ba6a..0000000 --- a/src/main/java/com/ifish7/mq/queues/event/support/PushEventSupport.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.ifish7.mq.queues.event.support; - -import com.alibaba.fastjson.JSONObject; -import lombok.extern.log4j.Log4j; - -import java.lang.reflect.Method; - -/** - * @author: yan.y - * @Description: 推送事件总线处理 - * @Date: Created in 23:24 2019/4/10 - */ -@Log4j -public class PushEventSupport { - //事件处理类型 - protected String eventProcess; - - //事件名称 - protected String eventName; - - //事件体 - protected JSONObject eventBody; - - //事件处理 - public void process() { - try { - Class eventClazz = Class.forName(this.eventName); - Method method = eventClazz.getDeclaredMethod(this.eventProcess,Object.class); - method.setAccessible(true); - method.invoke(eventClazz.newInstance(),this.eventBody); - } catch (Exception e) { - log.info(e.getMessage(),e); - } - } - -} diff --git a/src/main/java/com/ifish7/mq/queues/listener/IfishDataQueueMessageListener.java b/src/main/java/com/ifish7/mq/queues/listener/IfishDataQueueMessageListener.java index 4935e46..b67b041 100644 --- a/src/main/java/com/ifish7/mq/queues/listener/IfishDataQueueMessageListener.java +++ b/src/main/java/com/ifish7/mq/queues/listener/IfishDataQueueMessageListener.java @@ -1,7 +1,7 @@ package com.ifish7.mq.queues.listener; import com.alibaba.fastjson.JSON; -import com.ifish7.mq.queues.event.support.DataEventSupport; +import com.ifish7.mq.queues.event.support.EventSupport; import lombok.extern.log4j.Log4j; import javax.jms.JMSException; @@ -23,8 +23,8 @@ public class IfishDataQueueMessageListener implements MessageListener{ TextMessage tm = (TextMessage) message; try { log.info("Ifish7 - Data : " + tm.getText()); - DataEventSupport dataEventSupport = JSON.parseObject(tm.getText(), DataEventSupport.class); - dataEventSupport.process(); + EventSupport eventSupport = JSON.parseObject(tm.getText(), EventSupport.class); + eventSupport.process(); } catch (JMSException e) { log.error(e); } diff --git a/src/main/java/com/ifish7/mq/queues/listener/IfishPushQueueMessageListener.java b/src/main/java/com/ifish7/mq/queues/listener/IfishPushQueueMessageListener.java index 7c86b0d..3064c95 100644 --- a/src/main/java/com/ifish7/mq/queues/listener/IfishPushQueueMessageListener.java +++ b/src/main/java/com/ifish7/mq/queues/listener/IfishPushQueueMessageListener.java @@ -1,5 +1,7 @@ package com.ifish7.mq.queues.listener; +import com.alibaba.fastjson.JSON; +import com.ifish7.mq.queues.event.support.EventSupport; import lombok.extern.log4j.Log4j; import javax.jms.JMSException; @@ -20,8 +22,10 @@ public class IfishPushQueueMessageListener implements MessageListener { TextMessage tm = (TextMessage) message; try { log.info("Ifish7 - Push : " + tm.getText()); + EventSupport eventSupport = JSON.parseObject(tm.getText(), EventSupport.class); + eventSupport.process(); } catch (JMSException e) { - log.error(e); + log.error(e.getMessage(),e); } } } diff --git a/src/main/java/com/ifish7/mq/utils/MybatisCodeGenerator.java b/src/main/java/com/ifish7/mq/utils/MybatisCodeGenerator.java index fe0118c..46c1dfd 100644 --- a/src/main/java/com/ifish7/mq/utils/MybatisCodeGenerator.java +++ b/src/main/java/com/ifish7/mq/utils/MybatisCodeGenerator.java @@ -54,11 +54,11 @@ public class MybatisCodeGenerator { // 数据源配置 DataSourceConfig dsc = new DataSourceConfig(); - dsc.setUrl("jdbc:mysql://localhost:3306/myfishdb?useUnicode=true&useSSL=false&characterEncoding=utf8"); + dsc.setUrl("jdbc:mysql://139.196.24.156:3306/myfishdb?useUnicode=true&useSSL=false&characterEncoding=utf8"); // dsc.setSchemaName("public"); dsc.setDriverName("com.mysql.jdbc.Driver"); dsc.setUsername("root"); - dsc.setPassword("123456"); + dsc.setPassword("ifish7mysql"); mpg.setDataSource(dsc); // 包配置 diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties index 953e587..3985c17 100644 --- a/src/main/resources/log4j.properties +++ b/src/main/resources/log4j.properties @@ -4,15 +4,16 @@ log4j.appender.Console=org.apache.log4j.ConsoleAppender log4j.appender.Console.Target=System.out #\u53EF\u4EE5\u7075\u6D3B\u5730\u6307\u5B9A\u65E5\u5FD7\u8F93\u51FA\u683C\u5F0F\uFF0C\u4E0B\u9762\u4E00\u884C\u662F\u6307\u5B9A\u5177\u4F53\u7684\u683C\u5F0F log4j.appender.Console.layout = org.apache.log4j.PatternLayout -log4j.appender.Console.layout.ConversionPattern=[ifishMQ][%c] - %m%n - +log4j.appender.Console.layout.ConversionPattern=[ifishMQ][%c] - %m%n #\u6587\u4EF6\u5927\u5C0F\u5230\u8FBE\u6307\u5B9A\u5C3A\u5BF8\u7684\u65F6\u5019\u4EA7\u751F\u4E00\u4E2A\u65B0\u7684\u6587\u4EF6 log4j.appender.File = org.apache.log4j.RollingFileAppender -#\u6307\u5B9A\u8F93\u51FA\u76EE\u5F55 +#\u6307\u5B9A\u8F93\u51FA\u76EE\u5F55 log4j.appender.File.File = logs/ifishMQ.log -#\u5B9A\u4E49\u6587\u4EF6\u6700\u5927\u5927\u5C0F +#\u5B9A\u4E49\u6587\u4EF6\u6700\u5927\u5927\u5C0F log4j.appender.File.MaxFileSize = 100 #\u8F93\u51FA\u6240\u4EE5\u65E5\u5FD7\uFF0C\u5982\u679C\u6362\u6210DEBUG\u8868\u793A\u8F93\u51FADEBUG\u4EE5\u4E0A\u7EA7\u522B\u65E5\u5FD7 log4j.appender.File.Threshold = ALL log4j.appender.File.layout = org.apache.log4j.PatternLayout -log4j.appender.File.layout.ConversionPattern =[ifishMQ][%p] [%d{yyyy-MM-dd HH\:mm\:ss}][%c]%m%n \ No newline at end of file +log4j.appender.File.layout.ConversionPattern =[ifishMQ][%p] [%d{yyyy-MM-dd HH\:mm\:ss}][%c]%m%n + +log4j.logger.org.apache.activemq=INFO \ No newline at end of file diff --git a/src/main/resources/mapper/user/TblPushUserDeviceMapper.xml b/src/main/resources/mapper/user/TblPushUserDeviceMapper.xml new file mode 100644 index 0000000..30aae8d --- /dev/null +++ b/src/main/resources/mapper/user/TblPushUserDeviceMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/main/resources/mq.properties b/src/main/resources/mq.properties index 2409198..60d854c 100644 --- a/src/main/resources/mq.properties +++ b/src/main/resources/mq.properties @@ -1,5 +1,6 @@ -broker_url=tcp://localhost:61616 +broker_url=tcp://test.ifish7.com:61616 username=admin -password=admin +#password=admin +password=adminifish7 queue_data_name=ifishDataMq queue_push_name=ifishPushMq \ No newline at end of file diff --git a/src/main/resources/push.properties b/src/main/resources/push.properties index 94ffc74..c2f124b 100644 --- a/src/main/resources/push.properties +++ b/src/main/resources/push.properties @@ -1,6 +1,6 @@ accessKeyId= LTAIfZaosFH5IWlD accessKeySecret = dvlE8eFii31BcGb8HzkGz3eSaJ6Y94 -appKey = 23252055 +appKey = 26023230 #\u76EE\u524D\u8BE5\u503C\u56FA\u5B9A\uFF0C\u4E0D\u7528\u52A8 regionId = cn-hangzhou diff --git a/src/main/resources/spring/spring-mq.xml b/src/main/resources/spring/spring-mq.xml index 132f816..b76abd2 100644 --- a/src/main/resources/spring/spring-mq.xml +++ b/src/main/resources/spring/spring-mq.xml @@ -1,24 +1,32 @@ - - + + - - - - - - + + + + - + + + + + + + + + + + + + + + + + @@ -41,29 +49,17 @@ - + - + - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/resources/spring/spring-mybatis.xml b/src/main/resources/spring/spring-mybatis.xml index 5e66ace..766a12d 100644 --- a/src/main/resources/spring/spring-mybatis.xml +++ b/src/main/resources/spring/spring-mybatis.xml @@ -50,7 +50,7 @@ - + diff --git a/src/test/java/com/ifish7/mq/push/AliyunPushApiTest.java b/src/test/java/com/ifish7/mq/push/AliyunPushApiTest.java index 95c7344..e785131 100644 --- a/src/test/java/com/ifish7/mq/push/AliyunPushApiTest.java +++ b/src/test/java/com/ifish7/mq/push/AliyunPushApiTest.java @@ -27,7 +27,7 @@ public class AliyunPushApiTest { IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAIfZaosFH5IWlD", "dvlE8eFii31BcGb8HzkGz3eSaJ6Y94"); DefaultAcsClient client = new DefaultAcsClient(profile); PushRequest pushRequest = new PushRequest(); - pushRequest.setAppKey(23252055l); + pushRequest.setAppKey(26023230l); pushRequest.setSysProtocol(ProtocolType.HTTPS); pushRequest.setSysMethod(MethodType.POST); pushRequest.setStoreOffline(true); @@ -45,15 +45,21 @@ public class AliyunPushApiTest { pushRequest.setAcceptFormat(FormatType.JSON); //根据Target来设定,多个值使用逗号分隔 //此处应该查询出用户所对应的deviceId ★★★★★ - pushRequest.setTargetValue("18aujhs872ysgd6tx7329oaliygx7432"); + pushRequest.setTargetValue("c17c0590e8254b6b977b8fd7706fa8c2"); //推送类型 - pushRequest.setPushType("MESSAGE"); + pushRequest.setPushType("NOTICE"); //推送设备类型 pushRequest.setDeviceType("ANDROID"); // 消息的标题 pushRequest.setTitle("温度报警"); // 消息的内容 pushRequest.setBody("[温度报警]你的水族箱\"鱼缸1234\"在2019-04-10 23:40:00,温度达到29℃,已高于28℃,请及时查看!"); + + // 推送配置: Android + pushRequest.setAndroidNotifyType("BOTH");//通知的提醒方式 "VIBRATE" : 震动 "SOUND" : 声音 "BOTH" : 声音和震动 NONE : 静音 + pushRequest.setAndroidOpenType("APPLICATION"); //点击通知后动作 "APPLICATION" : 打开应用 "ACTIVITY" : 打开AndroidActivity "URL" : 打开URL "NONE" : 无跳转 + // 指定notificaitonchannel id + pushRequest.setAndroidNotificationChannel("1"); try { PushResponse response = client.getAcsResponse(pushRequest); log.info(response);