Commit 563985dcfc9e68ddc208f72c811ff0b2ced83cf2
1 parent
d8e16104
feat:【MP 公众号】兼容无 API 权限的个人公众号场景
Showing
1 changed file
with
10 additions
and
1 deletions
yudao-module-mp/src/main/java/cn/iocoder/yudao/module/mp/service/handler/user/SubscribeHandler.java
| 1 | 1 | package cn.iocoder.yudao.module.mp.service.handler.user; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.util.ObjUtil; | |
| 3 | 4 | import cn.iocoder.yudao.module.mp.framework.mp.core.context.MpContextHolder; |
| 4 | 5 | import cn.iocoder.yudao.module.mp.service.message.MpAutoReplyService; |
| 5 | 6 | import cn.iocoder.yudao.module.mp.service.user.MpUserService; |
| 7 | +import jakarta.annotation.Resource; | |
| 6 | 8 | import lombok.extern.slf4j.Slf4j; |
| 7 | 9 | import me.chanjar.weixin.common.error.WxErrorException; |
| 10 | +import me.chanjar.weixin.common.error.WxMpErrorMsgEnum; | |
| 8 | 11 | import me.chanjar.weixin.common.session.WxSessionManager; |
| 9 | 12 | import me.chanjar.weixin.mp.api.WxMpMessageHandler; |
| 10 | 13 | import me.chanjar.weixin.mp.api.WxMpService; |
| ... | ... | @@ -13,7 +16,6 @@ import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; |
| 13 | 16 | import me.chanjar.weixin.mp.bean.result.WxMpUser; |
| 14 | 17 | import org.springframework.stereotype.Component; |
| 15 | 18 | |
| 16 | -import jakarta.annotation.Resource; | |
| 17 | 19 | import java.util.Map; |
| 18 | 20 | |
| 19 | 21 | /** |
| ... | ... | @@ -40,6 +42,13 @@ public class SubscribeHandler implements WxMpMessageHandler { |
| 40 | 42 | wxMpUser = weixinService.getUserService().userInfo(wxMessage.getFromUser()); |
| 41 | 43 | } catch (WxErrorException e) { |
| 42 | 44 | log.error("[handle][粉丝({})] 获取粉丝信息失败!", wxMessage.getFromUser(), e); |
| 45 | + // 特殊情况(个人账号,无接口权限):https://t.zsxq.com/cLFq5 | |
| 46 | + if (ObjUtil.equal(e.getError().getErrorCode(), WxMpErrorMsgEnum.CODE_48001)) { | |
| 47 | + wxMpUser = new WxMpUser(); | |
| 48 | + wxMpUser.setOpenId(wxMessage.getFromUser()); | |
| 49 | + wxMpUser.setSubscribe(true); | |
| 50 | + wxMpUser.setSubscribeTime(System.currentTimeMillis() / 1000L); | |
| 51 | + } | |
| 43 | 52 | } |
| 44 | 53 | |
| 45 | 54 | // 第二步,保存粉丝信息 | ... | ... |