主要删除多个回复相关类
This commit is contained in:
parent
bda860bb6c
commit
4ecf2c4764
@ -38,11 +38,8 @@ public class Weixin4jServerStartupWithoutThread {
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public static void main(String[] args) throws WeixinException {
|
||||
//ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
|
||||
// new String[] { "classpath:/spring-bean.xml" });
|
||||
new WeixinServerBootstrap(aesToken)
|
||||
.handlerPackagesToScan(handlerPackage).openAlwaysResponse()
|
||||
//.resolveBeanFactory(new SpringBeanFactory(applicationContext))
|
||||
.startup(port);
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,9 +20,13 @@ import com.foxinmy.weixin4j.response.WeixinResponse;
|
||||
*/
|
||||
@Component
|
||||
public class HelloMessageHandler extends MessageHandlerAdapter<TextMessage> {
|
||||
|
||||
@Override
|
||||
public boolean canHandle0(WeixinRequest request, TextMessage message)
|
||||
throws WeixinException {
|
||||
/**
|
||||
* 用户输入hello时
|
||||
*/
|
||||
return message.getContent().equalsIgnoreCase("hello");
|
||||
}
|
||||
|
||||
|
||||
@ -141,4 +141,4 @@
|
||||
|
||||
+ 修改ClassUtil获取class不到的bug
|
||||
|
||||
+ 新增MultipleMessageHandlerAdapter多个消息适配类
|
||||
+ ~~新增MultipleMessageHandlerAdapter多个消息适配类~~
|
||||
@ -143,7 +143,7 @@ public class WeixinMessageDispatcher {
|
||||
response = handlerExecutor.getMessageHandler().doHandle(request,
|
||||
message, messageTransfer.getNodeNames());
|
||||
handlerExecutor.applyPostHandle(request, response, message);
|
||||
context.write(response);
|
||||
context.writeAndFlush(response);
|
||||
} catch (Exception e) {
|
||||
exception = e;
|
||||
}
|
||||
|
||||
@ -1,85 +0,0 @@
|
||||
package com.foxinmy.weixin4j.response;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 多个消息回复
|
||||
*
|
||||
* @className MultipleResponse
|
||||
* @author jy
|
||||
* @date 2016年4月27日
|
||||
* @since JDK 1.6
|
||||
* @see
|
||||
*/
|
||||
public class MultipleResponse implements WeixinResponse {
|
||||
|
||||
private List<WeixinResponse> responses;
|
||||
|
||||
public MultipleResponse(WeixinResponse... responses) {
|
||||
if (responses == null) {
|
||||
throw new IllegalArgumentException("responses not be empty");
|
||||
}
|
||||
this.responses = Arrays.asList(responses);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMsgType() {
|
||||
return "multiple";
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入首条回复
|
||||
*
|
||||
* @param response
|
||||
*/
|
||||
public void addFirstResponse(WeixinResponse response) {
|
||||
responses.add(0, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除首条回复
|
||||
*
|
||||
* @return 移除的回复
|
||||
*/
|
||||
public WeixinResponse removeFirstResponse() {
|
||||
return responses.remove(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入末条回复
|
||||
*
|
||||
* @param response
|
||||
*/
|
||||
public void addLastResponse(WeixinResponse response) {
|
||||
responses.add(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除末条回复
|
||||
*
|
||||
* @return 移除的回复
|
||||
*/
|
||||
public WeixinResponse removeLastResponse() {
|
||||
return responses.remove(responses.size() - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的回复
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<WeixinResponse> getResponses() {
|
||||
return this.responses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toContent() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MultipleResponse [responses=" + responses + "]";
|
||||
}
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
package com.foxinmy.weixin4j.socket;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToMessageEncoder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.foxinmy.weixin4j.response.MultipleResponse;
|
||||
import com.foxinmy.weixin4j.response.WeixinResponse;
|
||||
|
||||
/**
|
||||
* 微信多个回复编码类
|
||||
*
|
||||
* @className WeixinResponseEncoder
|
||||
* @author jy
|
||||
* @date 2016年4月27日
|
||||
* @since JDK 1.6
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/0/61c3a8b9d50ac74f18bdf2e54ddfc4e0.html">加密接入指引</a>
|
||||
* @see com.foxinmy.weixin4j.response.MultipleResponse
|
||||
*/
|
||||
public class MultipleResponseEncoder extends
|
||||
MessageToMessageEncoder<MultipleResponse> {
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, MultipleResponse response,
|
||||
List<Object> out) throws Exception {
|
||||
for (WeixinResponse r : response.getResponses()) {
|
||||
ctx.writeAndFlush(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -39,7 +39,6 @@ public class WeixinServerInitializer extends ChannelInitializer<SocketChannel> {
|
||||
pipeline.addLast(new WeixinMessageDecoder(aesTokenMap));
|
||||
pipeline.addLast(new WeixinResponseEncoder());
|
||||
pipeline.addLast(new SingleResponseEncoder());
|
||||
pipeline.addLast(new MultipleResponseEncoder());
|
||||
pipeline.addLast(new WeixinRequestHandler(messageDispatcher));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user