From a81c4f0986322b34938c10d7f3795aff2ec2c49d Mon Sep 17 00:00:00 2001
From: WenG <450292408@qq.com>
Date: Thu, 17 Sep 2020 21:59:45 +0800
Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=B6=88=E6=81=AF=E6=A8=A1?=
=?UTF-8?q?=E6=9D=BF=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
cloud-common-wechat/pom.xml | 6 ++
.../src/test/java/MsgTest.java | 74 +++++++++++++++++++
2 files changed, 80 insertions(+)
create mode 100644 cloud-common-wechat/src/test/java/MsgTest.java
diff --git a/cloud-common-wechat/pom.xml b/cloud-common-wechat/pom.xml
index efc2849..1a0def4 100644
--- a/cloud-common-wechat/pom.xml
+++ b/cloud-common-wechat/pom.xml
@@ -17,6 +17,12 @@
cloud-common
1.0.1-SNAPSHOT
+
+ junit
+ junit
+ 4.12
+ test
+
\ No newline at end of file
diff --git a/cloud-common-wechat/src/test/java/MsgTest.java b/cloud-common-wechat/src/test/java/MsgTest.java
new file mode 100644
index 0000000..6292ae2
--- /dev/null
+++ b/cloud-common-wechat/src/test/java/MsgTest.java
@@ -0,0 +1,74 @@
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import org.junit.Test;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * When you feel like quitting. Think about why you started
+ * 当你想要放弃的时候,想想当初你为何开始
+ *
+ * @ClassName: MsgTemplateTest
+ * @Description:
+ * @Author: WangGeng
+ * @Date: 2020/9/15 15:37
+ * @Version: 1.0
+ **/
+public class MsgTest {
+
+ private static final String ACCESS_TOKEN = "37_GEl-Cwm-eYMf061QhVyPBGMqmMwucJrqC7BFQa3neeFMjik1xKdZDnNWUSwM_UnKb9xNtTgcZba_X3odvC069CCft2aLRNl8MdojGvYzLytv66v4B8r0RUjO4z08bLwViDfbbwayEJWvC0sHTVKjAFAWYN";
+
+ @Test
+ public void template() {
+ RestTemplate restTemplate = new RestTemplate();
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("touser", "oXtnkwxZGEccnCVitqEcFV6TyNvM");
+ jsonObject.put("template_id", "K5MLWBBVBE30bIo1cc04nYoePRWN5wlqlWDU9x5lxc4");
+ jsonObject.put("url", "https://www.baidu.com");
+ jsonObject.put("topcolor", "#FF0000");
+
+ JSONObject data = new JSONObject();
+ JSONObject startTime = new JSONObject();
+ startTime.put("value", "2020-09-15 08:00");
+ startTime.put("color", "#173177");
+ data.put("startTime", startTime);
+
+ JSONObject endTime = new JSONObject();
+ endTime.put("value", "2020-09-15 18:00");
+ endTime.put("color", "#173177");
+ data.put("endTime", endTime);
+
+ JSONObject remarks = new JSONObject();
+ remarks.put("value", "这里是相关备注信息");
+ remarks.put("color", "#173177");
+ data.put("remarks", remarks);
+
+ jsonObject.put("data", data);
+
+ ResponseEntity result = restTemplate.postForEntity("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={access_token}", jsonObject, JSONObject.class, ACCESS_TOKEN);
+ System.out.println(result.getStatusCode());
+ System.out.println(result.getBody());
+ }
+
+ @Test
+ public void groupMessage() {
+ RestTemplate restTemplate = new RestTemplate();
+ JSONObject jsonObject = new JSONObject();
+
+ JSONArray touser = new JSONArray();
+ touser.add("oXtnkwxZGEccnCVitqEcFV6TyNvM");
+ touser.add("oXtnkw8l7ZtDyJufeHSCIXWRK84c");
+ jsonObject.put("touser", touser);
+ jsonObject.put("msgtype", "text");
+
+ JSONObject text = new JSONObject();
+ text.put("content", "您好微信
");
+ jsonObject.put("text", text);
+
+ ResponseEntity result = restTemplate.postForEntity("https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token={access_token}", jsonObject, JSONObject.class, ACCESS_TOKEN);
+ System.out.println(result.getStatusCode());
+ System.out.println(result.getBody());
+ }
+
+}