|
@@ -1,34 +1,45 @@
|
|
|
package com.ifast.wxmp.handler;
|
|
|
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-
|
|
|
import com.ifast.wxmp.builder.TextBuilder;
|
|
|
+import com.ifast.wxmp.domain.MpFansDO;
|
|
|
+import com.ifast.wxmp.service.MpConfigService;
|
|
|
+import com.ifast.wxmp.service.MpFansService;
|
|
|
import com.ifast.wxmp.service.WeixinService;
|
|
|
-
|
|
|
+import com.ifast.wxmp.util.WxMpConfigHolder;
|
|
|
import me.chanjar.weixin.common.exception.WxErrorException;
|
|
|
import me.chanjar.weixin.common.session.WxSessionManager;
|
|
|
import me.chanjar.weixin.mp.api.WxMpService;
|
|
|
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
|
|
|
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
|
|
|
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
* <pre>
|
|
|
+ * 关注
|
|
|
* </pre>
|
|
|
- *
|
|
|
+ * <p>
|
|
|
* <small> 2018年6月13日 | Aron</small>
|
|
|
*/
|
|
|
@Component
|
|
|
public class SubscribeHandler extends AbstractHandler {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private MpFansService mpFansService;
|
|
|
+ @Autowired
|
|
|
+ private MpConfigService mpConfigService;
|
|
|
+
|
|
|
@Override
|
|
|
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService,
|
|
|
- WxSessionManager sessionManager) throws WxErrorException {
|
|
|
+ WxSessionManager sessionManager) throws WxErrorException {
|
|
|
|
|
|
- this.logger.info("新关注用户 OPENID: " + wxMessage.getFromUser());
|
|
|
+ this.logger.info("新关注用户 openid: " + wxMessage.getFromUser());
|
|
|
|
|
|
WeixinService weixinService = (WeixinService) wxMpService;
|
|
|
|
|
@@ -36,7 +47,11 @@ public class SubscribeHandler extends AbstractHandler {
|
|
|
WxMpUser userWxInfo = weixinService.getUserService().userInfo(wxMessage.getFromUser(), null);
|
|
|
|
|
|
if (userWxInfo != null) {
|
|
|
- // TODO 可以添加关注用户到本地
|
|
|
+ this.logger.debug("同步微信用户信息数据");
|
|
|
+ MpFansDO fans = new MpFansDO();
|
|
|
+ convert(userWxInfo, fans);
|
|
|
+ mpFansService.sync(fans);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
WxMpXmlOutMessage responseResult = null;
|
|
@@ -59,11 +74,40 @@ public class SubscribeHandler extends AbstractHandler {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ private void convert(WxMpUser wxUser, MpFansDO fans) {
|
|
|
+ BeanUtils.copyProperties(wxUser, fans);
|
|
|
+// fans.setCity(wxUser.getCity());
|
|
|
+// fans.setCountry(wxUser.getCountry());
|
|
|
+ fans.setGroupid(wxUser.getGroupId());
|
|
|
+ fans.setHeadimgurl(wxUser.getHeadImgUrl());
|
|
|
+// fans.setLanguage(wxUser.getLanguage());
|
|
|
+// fans.setNickname(wxUser.getNickname());
|
|
|
+ fans.setOpenid(wxUser.getOpenId());
|
|
|
+// fans.setProvince(wxUser.getProvince());
|
|
|
+// fans.setRemark(wxUser.getRemark());
|
|
|
+// fans.setSex(wxUser.getSex());
|
|
|
+ fans.setMpId(this.getMpIdByAppId(WxMpConfigHolder.getCurrentAppId()));
|
|
|
+ // fans.setStatus(status);
|
|
|
+ // fans.setSubscribeKey();
|
|
|
+ fans.setSubscribe(wxUser.getSubscribe() ? 1 : 0);
|
|
|
+ fans.setSubscribeTime(new Date());
|
|
|
+ fans.setTagidList(Arrays.toString(wxUser.getTagIds()));
|
|
|
+ fans.setUnionid(wxUser.getUnionId());
|
|
|
+
|
|
|
+ this.logger.debug("convert return :{}", fans);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public long getMpIdByAppId(String appId) {
|
|
|
+ return mpConfigService.findOneByKv("app_id", appId).getId();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 处理特殊请求,比如如果是扫码进来的,可以做相应处理
|
|
|
*/
|
|
|
protected WxMpXmlOutMessage handleSpecial(WxMpXmlMessage wxMessage) throws Exception {
|
|
|
// TODO
|
|
|
+ logger.debug("扫码事件触发... :", wxMessage);
|
|
|
return null;
|
|
|
}
|
|
|
|