From 3c885449e26a6b5147fd28c5b030a2de1fac5185 Mon Sep 17 00:00:00 2001 From: qi_liang Date: Sat, 7 Mar 2020 02:16:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BE=AE=E4=BF=A1=E5=9B=9E?= =?UTF-8?q?=E5=A4=8D=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/lq/wechat/web/WechatController.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/lq/wechat/web/WechatController.java b/src/main/java/com/lq/wechat/web/WechatController.java index 86ccb02..3ffb1c5 100755 --- a/src/main/java/com/lq/wechat/web/WechatController.java +++ b/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); //微信公众号详情 WechatInfo wechatInfo = wechatInfoService.getByOpenId(wechatOpenId); - + BaseMessage baseMessage = null; if (wechatInfo!=null) { TextMessage text = new TextMessage(); text.setFromUserName(wechatOpenId); @@ -99,36 +99,37 @@ public class WechatController extends BaseController { switch (msgType) { case ConstantSet.MESSAGE_TYPE_TEXT: String content = map.get(WECHAT_CONTENT_KEY); - BaseMessage baseMessage = wechatRuleService.getByKeyworkdAndWechatInfoId(content, wechatInfo); - baseMessage.setCreateTime(System.currentTimeMillis()); - baseMessage.setFromUserName(wechatOpenId); - baseMessage.setToUserName(openId); - message = MessageUtil.MessageToXml(baseMessage); + baseMessage = wechatRuleService.getByKeyworkdAndWechatInfoId(content, wechatInfo); + if (baseMessage!=null) { + baseMessage.setCreateTime(System.currentTimeMillis()); + baseMessage.setFromUserName(wechatOpenId); + baseMessage.setToUserName(openId); + }else { + // + text.setContent("服务器繁忙!"); + baseMessage = text; + + } + break; case ConstantSet.MESSAGE_TYPE_IMAGE: text.setContent("您发送的消息是:" + "图片"); - message = MessageUtil.MessageToXml(text); break; case ConstantSet.MESSAGE_TYPE_VIDEO: text.setContent("您发送的消息是:" + "视频"); - message = MessageUtil.MessageToXml(text); break; case ConstantSet.MESSAGE_TYPE_SHORTVIDEO: text.setContent("您发送的消息是:" + "小视频"); - message = MessageUtil.MessageToXml(text); break; case ConstantSet.MESSAGE_TYPE_VOICE: text.setContent("您发送的消息是:" + "语音"); - message = MessageUtil.MessageToXml(text); break; case ConstantSet.MESSAGE_TYPE_LINK: text.setContent("您发送的消息是:" + "链接"); - message = MessageUtil.MessageToXml(text); break; case ConstantSet.MESSAGE_TYPE_LOCATION: text.setContent("您发送的消息是:" + "位置"); - message = MessageUtil.MessageToXml(text); break; case ConstantSet.MESSAGE_TYPE_EVENT: String event = map.get("Event"); @@ -158,9 +159,10 @@ public class WechatController extends BaseController { default: text.setContent("您发送的消息是:" + "无法理解"); - message = MessageUtil.MessageToXml(text); + baseMessage = text; break; } + message = MessageUtil.MessageToXml(baseMessage); } } catch (Exception e) {