diff --git a/ifishMQ.iml b/ifishMQ.iml
index 680dd2f..c0acc5f 100644
--- a/ifishMQ.iml
+++ b/ifishMQ.iml
@@ -34,9 +34,12 @@
+
+
+
@@ -60,7 +63,6 @@
-
@@ -75,10 +77,7 @@
-
-
-
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 5ee00e6..ac263fc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -32,6 +32,19 @@
test
+
+ org.springframework
+ spring-test
+ 5.0.8.RELEASE
+
+
+ *
+ *
+
+
+ test
+
+
com.aliyun
@@ -201,22 +214,11 @@
-
- org.apache.httpcomponents
- httpclient
- 4.2
-
-
org.apache.commons
commons-lang3
3.1
-
- commons-httpclient
- commons-httpclient
- 3.1
-
diff --git a/src/main/java/com/ifish7/mq/push/AliyunPushApi.java b/src/main/java/com/ifish7/mq/push/AliyunPushApi.java
new file mode 100644
index 0000000..99f042a
--- /dev/null
+++ b/src/main/java/com/ifish7/mq/push/AliyunPushApi.java
@@ -0,0 +1,92 @@
+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.ifish7.mq.business.user.entity.TblPushList;
+import com.ifish7.mq.business.user.service.ITblPushListService;
+import lombok.extern.log4j.Log4j;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.time.LocalDateTime;
+
+/**
+ * @author: yan.y
+ * @Description:
+ * @Date: Created in 21:42 2019/4/10
+ */
+@Log4j
+public class AliyunPushApi {
+
+ private DefaultAcsClient client;
+
+ public AliyunPushApi(String regionId,String accessKeyId,String accessKeySecret){
+ client = new DefaultAcsClient(DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret));
+ }
+
+ //推送target类型
+ private static final String TARGET_TYPE = "DEVICE";
+ //推送类型
+ private static final String PUSH_TYPE = "MESSAGE";
+
+ @Autowired
+ private PushRequest pushRequest;
+
+ @Autowired
+ private ITblPushListService pushListService;
+
+ public void advancedPush(JSONObject json){
+
+ //推送目标:
+ //DEVICE:根据设备推送
+ //ACCOUNT:根据账号推送
+ //ALIAS:根据别名推送
+ //TAG:根据标签推送
+ //ALL:推送给全部设备
+ pushRequest.setTarget(TARGET_TYPE);
+
+ 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);
+
+ 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);
+ }
+
+
+ }
+}
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 de9a7fb..91f6e8d 100644
--- a/src/main/java/com/ifish7/mq/queues/event/PushNotifcationEvent.java
+++ b/src/main/java/com/ifish7/mq/queues/event/PushNotifcationEvent.java
@@ -1,5 +1,9 @@
package com.ifish7.mq.queues.event;
+import com.alibaba.fastjson.JSONObject;
+import com.ifish7.mq.push.AliyunPushApi;
+import com.ifish7.mq.utils.AppBeans;
+
/**
* @author: yan.y
* @Description: 消息推送事件
@@ -8,4 +12,12 @@ package com.ifish7.mq.queues.event;
*/
public class PushNotifcationEvent {
+ /**
+ * 设备通知增强版
+ * @param eventBody 事件体
+ */
+ private void deviceNotifcationPlus(JSONObject eventBody){
+ AliyunPushApi aliyunPushApi = AppBeans.getBean(AliyunPushApi.class);
+ aliyunPushApi.advancedPush(eventBody);
+ }
}
diff --git a/src/main/java/com/ifish7/mq/queues/event/support/EventSupport.java b/src/main/java/com/ifish7/mq/queues/event/support/DataEventSupport.java
similarity index 93%
rename from src/main/java/com/ifish7/mq/queues/event/support/EventSupport.java
rename to src/main/java/com/ifish7/mq/queues/event/support/DataEventSupport.java
index adcd901..d87ef45 100644
--- a/src/main/java/com/ifish7/mq/queues/event/support/EventSupport.java
+++ b/src/main/java/com/ifish7/mq/queues/event/support/DataEventSupport.java
@@ -2,19 +2,17 @@ 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
-@Data
-public class EventSupport {
+public class DataEventSupport {
//事件处理类型
protected String eventProcess;
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
new file mode 100644
index 0000000..cd6ba6a
--- /dev/null
+++ b/src/main/java/com/ifish7/mq/queues/event/support/PushEventSupport.java
@@ -0,0 +1,36 @@
+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 b983199..4935e46 100644
--- a/src/main/java/com/ifish7/mq/queues/listener/IfishDataQueueMessageListener.java
+++ b/src/main/java/com/ifish7/mq/queues/listener/IfishDataQueueMessageListener.java
@@ -1,8 +1,7 @@
package com.ifish7.mq.queues.listener;
import com.alibaba.fastjson.JSON;
-import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
-import com.ifish7.mq.queues.event.support.EventSupport;
+import com.ifish7.mq.queues.event.support.DataEventSupport;
import lombok.extern.log4j.Log4j;
import javax.jms.JMSException;
@@ -24,8 +23,8 @@ public class IfishDataQueueMessageListener implements MessageListener{
TextMessage tm = (TextMessage) message;
try {
log.info("Ifish7 - Data : " + tm.getText());
- EventSupport eventSupport = JSON.parseObject(tm.getText(), EventSupport.class);
- eventSupport.process();
+ DataEventSupport dataEventSupport = JSON.parseObject(tm.getText(), DataEventSupport.class);
+ dataEventSupport.process();
} catch (JMSException e) {
log.error(e);
}
diff --git a/src/main/resources/push.properties b/src/main/resources/push.properties
new file mode 100644
index 0000000..94ffc74
--- /dev/null
+++ b/src/main/resources/push.properties
@@ -0,0 +1,26 @@
+accessKeyId= LTAIfZaosFH5IWlD
+accessKeySecret = dvlE8eFii31BcGb8HzkGz3eSaJ6Y94
+appKey = 23252055
+#\u76EE\u524D\u8BE5\u503C\u56FA\u5B9A\uFF0C\u4E0D\u7528\u52A8
+regionId = cn-hangzhou
+
+protocol = HTTPS
+method = POST
+storeOffline = true
+version = 2016-08-01
+# \u53D1\u9001\u7684deviceId, \u5217\u8868\u7528\u9017\u53F7\u5206\u9694 \u6BD4\u5982: 111 \u6216\u662F 111,222
+#deviceIds =
+#deviceId =
+
+# \u53D1\u9001\u7684account, \u5217\u8868\u7528\u9017\u53F7\u5206\u9694 \u6BD4\u5982: account1 \u6216\u662F account1,account2
+#accounts =
+#account =
+
+# \u53D1\u9001\u7684alias, \u5217\u8868\u7528\u9017\u53F7\u5206\u9694 \u6BD4\u5982: alias1,alias2
+#aliases =
+#alias =
+
+# \u53D1\u9001\u7684tag, tag\u8868\u8FBE\u5F0F\u53C2\u8003\u6587\u6863:https://help.aliyun.com/document_detail/48055.html?
+#tag =
+#tagExpression =
+
diff --git a/src/main/resources/spring-main.xml b/src/main/resources/spring-main.xml
index 676646a..4d7b09f 100644
--- a/src/main/resources/spring-main.xml
+++ b/src/main/resources/spring-main.xml
@@ -14,6 +14,7 @@
classpath:mq.properties
classpath:jdbc.properties
classpath:log4j.properties
+ classpath:push.properties
@@ -23,4 +24,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/test/java/com/ifish7/mq/push/AliyunPushApiTest.java b/src/test/java/com/ifish7/mq/push/AliyunPushApiTest.java
new file mode 100644
index 0000000..95c7344
--- /dev/null
+++ b/src/test/java/com/ifish7/mq/push/AliyunPushApiTest.java
@@ -0,0 +1,65 @@
+package com.ifish7.mq.push;
+
+import com.aliyuncs.DefaultAcsClient;
+import com.aliyuncs.exceptions.ClientException;
+import com.aliyuncs.http.FormatType;
+import com.aliyuncs.http.MethodType;
+import com.aliyuncs.http.ProtocolType;
+import com.aliyuncs.profile.DefaultProfile;
+import com.aliyuncs.profile.IClientProfile;
+import com.aliyuncs.push.model.v20160801.PushRequest;
+import com.aliyuncs.push.model.v20160801.PushResponse;
+import lombok.extern.log4j.Log4j;
+import org.junit.Test;
+
+/**
+ * @author: yan.y
+ * @Description:
+ * @Date: Created in 23:42 2019/4/10
+ */
+//@RunWith(SpringJUnit4ClassRunner.class)
+//@ContextConfiguration(locations="classpath:spring-main.xml")
+@Log4j
+public class AliyunPushApiTest {
+
+ @Test
+ public void testAdvancedPush(){
+ IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAIfZaosFH5IWlD", "dvlE8eFii31BcGb8HzkGz3eSaJ6Y94");
+ DefaultAcsClient client = new DefaultAcsClient(profile);
+ PushRequest pushRequest = new PushRequest();
+ pushRequest.setAppKey(23252055l);
+ pushRequest.setSysProtocol(ProtocolType.HTTPS);
+ pushRequest.setSysMethod(MethodType.POST);
+ pushRequest.setStoreOffline(true);
+ pushRequest.setSysRegionId("cn-hangzhou");
+ pushRequest.setSysVersion("2016-08-01");
+
+ //推送目标:
+ //DEVICE:根据设备推送
+ //ACCOUNT:根据账号推送
+ //ALIAS:根据别名推送
+ //TAG:根据标签推送
+ //ALL:推送给全部设备
+ pushRequest.setTarget("DEVICE");
+
+ pushRequest.setAcceptFormat(FormatType.JSON);
+ //根据Target来设定,多个值使用逗号分隔
+ //此处应该查询出用户所对应的deviceId ★★★★★
+ pushRequest.setTargetValue("18aujhs872ysgd6tx7329oaliygx7432");
+ //推送类型
+ pushRequest.setPushType("MESSAGE");
+ //推送设备类型
+ pushRequest.setDeviceType("ANDROID");
+ // 消息的标题
+ pushRequest.setTitle("温度报警");
+ // 消息的内容
+ pushRequest.setBody("[温度报警]你的水族箱\"鱼缸1234\"在2019-04-10 23:40:00,温度达到29℃,已高于28℃,请及时查看!");
+ try {
+ PushResponse response = client.getAcsResponse(pushRequest);
+ log.info(response);
+ } catch (ClientException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/resources/spring-main.xml b/src/test/resources/spring-main.xml
new file mode 100644
index 0000000..0ea4e51
--- /dev/null
+++ b/src/test/resources/spring-main.xml
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+ classpath:push.properties
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file