Commit e18ac461eaf66c83a0ae31a7e85565c639c40388
1 parent
90bdc1fd
fix: 修复公众号模块,当粉丝第一次关注的时候会出现错误(公众号粉丝不存在)
Showing
1 changed file
with
9 additions
and
3 deletions
yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/message/MpMessageServiceImpl.java
| 1 | package cn.iocoder.yudao.module.mp.service.message; | 1 | package cn.iocoder.yudao.module.mp.service.message; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.lang.Assert; | 3 | import cn.hutool.core.lang.Assert; |
| 4 | +import cn.hutool.core.util.ObjUtil; | ||
| 4 | import cn.hutool.core.util.StrUtil; | 5 | import cn.hutool.core.util.StrUtil; |
| 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | import cn.iocoder.yudao.module.mp.controller.admin.message.vo.message.MpMessagePageReqVO; | 7 | import cn.iocoder.yudao.module.mp.controller.admin.message.vo.message.MpMessagePageReqVO; |
| @@ -17,6 +18,8 @@ import cn.iocoder.yudao.module.mp.service.account.MpAccountService; | @@ -17,6 +18,8 @@ import cn.iocoder.yudao.module.mp.service.account.MpAccountService; | ||
| 17 | import cn.iocoder.yudao.module.mp.service.material.MpMaterialService; | 18 | import cn.iocoder.yudao.module.mp.service.material.MpMaterialService; |
| 18 | import cn.iocoder.yudao.module.mp.service.message.bo.MpMessageSendOutReqBO; | 19 | import cn.iocoder.yudao.module.mp.service.message.bo.MpMessageSendOutReqBO; |
| 19 | import cn.iocoder.yudao.module.mp.service.user.MpUserService; | 20 | import cn.iocoder.yudao.module.mp.service.user.MpUserService; |
| 21 | +import jakarta.annotation.Resource; | ||
| 22 | +import jakarta.validation.Validator; | ||
| 20 | import lombok.extern.slf4j.Slf4j; | 23 | import lombok.extern.slf4j.Slf4j; |
| 21 | import me.chanjar.weixin.common.api.WxConsts; | 24 | import me.chanjar.weixin.common.api.WxConsts; |
| 22 | import me.chanjar.weixin.common.error.WxErrorException; | 25 | import me.chanjar.weixin.common.error.WxErrorException; |
| @@ -28,9 +31,6 @@ import org.springframework.context.annotation.Lazy; | @@ -28,9 +31,6 @@ import org.springframework.context.annotation.Lazy; | ||
| 28 | import org.springframework.stereotype.Service; | 31 | import org.springframework.stereotype.Service; |
| 29 | import org.springframework.validation.annotation.Validated; | 32 | import org.springframework.validation.annotation.Validated; |
| 30 | 33 | ||
| 31 | -import jakarta.annotation.Resource; | ||
| 32 | -import jakarta.validation.Validator; | ||
| 33 | - | ||
| 34 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 34 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 35 | import static cn.iocoder.yudao.module.mp.enums.ErrorCodeConstants.MESSAGE_SEND_FAIL; | 35 | import static cn.iocoder.yudao.module.mp.enums.ErrorCodeConstants.MESSAGE_SEND_FAIL; |
| 36 | 36 | ||
| @@ -72,6 +72,12 @@ public class MpMessageServiceImpl implements MpMessageService { | @@ -72,6 +72,12 @@ public class MpMessageServiceImpl implements MpMessageService { | ||
| 72 | // 获得关联信息 | 72 | // 获得关联信息 |
| 73 | MpAccountDO account = mpAccountService.getAccountFromCache(appId); | 73 | MpAccountDO account = mpAccountService.getAccountFromCache(appId); |
| 74 | Assert.notNull(account, "公众号账号({}) 不存在", appId); | 74 | Assert.notNull(account, "公众号账号({}) 不存在", appId); |
| 75 | + | ||
| 76 | + // 订阅事件不记录,因为此时公众号粉丝表中还没有此粉丝的数据 | ||
| 77 | + if (ObjUtil.equal(wxMessage.getEvent(), WxConsts.EventType.SUBSCRIBE)) { | ||
| 78 | + return; | ||
| 79 | + } | ||
| 80 | + | ||
| 75 | MpUserDO user = mpUserService.getUser(appId, wxMessage.getFromUser()); | 81 | MpUserDO user = mpUserService.getUser(appId, wxMessage.getFromUser()); |
| 76 | Assert.notNull(user, "公众号粉丝({}/{}) 不存在", appId, wxMessage.getFromUser()); | 82 | Assert.notNull(user, "公众号粉丝({}/{}) 不存在", appId, wxMessage.getFromUser()); |
| 77 | 83 |