Browse Source

Merge branch 'master' of gitee.com:ccsens_s/wxconfigurer

master
zy_Java 4 years ago
parent
commit
8379a8f61e
  1. 84
      src/main/java/com/ccsens/opensource/wxconfigurer/bean/vo/WxReplyNewsVo.java
  2. 26
      src/main/java/com/ccsens/opensource/wxconfigurer/bean/vo/WxReplyVo.java
  3. 4
      src/main/java/com/ccsens/opensource/wxconfigurer/config/SpringConfig.java
  4. 35
      src/main/java/com/ccsens/opensource/wxconfigurer/util/WxGzhUtil.java
  5. 28
      src/main/java/com/ccsens/opensource/wxconfigurer/web/rest/WxController.java

84
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<Item> articles = new ArrayList<>();
/**
* 图文消息信息注意如果图文数超过限制则将只发限制内的条数
*/
@Data
public static class Item {
/**
* 图文消息标题
*/
@JacksonXmlProperty(localName = "Title")
private String title;
/**
* 图文消息描述
*/
@JacksonXmlProperty(localName = "Description")
private String description;
/**
* 图片链接支持JPGPNG格式较好的效果为大图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));
}
}

26
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;
}

4
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/");
}
/**

35
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<String, ReplyType> types = new HashMap<>();
/**
* 记录图文返回关系
*/
public static final Map<String, WxReplyNewsVo.Item> news = new HashMap<>();
static {
types.put("智慧平车", ReplyType.NEWS);
types.put("平车", ReplyType.NEWS);
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"));
}
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";
/**取消订阅*/

28
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 "";
}
@ -111,8 +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";

Loading…
Cancel
Save