mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-11-04 04:08:43 +08:00 
			
		
		
		
	【代码优化】SYSTEM:微信小程序的订阅
This commit is contained in:
		@@ -8,6 +8,7 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 | 
			
		||||
import cn.iocoder.yudao.module.system.api.social.dto.*;
 | 
			
		||||
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
 | 
			
		||||
import cn.iocoder.yudao.module.system.service.social.SocialClientService;
 | 
			
		||||
import cn.iocoder.yudao.module.system.service.social.SocialUserService;
 | 
			
		||||
import jakarta.annotation.Resource;
 | 
			
		||||
import lombok.extern.slf4j.Slf4j;
 | 
			
		||||
import me.chanjar.weixin.common.bean.WxJsapiSignature;
 | 
			
		||||
@@ -33,7 +34,7 @@ public class SocialClientApiImpl implements SocialClientApi {
 | 
			
		||||
    @Resource
 | 
			
		||||
    private SocialClientService socialClientService;
 | 
			
		||||
    @Resource
 | 
			
		||||
    public SocialUserApi socialUserApi;
 | 
			
		||||
    private SocialUserService socialUserService;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String getAuthorizeUrl(Integer socialType, Integer userType, String redirectUri) {
 | 
			
		||||
@@ -68,29 +69,29 @@ public class SocialClientApiImpl implements SocialClientApi {
 | 
			
		||||
    @Override
 | 
			
		||||
    public void sendWxaSubscribeMessage(SocialWxaSubscribeMessageSendReqDTO reqDTO) {
 | 
			
		||||
        // 1.1 获得订阅模版列表
 | 
			
		||||
        List<SocialWxaSubscribeTemplateRespDTO> templateList = getWxaSubscribeTemplateList(reqDTO.getUserType());
 | 
			
		||||
        List<TemplateInfo> templateList = socialClientService.getSubscribeTemplateList(reqDTO.getUserType());
 | 
			
		||||
        if (CollUtil.isEmpty(templateList)) {
 | 
			
		||||
            log.warn("[sendSubscribeMessage][reqDTO({}) 发送订阅消息失败,原因:没有找到订阅模板]", reqDTO);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        // 1.2 获得需要使用的模版
 | 
			
		||||
        SocialWxaSubscribeTemplateRespDTO template = findOne(templateList, item ->
 | 
			
		||||
        TemplateInfo template = findOne(templateList, item ->
 | 
			
		||||
                ObjUtil.equal(item.getTitle(), reqDTO.getTemplateTitle()));
 | 
			
		||||
        if (template == null) {
 | 
			
		||||
            log.warn("[sendSubscribeMessage][reqDTO({}) 发送订阅消息失败,原因:没有找到订阅模板]", reqDTO);
 | 
			
		||||
            log.warn("[sendWxaSubscribeMessage][reqDTO({}) 发送订阅消息失败,原因:没有找到订阅模板]", reqDTO);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 2. 获得社交用户
 | 
			
		||||
        SocialUserRespDTO socialUser = socialUserApi.getSocialUserByUserId(reqDTO.getUserType(), reqDTO.getUserId(),
 | 
			
		||||
        SocialUserRespDTO socialUser = socialUserService.getSocialUserByUserId(reqDTO.getUserType(), reqDTO.getUserId(),
 | 
			
		||||
                SocialTypeEnum.WECHAT_MINI_APP.getType());
 | 
			
		||||
        if (StrUtil.isBlankIfStr(socialUser.getOpenid())) {
 | 
			
		||||
            log.warn("[sendSubscribeMessage][reqDTO({}) 发送订阅消息失败,原因:会员 openid 缺失]", reqDTO);
 | 
			
		||||
            log.warn("[sendWxaSubscribeMessage][reqDTO({}) 发送订阅消息失败,原因:会员 openid 缺失]", reqDTO);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 3. 发送订阅消息
 | 
			
		||||
        socialClientService.sendSubscribeMessage(reqDTO, template.getId(), socialUser.getOpenid());
 | 
			
		||||
        socialClientService.sendSubscribeMessage(reqDTO, template.getPriTmplId(), socialUser.getOpenid());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user