From da03dbc7c55c989825740359d8ecb736795bc545 Mon Sep 17 00:00:00 2001 From: zhizhi wu <2377881365@qq.com> Date: Tue, 2 Mar 2021 14:52:25 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=B6=88=E6=81=AF=E5=9B=9E=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wxconfigurer/bean/vo/WxReplyNewsVo.java | 84 +++++++++++++++++++ .../wxconfigurer/bean/vo/WxReplyVo.java | 26 ++++++ .../wxconfigurer/config/SpringConfig.java | 4 +- .../wxconfigurer/util/WxGzhUtil.java | 35 ++++++++ .../wxconfigurer/web/rest/WxController.java | 25 ++++++ 5 files changed, 172 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/ccsens/opensource/wxconfigurer/bean/vo/WxReplyNewsVo.java create mode 100644 src/main/java/com/ccsens/opensource/wxconfigurer/bean/vo/WxReplyVo.java diff --git a/src/main/java/com/ccsens/opensource/wxconfigurer/bean/vo/WxReplyNewsVo.java b/src/main/java/com/ccsens/opensource/wxconfigurer/bean/vo/WxReplyNewsVo.java new file mode 100644 index 0000000..53ecb88 --- /dev/null +++ b/src/main/java/com/ccsens/opensource/wxconfigurer/bean/vo/WxReplyNewsVo.java @@ -0,0 +1,84 @@ +package com.ccsens.opensource.wxconfigurer.bean.vo; + +import com.ccsens.opensource.wxconfigurer.util.JacksonUtil; +import com.ccsens.opensource.wxconfigurer.util.WxGzhUtil; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +/** + * @description: 微信被动回复用户消息--图文消息 + * @author: whj + * @time: 2020/12/22 16:08 + */ + +@Data +@JacksonXmlRootElement(localName = "xml") +public class WxReplyNewsVo extends WxReplyVo { + + /** + * 图文消息个数;当用户发送文本、图片、语音、视频、图文、地理位置这六种消息时,开发者只能回复1条图文消息;其余场景最多可回复8条图文消息 + */ + @JacksonXmlProperty(localName = "ArticleCount") + private Integer articleCount; + @JacksonXmlProperty(localName = "item") + @JacksonXmlElementWrapper(localName="Articles") + private List articles = new ArrayList<>(); + /** + * 图文消息信息,注意,如果图文数超过限制,则将只发限制内的条数 + */ + @Data + public static class Item { + /** + * 图文消息标题 + */ + @JacksonXmlProperty(localName = "Title") + private String title; + /** + * 图文消息描述 + */ + @JacksonXmlProperty(localName = "Description") + private String description; + /** + * 图片链接,支持JPG、PNG格式,较好的效果为大图360*200,小图200*200 + */ + @JacksonXmlProperty(localName = "PicUrl") + private String picUrl; + /** + * 点击图文消息跳转链接 + */ + @JacksonXmlProperty(localName = "Url") + private String url; + + public Item(String title, String description, String picUrl, String url) { + this.title = title; + this.description = description; + this.picUrl = picUrl; + this.url = url; + } + } + + + + + public WxReplyNewsVo(){ + this.msgType = "news"; + } + + public WxReplyNewsVo(String gzhId, String openId){ + this(); + this.gzhId = gzhId; + this.openId = openId; + } + + public static void main(String[] args) throws JsonProcessingException { + WxReplyNewsVo vo = new WxReplyNewsVo(); + vo.getArticles().add(WxGzhUtil.Reply.news.get("平车")); + System.out.println(JacksonUtil.beanToXml(vo)); + } +} diff --git a/src/main/java/com/ccsens/opensource/wxconfigurer/bean/vo/WxReplyVo.java b/src/main/java/com/ccsens/opensource/wxconfigurer/bean/vo/WxReplyVo.java new file mode 100644 index 0000000..d4661c5 --- /dev/null +++ b/src/main/java/com/ccsens/opensource/wxconfigurer/bean/vo/WxReplyVo.java @@ -0,0 +1,26 @@ +package com.ccsens.opensource.wxconfigurer.bean.vo; + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; +import lombok.Data; + +/** + * @description: 微信被动回复用户消息 + * @author: whj + * @time: 2020/12/22 16:02 + */ +@Data +@JacksonXmlRootElement(localName = "xml") +public class WxReplyVo { + + + @JacksonXmlProperty(localName = "FromUserName") + protected String gzhId; + @JacksonXmlProperty(localName = "ToUserName") + protected String openId; + @JacksonXmlProperty(localName = "CreateTime") + protected Long createTime = System.currentTimeMillis(); + @JacksonXmlProperty(localName = "MsgType") + protected String msgType; + +} diff --git a/src/main/java/com/ccsens/opensource/wxconfigurer/config/SpringConfig.java b/src/main/java/com/ccsens/opensource/wxconfigurer/config/SpringConfig.java index d7b7c60..7126131 100644 --- a/src/main/java/com/ccsens/opensource/wxconfigurer/config/SpringConfig.java +++ b/src/main/java/com/ccsens/opensource/wxconfigurer/config/SpringConfig.java @@ -100,8 +100,8 @@ public class SpringConfig implements WebMvcConfigurer { .addResourceLocations("classpath:/META-INF/resources/"); registry.addResourceHandler("/webjars/**") .addResourceLocations("classpath:/META-INF/resources/webjars/"); -// registry.addResourceHandler("/uploads/**") -// .addResourceLocations("file:///home/umg/uploads/"); + registry.addResourceHandler("/uploads/**") + .addResourceLocations("file:///home/wxconfigurer/uploads/"); } /** diff --git a/src/main/java/com/ccsens/opensource/wxconfigurer/util/WxGzhUtil.java b/src/main/java/com/ccsens/opensource/wxconfigurer/util/WxGzhUtil.java index ba4463a..5db3f46 100644 --- a/src/main/java/com/ccsens/opensource/wxconfigurer/util/WxGzhUtil.java +++ b/src/main/java/com/ccsens/opensource/wxconfigurer/util/WxGzhUtil.java @@ -7,6 +7,7 @@ import cn.hutool.http.HttpRequest; import com.alibaba.fastjson.JSONException; import com.alibaba.fastjson.JSONObject; import com.ccsens.opensource.wxconfigurer.bean.po.*; +import com.ccsens.opensource.wxconfigurer.bean.vo.WxReplyNewsVo; import com.ccsens.opensource.wxconfigurer.exception.BaseException; import com.ccsens.opensource.wxconfigurer.exception.BusinessException; import com.ccsens.opensource.wxconfigurer.exception.WxException; @@ -18,6 +19,7 @@ import org.slf4j.LoggerFactory; import java.io.IOException; import java.security.MessageDigest; import java.util.Arrays; +import java.util.HashMap; import java.util.Map; /** @@ -73,6 +75,38 @@ public class WxGzhUtil { private static final String ENCODING_AES_KEY = "MQEXG7grhRNsARbUzem6OwnGr2ZW9o5jsauNqaQWOuu"; private static final String MCHID = ""; private static final String KEY = ""; + + /** + * 被动回复用户消息 + */ + public static class Reply{ + /** + * 记录不同文本的不同返回结果 + */ + public static final Map types = new HashMap<>(); + /** + * 记录图文返回关系 + */ + public static final Map news = new HashMap<>(); + + static { + types.put("智慧平车", ReplyType.NEWS); + types.put("平车", ReplyType.NEWS); + news.put("智慧平车", new WxReplyNewsVo.Item("用户指南 | 智慧平车产品说明书v1.0", "用户指南 | 智慧平车产品说明书v1.0", "https://www.tall.wiki/wxconfigurer-api/uploads/reply/wisdomcar.jpg", "https://www.yuque.com/docs/share/d0393d9f-66db-4e76-b039-d78989f6f4c5")); + news.put("平车", new WxReplyNewsVo.Item("用户指南 | 智慧平车产品说明书v1.0", "用户指南 | 智慧平车产品说明书v1.0", "https://www.tall.wiki/wxconfigurer-api/uploads/reply/wisdomcar.jpg", "https://www.yuque.com/docs/share/d0393d9f-66db-4e76-b039-d78989f6f4c5")); + } + + + public enum ReplyType{ + TEXT, + IMAGE, + VOICE, + VIDEO, + MUSIC, + NEWS; + } + } + public static final class Field{ public static final int SUCCESS_CODE = 0; public static final String ERROR_CODE = "errcode"; @@ -88,6 +122,7 @@ public class WxGzhUtil { } public static class FieldValue{ public final static String EVENT = "event"; + public final static String EVENT_TEXT = "text"; /**订阅*/ public final static String SUBSCRIBE= "subscribe"; /**取消订阅*/ diff --git a/src/main/java/com/ccsens/opensource/wxconfigurer/web/rest/WxController.java b/src/main/java/com/ccsens/opensource/wxconfigurer/web/rest/WxController.java index 8bf163b..60737a0 100644 --- a/src/main/java/com/ccsens/opensource/wxconfigurer/web/rest/WxController.java +++ b/src/main/java/com/ccsens/opensource/wxconfigurer/web/rest/WxController.java @@ -6,7 +6,9 @@ import cn.hutool.core.util.StrUtil; import com.ccsens.opensource.wxconfigurer.bean.dto.WxGzhAction; import com.ccsens.opensource.wxconfigurer.bean.po.WxGzhAuthType; import com.ccsens.opensource.wxconfigurer.bean.po.WxGzhMenu; +import com.ccsens.opensource.wxconfigurer.bean.vo.WxReplyNewsVo; import com.ccsens.opensource.wxconfigurer.service.IUserService; +import com.ccsens.opensource.wxconfigurer.util.JacksonUtil; import com.ccsens.opensource.wxconfigurer.util.JsonResponse; import com.ccsens.opensource.wxconfigurer.util.WxGzhUtil; import io.swagger.annotations.Api; @@ -84,6 +86,29 @@ public class WxController { default:break; } + } else if(WxGzhUtil.FieldValue.EVENT_TEXT.equals(wxGzhAction.getMsgType())){ + // 回复文本消息 + log.info("接收的消息内容:{}", wxGzhAction.getContent()); + WxGzhUtil.Reply.ReplyType replyType = WxGzhUtil.Reply.types.get(wxGzhAction.getContent()); + if (replyType == null) { + return ""; + } + switch (replyType) { + case NEWS: + WxReplyNewsVo.Item item = WxGzhUtil.Reply.news.get(wxGzhAction.getContent()); + WxReplyNewsVo vo = new WxReplyNewsVo(wxGzhAction.getGzhId(), wxGzhAction.getOpenId()); + vo.getArticles().add(item); + vo.setArticleCount(vo.getArticles().size()); + log.info("自动回复图文:{}", vo); + return JacksonUtil.beanToXml(vo); + case TEXT: + case IMAGE: + case MUSIC: + case VIDEO: + case VOICE: + default: + break; + } } return ""; } From 70443be2e1675bf803fdd48f1724b617a276aed6 Mon Sep 17 00:00:00 2001 From: zhizhi wu <2377881365@qq.com> Date: Tue, 2 Mar 2021 14:54:14 +0800 Subject: [PATCH 2/3] ht www.tall --- .../ccsens/opensource/wxconfigurer/web/rest/WxController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/ccsens/opensource/wxconfigurer/web/rest/WxController.java b/src/main/java/com/ccsens/opensource/wxconfigurer/web/rest/WxController.java index 60737a0..e1bbbfb 100644 --- a/src/main/java/com/ccsens/opensource/wxconfigurer/web/rest/WxController.java +++ b/src/main/java/com/ccsens/opensource/wxconfigurer/web/rest/WxController.java @@ -136,7 +136,7 @@ public class WxController { String ccshopMiniprogramPage = "pages/tabbar/mall/mall?scene=issue_665123784503701504"; String commonUrl = "https://www.ccsens.com"; String wikiUrl = "https://www.yuque.com/ccsens"; - String htproUrl = "https://test.tall.wiki/ht-dev/zy"; + String htproUrl = "https://www.tall.wiki/ht-dev/zy"; String historyUrl = "https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=MzI4NjI4NTA1Ng==&scene=124#wechat_redirect"; String mtproUrl = "https://www.tall.wiki/mt/"; String ygczUrl = "https://test.tall.wiki/pt-dev/zy"; From 814ca4d54e48603700467e269bde038471763ed2 Mon Sep 17 00:00:00 2001 From: zhizhi wu <2377881365@qq.com> Date: Tue, 30 Mar 2021 14:55:17 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=9B=9E=E5=A4=8D?= =?UTF-8?q?=E6=A0=87=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ccsens/opensource/wxconfigurer/util/WxGzhUtil.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/ccsens/opensource/wxconfigurer/util/WxGzhUtil.java b/src/main/java/com/ccsens/opensource/wxconfigurer/util/WxGzhUtil.java index 5db3f46..5ee0f39 100644 --- a/src/main/java/com/ccsens/opensource/wxconfigurer/util/WxGzhUtil.java +++ b/src/main/java/com/ccsens/opensource/wxconfigurer/util/WxGzhUtil.java @@ -92,8 +92,8 @@ public class WxGzhUtil { static { types.put("智慧平车", ReplyType.NEWS); types.put("平车", ReplyType.NEWS); - news.put("智慧平车", new WxReplyNewsVo.Item("用户指南 | 智慧平车产品说明书v1.0", "用户指南 | 智慧平车产品说明书v1.0", "https://www.tall.wiki/wxconfigurer-api/uploads/reply/wisdomcar.jpg", "https://www.yuque.com/docs/share/d0393d9f-66db-4e76-b039-d78989f6f4c5")); - news.put("平车", new WxReplyNewsVo.Item("用户指南 | 智慧平车产品说明书v1.0", "用户指南 | 智慧平车产品说明书v1.0", "https://www.tall.wiki/wxconfigurer-api/uploads/reply/wisdomcar.jpg", "https://www.yuque.com/docs/share/d0393d9f-66db-4e76-b039-d78989f6f4c5")); + news.put("智慧平车", new WxReplyNewsVo.Item("用户指南 | 智慧平车产品说明书", "用户指南 | 智慧平车产品说明书", "https://www.tall.wiki/wxconfigurer-api/uploads/reply/wisdomcar.jpg", "https://www.yuque.com/docs/share/d0393d9f-66db-4e76-b039-d78989f6f4c5")); + news.put("平车", new WxReplyNewsVo.Item("用户指南 | 智慧平车产品说明书", "用户指南 | 智慧平车产品说明书", "https://www.tall.wiki/wxconfigurer-api/uploads/reply/wisdomcar.jpg", "https://www.yuque.com/docs/share/d0393d9f-66db-4e76-b039-d78989f6f4c5")); }