修改微信回复逻辑

master
星期八 5 years ago
parent 219a545025
commit 3c885449e2
  1. 28
      src/main/java/com/lq/wechat/web/WechatController.java

@ -87,7 +87,7 @@ public class WechatController extends BaseController {
String openId = map.get(WECHAT_USER_OPENID_KEY); String openId = map.get(WECHAT_USER_OPENID_KEY);
//微信公众号详情 //微信公众号详情
WechatInfo wechatInfo = wechatInfoService.getByOpenId(wechatOpenId); WechatInfo wechatInfo = wechatInfoService.getByOpenId(wechatOpenId);
BaseMessage baseMessage = null;
if (wechatInfo!=null) { if (wechatInfo!=null) {
TextMessage text = new TextMessage(); TextMessage text = new TextMessage();
text.setFromUserName(wechatOpenId); text.setFromUserName(wechatOpenId);
@ -99,36 +99,37 @@ public class WechatController extends BaseController {
switch (msgType) { switch (msgType) {
case ConstantSet.MESSAGE_TYPE_TEXT: case ConstantSet.MESSAGE_TYPE_TEXT:
String content = map.get(WECHAT_CONTENT_KEY); String content = map.get(WECHAT_CONTENT_KEY);
BaseMessage baseMessage = wechatRuleService.getByKeyworkdAndWechatInfoId(content, wechatInfo); baseMessage = wechatRuleService.getByKeyworkdAndWechatInfoId(content, wechatInfo);
baseMessage.setCreateTime(System.currentTimeMillis()); if (baseMessage!=null) {
baseMessage.setFromUserName(wechatOpenId); baseMessage.setCreateTime(System.currentTimeMillis());
baseMessage.setToUserName(openId); baseMessage.setFromUserName(wechatOpenId);
message = MessageUtil.MessageToXml(baseMessage); baseMessage.setToUserName(openId);
}else {
//
text.setContent("服务器繁忙!");
baseMessage = text;
}
break; break;
case ConstantSet.MESSAGE_TYPE_IMAGE: case ConstantSet.MESSAGE_TYPE_IMAGE:
text.setContent("您发送的消息是:" + "图片"); text.setContent("您发送的消息是:" + "图片");
message = MessageUtil.MessageToXml(text);
break; break;
case ConstantSet.MESSAGE_TYPE_VIDEO: case ConstantSet.MESSAGE_TYPE_VIDEO:
text.setContent("您发送的消息是:" + "视频"); text.setContent("您发送的消息是:" + "视频");
message = MessageUtil.MessageToXml(text);
break; break;
case ConstantSet.MESSAGE_TYPE_SHORTVIDEO: case ConstantSet.MESSAGE_TYPE_SHORTVIDEO:
text.setContent("您发送的消息是:" + "小视频"); text.setContent("您发送的消息是:" + "小视频");
message = MessageUtil.MessageToXml(text);
break; break;
case ConstantSet.MESSAGE_TYPE_VOICE: case ConstantSet.MESSAGE_TYPE_VOICE:
text.setContent("您发送的消息是:" + "语音"); text.setContent("您发送的消息是:" + "语音");
message = MessageUtil.MessageToXml(text);
break; break;
case ConstantSet.MESSAGE_TYPE_LINK: case ConstantSet.MESSAGE_TYPE_LINK:
text.setContent("您发送的消息是:" + "链接"); text.setContent("您发送的消息是:" + "链接");
message = MessageUtil.MessageToXml(text);
break; break;
case ConstantSet.MESSAGE_TYPE_LOCATION: case ConstantSet.MESSAGE_TYPE_LOCATION:
text.setContent("您发送的消息是:" + "位置"); text.setContent("您发送的消息是:" + "位置");
message = MessageUtil.MessageToXml(text);
break; break;
case ConstantSet.MESSAGE_TYPE_EVENT: case ConstantSet.MESSAGE_TYPE_EVENT:
String event = map.get("Event"); String event = map.get("Event");
@ -158,9 +159,10 @@ public class WechatController extends BaseController {
default: default:
text.setContent("您发送的消息是:" + "无法理解"); text.setContent("您发送的消息是:" + "无法理解");
message = MessageUtil.MessageToXml(text); baseMessage = text;
break; break;
} }
message = MessageUtil.MessageToXml(baseMessage);
} }
} catch (Exception e) { } catch (Exception e) {

Loading…
Cancel
Save