Blame view

parking-module-system/src/main/java/com/zteits/wxcp/handler/LocationHandler.java 1.44 KB
55f68655   王彪总   新项目
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  package com.zteits.wxcp.handler;
  
  import java.util.Map;
  
  import org.springframework.stereotype.Component;
  
  import com.zteits.wxcp.builder.TextBuilder;
  import me.chanjar.weixin.common.api.WxConsts;
  import me.chanjar.weixin.common.session.WxSessionManager;
  import me.chanjar.weixin.cp.api.WxCpService;
  import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
  import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage;
  
  /**
   * @author Binary Wang(https://github.com/binarywang)
   */
  @Component
  public class LocationHandler extends AbstractHandler {
  
    @Override
    public WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage, Map<String, Object> context, WxCpService cpService,
                                    WxSessionManager sessionManager) {
      if (wxMessage.getMsgType().equals(WxConsts.XmlMsgType.LOCATION)) {
        //TODO 接收处理用户发送的地理位置消息
        try {
          String content = "感谢反馈,您的的地理位置已收到!";
          return new TextBuilder().build(content, wxMessage, null);
        } catch (Exception e) {
          this.logger.error("位置消息接收处理失败", e);
          return null;
        }
      }
  
      //上报地理位置事件
      this.logger.info("\n上报地理位置,纬度 : {}\n经度 : {}\n精度 : {}",
          wxMessage.getLatitude(), wxMessage.getLongitude(), String.valueOf(wxMessage.getPrecision()));
  
      //TODO  可以将用户地理位置信息保存到本地数据库,以便以后使用
  
      return null;
    }
  
  }