LocationHandler.java 1.6 KB

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