up
This commit is contained in:
parent
7c3857c789
commit
31d85f713b
@ -37,6 +37,7 @@ import com.foxinmy.weixin4j.socket.WeixinMessageTransfer;
|
|||||||
import com.foxinmy.weixin4j.util.ClassUtil;
|
import com.foxinmy.weixin4j.util.ClassUtil;
|
||||||
import com.foxinmy.weixin4j.util.HttpUtil;
|
import com.foxinmy.weixin4j.util.HttpUtil;
|
||||||
import com.foxinmy.weixin4j.util.ServerToolkits;
|
import com.foxinmy.weixin4j.util.ServerToolkits;
|
||||||
|
import com.foxinmy.weixin4j.xml.MessageTransferHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信消息分发器
|
* 微信消息分发器
|
||||||
@ -115,8 +116,11 @@ public class WeixinMessageDispatcher {
|
|||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
*/
|
*/
|
||||||
public void doDispatch(final ChannelHandlerContext context,
|
public void doDispatch(final ChannelHandlerContext context,
|
||||||
final WeixinRequest request,
|
final WeixinRequest request) throws WeixinException {
|
||||||
final WeixinMessageTransfer messageTransfer) throws WeixinException {
|
WeixinMessageTransfer messageTransfer = MessageTransferHandler
|
||||||
|
.parser(request);
|
||||||
|
context.channel().attr(ServerToolkits.MESSAGE_TRANSFER_KEY)
|
||||||
|
.set(messageTransfer);
|
||||||
WeixinMessageKey messageKey = defineMessageKey(messageTransfer, request);
|
WeixinMessageKey messageKey = defineMessageKey(messageTransfer, request);
|
||||||
Class<? extends WeixinMessage> targetClass = messageMatcher
|
Class<? extends WeixinMessage> targetClass = messageMatcher
|
||||||
.match(messageKey);
|
.match(messageKey);
|
||||||
|
|||||||
@ -59,7 +59,6 @@ public class WeixinMessage implements Serializable {
|
|||||||
private long createTime;
|
private long createTime;
|
||||||
/**
|
/**
|
||||||
* 消息类型
|
* 消息类型
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@XmlElement(name = "MsgType")
|
@XmlElement(name = "MsgType")
|
||||||
private String msgType;
|
private String msgType;
|
||||||
@ -75,7 +74,7 @@ public class WeixinMessage implements Serializable {
|
|||||||
private String agentId;
|
private String agentId;
|
||||||
|
|
||||||
public WeixinMessage() {
|
public WeixinMessage() {
|
||||||
|
// jaxb required
|
||||||
}
|
}
|
||||||
|
|
||||||
public WeixinMessage(String msgType) {
|
public WeixinMessage(String msgType) {
|
||||||
|
|||||||
@ -22,7 +22,6 @@ import com.foxinmy.weixin4j.util.AesToken;
|
|||||||
import com.foxinmy.weixin4j.util.HttpUtil;
|
import com.foxinmy.weixin4j.util.HttpUtil;
|
||||||
import com.foxinmy.weixin4j.util.MessageUtil;
|
import com.foxinmy.weixin4j.util.MessageUtil;
|
||||||
import com.foxinmy.weixin4j.util.ServerToolkits;
|
import com.foxinmy.weixin4j.util.ServerToolkits;
|
||||||
import com.foxinmy.weixin4j.xml.MessageTransferHandler;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信请求处理类
|
* 微信请求处理类
|
||||||
@ -57,7 +56,7 @@ public class WeixinRequestHandler extends
|
|||||||
@Override
|
@Override
|
||||||
protected void channelRead0(ChannelHandlerContext ctx, WeixinRequest request)
|
protected void channelRead0(ChannelHandlerContext ctx, WeixinRequest request)
|
||||||
throws WeixinException {
|
throws WeixinException {
|
||||||
final AesToken aesToken = request.getAesToken();
|
AesToken aesToken = request.getAesToken();
|
||||||
if (aesToken == null
|
if (aesToken == null
|
||||||
|| (ServerToolkits.isBlank(request.getSignature()) && ServerToolkits
|
|| (ServerToolkits.isBlank(request.getSignature()) && ServerToolkits
|
||||||
.isBlank(request.getMsgSignature()))) {
|
.isBlank(request.getMsgSignature()))) {
|
||||||
@ -112,11 +111,7 @@ public class WeixinRequestHandler extends
|
|||||||
.addListener(ChannelFutureListener.CLOSE);
|
.addListener(ChannelFutureListener.CLOSE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
WeixinMessageTransfer messageTransfer = MessageTransferHandler
|
messageDispatcher.doDispatch(ctx, request);
|
||||||
.parser(request);
|
|
||||||
ctx.channel().attr(ServerToolkits.MESSAGE_TRANSFER_KEY)
|
|
||||||
.set(messageTransfer);
|
|
||||||
messageDispatcher.doDispatch(ctx, request, messageTransfer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private FullHttpResponse resolveResponse(HttpResponseStatus responseStatus,
|
private FullHttpResponse resolveResponse(HttpResponseStatus responseStatus,
|
||||||
|
|||||||
@ -31,7 +31,7 @@ public final class ServerToolkits {
|
|||||||
public static final String CONTENTTYPE$TEXT_PLAIN = "text/plain";
|
public static final String CONTENTTYPE$TEXT_PLAIN = "text/plain";
|
||||||
|
|
||||||
public static final AttributeKey<WeixinMessageTransfer> MESSAGE_TRANSFER_KEY = AttributeKey
|
public static final AttributeKey<WeixinMessageTransfer> MESSAGE_TRANSFER_KEY = AttributeKey
|
||||||
.valueOf("$_MESSAGETRANSFER");
|
.valueOf("attr:MESSAGETRANSFER");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回一个定长的随机字符串(包含数字和大小写字母)
|
* 返回一个定长的随机字符串(包含数字和大小写字母)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user