You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
3.8 KiB
103 lines
3.8 KiB
package com.ynxbd.wx.servlet;
|
|
|
|
import com.ynxbd.common.result.Result;
|
|
import com.ynxbd.wx.config.WeChatConfig;
|
|
import com.ynxbd.wx.wxfactory.bean.event.WxEvent;
|
|
import com.ynxbd.wx.wxfactory.utils.WxEventHelper;
|
|
import com.ynxbd.wx.wxfactory.utils.WxPassiveReplyHelper;
|
|
import com.ynxbd.wx.wxfactory.utils.WxSignHelper;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import javax.servlet.annotation.WebServlet;
|
|
import javax.servlet.http.HttpServlet;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import java.io.IOException;
|
|
|
|
@Slf4j
|
|
@WebServlet("/wx")
|
|
public class WxServlet extends HttpServlet {
|
|
|
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
doPost(request, response);
|
|
}
|
|
|
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
request.setCharacterEncoding("UTF-8");
|
|
response.setCharacterEncoding("UTF-8");
|
|
|
|
WxEvent wxEvent = WxSignHelper.getReqXmlToBean(request, WxEvent.class);
|
|
// log.warn("wxEvent={}", wxEvent);
|
|
if (wxEvent == null) {
|
|
String echoStr = request.getParameter("echostr");
|
|
if (echoStr != null) {
|
|
Result.respStr(response, echoStr); // 首次请求申请验证,返回echoStr
|
|
return;
|
|
}
|
|
log.warn("[消息]event is null");
|
|
Result.respStr(response, WxPassiveReplyHelper.SUCCESS);
|
|
return;
|
|
}
|
|
|
|
if (WxEventHelper.filter(wxEvent)) {
|
|
Result.respStr(response, WxPassiveReplyHelper.SUCCESS);
|
|
return;
|
|
}
|
|
|
|
if (!WxEventHelper.verifyEventSign(request, WeChatConfig.TOKEN)) {
|
|
log.warn("[消息]验签失败");
|
|
Result.respStr(response, WxPassiveReplyHelper.SUCCESS);
|
|
return;
|
|
}
|
|
|
|
|
|
String msgId = wxEvent.getMsgId();
|
|
if (msgId == null) {
|
|
Result.respStr(response, WxPassiveReplyHelper.SUCCESS);
|
|
return;
|
|
}
|
|
String toUserName = wxEvent.getToUserName();
|
|
String fromUserName = wxEvent.getFromUserName();
|
|
|
|
String key = fromUserName + "_" + toUserName + "_" + msgId + "_" + wxEvent.getCreateTime();
|
|
if (WxPassiveReplyHelper.isRepeat(key)) {
|
|
Result.respStr(response, WxPassiveReplyHelper.SUCCESS);
|
|
return;
|
|
}
|
|
|
|
String eventKey = wxEvent.getEventKey();
|
|
String event = wxEvent.getEvent();
|
|
String msgType = wxEvent.getMsgType();
|
|
String content = wxEvent.getContent();
|
|
content = content == null ? null : content.trim().toUpperCase();
|
|
|
|
WxPassiveReplyHelper.textCommon(response, content, msgType, fromUserName, toUserName);
|
|
|
|
switch (WeChatConfig.APP_ID) {
|
|
case "wx18b15dc67fc96f89":
|
|
WxPassiveReplyHelper.华坪县人民医院(response, content, msgType, fromUserName, toUserName, eventKey, event);
|
|
break;
|
|
|
|
case "wx1e30610a28d189a8":
|
|
WxPassiveReplyHelper.巍山县人民医院(response, content, msgType, fromUserName, toUserName, eventKey, event);
|
|
break;
|
|
|
|
case "wxca97aaeb3c40c0d0":
|
|
WxPassiveReplyHelper.芒市县人民医院(response, content, msgType, fromUserName, toUserName, eventKey, event);
|
|
break;
|
|
|
|
case "wxd503671f502bd89d":
|
|
WxPassiveReplyHelper.红河州第一人民医院(response, content, msgType, fromUserName, toUserName, eventKey, event);
|
|
break;
|
|
|
|
case "wx1f1e9d29f9b44c36":
|
|
WxPassiveReplyHelper.玉龙县人民医院(response, content, msgType, fromUserName, toUserName, eventKey, event);
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
Result.respStr(response, WxPassiveReplyHelper.SUCCESS);
|
|
}
|
|
|
|
}
|
|
|