View Javadoc
1   package com.foxinmy.weixin4j.example.server.handler;
2   
3   import java.util.Set;
4   
5   import com.foxinmy.weixin4j.exception.WeixinException;
6   import com.foxinmy.weixin4j.handler.WeixinMessageHandler;
7   import com.foxinmy.weixin4j.request.WeixinMessage;
8   import com.foxinmy.weixin4j.request.WeixinRequest;
9   import com.foxinmy.weixin4j.response.TextResponse;
10  import com.foxinmy.weixin4j.response.WeixinResponse;
11  
12  /**
13   * 自定义处理消息
14   *
15   * @className CustomMessageHandler
16   * @author jinyu(foxinmy@gmail.com)
17   * @date 2017年1月19日
18   * @since JDK 1.6
19   * @see
20   */
21  public class CustomMessageHandler implements WeixinMessageHandler {
22  
23      @Override
24      public boolean canHandle(WeixinRequest request, WeixinMessage message, Set<String> nodeNames) {
25          // 消息来源某个用户
26          return message.getFromUserName().equals("xxx");
27      }
28  
29      @Override
30      public WeixinResponse doHandle(WeixinRequest request, WeixinMessage messager) {
31          return new TextResponse("是你,是你,还是你。");
32      }
33  
34      @Override
35      public int weight() {
36          return 0;
37      }
38  }