|
@@ -2,13 +2,16 @@ package com.miaxis.wx.service.impl;
|
|
|
|
|
|
import cn.hutool.json.XML;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.miaxis.common.constant.Constants;
|
|
|
import com.miaxis.common.core.domain.entity.UserInfo;
|
|
|
import com.miaxis.common.utils.StringUtils;
|
|
|
import com.miaxis.common.utils.wx.MessageUtil;
|
|
|
import com.miaxis.feign.service.IWxSendService;
|
|
|
import com.miaxis.system.service.ISysUserService;
|
|
|
+import com.miaxis.wx.domain.WxForeverCode;
|
|
|
import com.miaxis.wx.mapper.WxMenuMapper;
|
|
|
+import com.miaxis.wx.service.IWxForeverCodeService;
|
|
|
import com.miaxis.wx.service.IWxGzhService;
|
|
|
import com.miaxis.wx.service.IWxMessageEvenService;
|
|
|
import com.qcloud.cos.COSClient;
|
|
@@ -45,6 +48,8 @@ public class WxGzhServiceImpl implements IWxGzhService {
|
|
|
|
|
|
private final IWxMessageEvenService wxMessageEvenService;
|
|
|
|
|
|
+ private final IWxForeverCodeService wxForeverCodeService;
|
|
|
+
|
|
|
@Value("${app.appid}")
|
|
|
private String appid;
|
|
|
|
|
@@ -104,12 +109,27 @@ public class WxGzhServiceImpl implements IWxGzhService {
|
|
|
String fromUserName = jsonObjectData.getStr("FromUserName");
|
|
|
// 区分消息类型
|
|
|
String msgType = jsonObjectData.getStr("MsgType");
|
|
|
+ //获取用户信息
|
|
|
+ String userInfoResult = wxSendService.userInfo(this.getGzhToken(), fromUserName, "zh_CN");
|
|
|
+ JSONObject jsonObj = JSONObject.parseObject(userInfoResult);
|
|
|
|
|
|
// 普通消息
|
|
|
if (MessageUtil.MESSAGE_TEXT.equals(msgType)) { // 文本消息
|
|
|
log.info("2.1...");
|
|
|
String content = jsonObjectData.getStr("Content");
|
|
|
- if (content.startsWith("你好")){
|
|
|
+ WxForeverCode wxForeverCode = wxForeverCodeService.getOne(new QueryWrapper<WxForeverCode>().eq("code", content).eq("openid",null));
|
|
|
+ //若该口令为未使用的口令
|
|
|
+ if (wxForeverCode != null){
|
|
|
+ log.info("2.1.1:口令有效,生成永久二维码");
|
|
|
+ String mediaId = wxMessageEvenService.gainTicketEvent(fromUserName, this.getGzhToken(),true);
|
|
|
+ //更新口令数据对象
|
|
|
+ wxForeverCode.setOpenid(jsonObj.getString("openid"));
|
|
|
+ wxForeverCode.setNickName(jsonObj.getString("nickname"));
|
|
|
+ wxForeverCode.setMediaId(mediaId);
|
|
|
+ wxForeverCodeService.updateById(wxForeverCode);
|
|
|
+ return MessageUtil.initImage(fromUserName,toUserName,mediaId);
|
|
|
+ }
|
|
|
+ else if (content.startsWith("你好")){
|
|
|
return MessageUtil.initText(fromUserName, toUserName, "你好啊");
|
|
|
}else if (content.startsWith("傻逼")){
|
|
|
return MessageUtil.initText(fromUserName, toUserName, "你才是煞笔");
|
|
@@ -127,9 +147,7 @@ public class WxGzhServiceImpl implements IWxGzhService {
|
|
|
if (MessageUtil.MESSAGE_SUBSCRIBE.equals(event)) { // 关注事件 或 扫描二维码关注事件
|
|
|
log.info("3.1...");
|
|
|
|
|
|
- //获取用户信息
|
|
|
- String userInfoResult = wxSendService.userInfo(this.getGzhToken(), fromUserName, "zh_CN");
|
|
|
- JSONObject jsonObj = JSONObject.parseObject(userInfoResult);
|
|
|
+
|
|
|
UserInfo user = userService.getStudentByOpenId(fromUserName);
|
|
|
UserInfo userInfo = new UserInfo();
|
|
|
if (user == null){
|
|
@@ -165,7 +183,13 @@ public class WxGzhServiceImpl implements IWxGzhService {
|
|
|
log.info("3.3.....click:" + jsonObjectData.get("EventKey"));
|
|
|
//判断事件KEY值,与自定义菜单接口中KEY值对应
|
|
|
if ("generateTicket".equals(jsonObjectData.get("EventKey"))){ //获取分销二维码
|
|
|
- String mediaId = wxMessageEvenService.gainTicketEvent(fromUserName, this.getGzhToken());
|
|
|
+ //先判定之前是否存在永久码,若存在,则返回相应的素材id
|
|
|
+ WxForeverCode wxForeverCode = wxForeverCodeService.getOne(new QueryWrapper<WxForeverCode>().eq("openid",fromUserName));
|
|
|
+ if (wxForeverCode!=null){
|
|
|
+ log.info("3.4:直接返回永久码图片");
|
|
|
+ return wxForeverCode.getMediaId();
|
|
|
+ }
|
|
|
+ String mediaId = wxMessageEvenService.gainTicketEvent(fromUserName, this.getGzhToken(), false);
|
|
|
return MessageUtil.initImage(fromUserName,toUserName,mediaId);
|
|
|
}
|
|
|
|