From c80a48e85c31803e91803217d093f831caa5244a Mon Sep 17 00:00:00 2001
From: zhongzb <972627721@qq.com>
Date: Fri, 7 Jul 2023 00:04:55 +0800
Subject: [PATCH] =?UTF-8?q?fix:=E6=A8=A1=E6=9D=BF=E9=A2=91=E6=8E=A7?=
=?UTF-8?q?=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
mallchat-common/pom.xml | 10 ++++++
mallchat-custom-server/pom.xml | 13 ++++++++
.../impl/WeChatMsgOperationServiceImpl.java | 23 ++++++--------
.../abin/mallchat/custom}/ac/ACTrieTest.java | 4 ++-
.../mallchat/custom}/ac/CreateTokenTest.java | 2 +-
.../mallchat/custom/spring/WXTemplate.java | 31 +++++++++++++++++++
6 files changed, 68 insertions(+), 15 deletions(-)
rename {mallchat-common/src/test/java/com/abin/mallchat/common/common/algorithm => mallchat-custom-server/src/test/java/com/abin/mallchat/custom}/ac/ACTrieTest.java (93%)
rename {mallchat-common/src/test/java/com/abin/mallchat/common/common/algorithm => mallchat-custom-server/src/test/java/com/abin/mallchat/custom}/ac/CreateTokenTest.java (94%)
create mode 100644 mallchat-custom-server/src/test/java/com/abin/mallchat/custom/spring/WXTemplate.java
diff --git a/mallchat-common/pom.xml b/mallchat-common/pom.xml
index 8d7c72f..65433e7 100644
--- a/mallchat-common/pom.xml
+++ b/mallchat-common/pom.xml
@@ -119,6 +119,16 @@
${junit.version}
test
+
+ org.springframework
+ spring-test
+ 5.3.19
+ test
+
+
+ org.springframework.boot
+ spring-boot-test
+
diff --git a/mallchat-custom-server/pom.xml b/mallchat-custom-server/pom.xml
index e2fd0c7..601d321 100644
--- a/mallchat-custom-server/pom.xml
+++ b/mallchat-custom-server/pom.xml
@@ -16,6 +16,19 @@
com.abin.mallchat
mallchat-common
+
+
+ junit
+ junit
+ ${junit.version}
+ test
+
+
+ org.springframework
+ spring-test
+ 5.3.19
+ test
+
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/service/impl/WeChatMsgOperationServiceImpl.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/service/impl/WeChatMsgOperationServiceImpl.java
index 640d58a..429068c 100644
--- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/service/impl/WeChatMsgOperationServiceImpl.java
+++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/service/impl/WeChatMsgOperationServiceImpl.java
@@ -5,14 +5,11 @@ import com.abin.mallchat.common.common.domain.dto.FrequencyControlDTO;
import com.abin.mallchat.common.common.exception.FrequencyControlException;
import com.abin.mallchat.common.common.handler.GlobalUncaughtExceptionHandler;
import com.abin.mallchat.common.common.service.frequencycontrol.FrequencyControlUtil;
-import com.abin.mallchat.common.common.utils.JsonUtils;
import com.abin.mallchat.common.user.domain.entity.User;
import com.abin.mallchat.common.user.service.cache.UserCache;
import com.abin.mallchat.custom.chat.service.WeChatMsgOperationService;
import lombok.extern.slf4j.Slf4j;
-import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
-import me.chanjar.weixin.mp.api.WxMpTemplateMsgService;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import org.springframework.beans.factory.annotation.Autowired;
@@ -37,7 +34,7 @@ public class WeChatMsgOperationServiceImpl implements WeChatMsgOperationService
new GlobalUncaughtExceptionHandler()));
// at消息的微信推送模板id
- private final String atMsgPublishTemplateId = "";
+ private final String atMsgPublishTemplateId = "Xd7sWPZsuWa0UmpvLaZPvaJVjNj1KjEa0zLOm5_Z7IU";
private final String WE_CHAT_MSG_COLOR = "#A349A4";
@@ -96,8 +93,8 @@ public class WeChatMsgOperationServiceImpl implements WeChatMsgOperationService
private List generateAtMsgData(User sender, String msg) {
List dataList = new ArrayList();
// todo: 没有消息模板,暂不实现
-// dataList.add(new WxMpTemplateData("senderName", sender.getName() , WE_CHAT_MSG_COLOR));
-// dataList.add(new WxMpTemplateData("content", msg , WE_CHAT_MSG_COLOR));
+ dataList.add(new WxMpTemplateData("name", sender.getName(), WE_CHAT_MSG_COLOR));
+ dataList.add(new WxMpTemplateData("content", msg, WE_CHAT_MSG_COLOR));
return dataList;
}
@@ -107,12 +104,12 @@ public class WeChatMsgOperationServiceImpl implements WeChatMsgOperationService
* @param templateMsg 微信模板消息
*/
protected void publishTemplateMsg(WxMpTemplateMessage templateMsg) {
- WxMpTemplateMsgService wxMpTemplateMsgService = wxMpService.getTemplateMsgService();
- try {
- wxMpTemplateMsgService.sendTemplateMsg(templateMsg);
- } catch (WxErrorException e) {
- log.error("publish we chat msg failed! open id is {}, msg is {}.",
- templateMsg.getToUser(), JsonUtils.toStr(templateMsg.getData()));
- }
+// WxMpTemplateMsgService wxMpTemplateMsgService = wxMpService.getTemplateMsgService();todo 等审核通过
+// try {
+// wxMpTemplateMsgService.sendTemplateMsg(templateMsg);
+// } catch (WxErrorException e) {
+// log.error("publish we chat msg failed! open id is {}, msg is {}.",
+// templateMsg.getToUser(), JsonUtils.toStr(templateMsg.getData()));
+// }
}
}
diff --git a/mallchat-common/src/test/java/com/abin/mallchat/common/common/algorithm/ac/ACTrieTest.java b/mallchat-custom-server/src/test/java/com/abin/mallchat/custom/ac/ACTrieTest.java
similarity index 93%
rename from mallchat-common/src/test/java/com/abin/mallchat/common/common/algorithm/ac/ACTrieTest.java
rename to mallchat-custom-server/src/test/java/com/abin/mallchat/custom/ac/ACTrieTest.java
index 2fb749f..1d80ab3 100644
--- a/mallchat-common/src/test/java/com/abin/mallchat/common/common/algorithm/ac/ACTrieTest.java
+++ b/mallchat-custom-server/src/test/java/com/abin/mallchat/custom/ac/ACTrieTest.java
@@ -1,5 +1,7 @@
-package com.abin.mallchat.common.common.algorithm.ac;
+package com.abin.mallchat.custom.ac;
+import com.abin.mallchat.common.common.algorithm.ac.ACTrie;
+import com.abin.mallchat.common.common.algorithm.ac.MatchResult;
import com.google.common.collect.Lists;
import org.junit.Test;
diff --git a/mallchat-common/src/test/java/com/abin/mallchat/common/common/algorithm/ac/CreateTokenTest.java b/mallchat-custom-server/src/test/java/com/abin/mallchat/custom/ac/CreateTokenTest.java
similarity index 94%
rename from mallchat-common/src/test/java/com/abin/mallchat/common/common/algorithm/ac/CreateTokenTest.java
rename to mallchat-custom-server/src/test/java/com/abin/mallchat/custom/ac/CreateTokenTest.java
index e73a9a9..2acb222 100644
--- a/mallchat-common/src/test/java/com/abin/mallchat/common/common/algorithm/ac/CreateTokenTest.java
+++ b/mallchat-custom-server/src/test/java/com/abin/mallchat/custom/ac/CreateTokenTest.java
@@ -1,4 +1,4 @@
-package com.abin.mallchat.common.common.algorithm.ac;
+package com.abin.mallchat.custom.ac;
import com.auth0.jwt.JWT;
diff --git a/mallchat-custom-server/src/test/java/com/abin/mallchat/custom/spring/WXTemplate.java b/mallchat-custom-server/src/test/java/com/abin/mallchat/custom/spring/WXTemplate.java
new file mode 100644
index 0000000..599b2ec
--- /dev/null
+++ b/mallchat-custom-server/src/test/java/com/abin/mallchat/custom/spring/WXTemplate.java
@@ -0,0 +1,31 @@
+package com.abin.mallchat.custom.spring;
+
+import com.abin.mallchat.custom.chat.service.WeChatMsgOperationService;
+import com.abin.mallchat.custom.chat.service.impl.ChatServiceImpl;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.util.Collections;
+
+/**
+ * Description: 微信模板测试
+ * Author: abin
+ * Date: 2023-07-06
+ */
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class WXTemplate {
+
+ @Autowired
+ private WeChatMsgOperationService chatMsgOperationService;
+ @Autowired
+ private ChatServiceImpl chatService;
+
+ @Test
+ public void test() {
+ chatMsgOperationService.publishChatMsgToWeChatUser(1L, Collections.singletonList(10008L), "你家规下去");
+ }
+}