com.foxinmy.weixin4j.socket.WeixinMessageDecoder Maven / Gradle / Ivy
package com.foxinmy.weixin4j.socket;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import com.foxinmy.weixin4j.request.WeixinRequest;
import com.foxinmy.weixin4j.type.EncryptType;
import com.foxinmy.weixin4j.util.AesToken;
import com.foxinmy.weixin4j.util.MessageUtil;
import com.foxinmy.weixin4j.util.ServerToolkits;
import com.foxinmy.weixin4j.xml.EncryptMessageHandler;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.QueryStringDecoder;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
/**
* 微信消息解码类
*
* @className WeixinMessageDecoder
* @author jinyu([email protected])
* @date 2014年11月13日
* @since JDK 1.6
* @see 加密接入指引
* @see com.foxinmy.weixin4j.request.WeixinRequest
*/
@ChannelHandler.Sharable
public class WeixinMessageDecoder extends MessageToMessageDecoder {
private final InternalLogger logger = InternalLoggerFactory.getInstance(getClass());
private Map aesTokenMap = new ConcurrentHashMap();
public WeixinMessageDecoder(final Map aesTokenMap) {
for (Entry entry : aesTokenMap.entrySet()) {
this.aesTokenMap.put(entry.getKey() == null ? "" : entry.getKey(), entry.getValue());
}
}
public void addAesToken(final AesToken asetoken) {
aesTokenMap.put(asetoken.getWeixinId(), asetoken);
}
@Override
protected void decode(ChannelHandlerContext ctx, FullHttpRequest req, List