云
6 天以前 d0cf2cb2c352bdeb146aad2bb57ba7d39cef3bbd
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialUserServiceImpl.java
@@ -47,6 +47,24 @@
    private SocialClientService socialClientService;
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void bindApprovedWxcpUser(String openid, Long userId) {
        int type = 30;
        int userType = cn.iocoder.yudao.framework.common.enums.UserTypeEnum.ADMIN.getValue();
        SocialUserDO socialUser = socialUserMapper.selectByTypeAndOpenid(type, openid);
        if (socialUser == null) throw new IllegalStateException("企业微信身份不存在,请重新扫码");
        SocialUserBindDO existing = socialUserBindMapper.selectByUserTypeAndSocialUserId(userType, socialUser.getId());
        if (existing != null) {
            if (!existing.getUserId().equals(userId)) throw new IllegalStateException("该企业微信身份已绑定其他账号");
            return;
        }
        if (socialUserBindMapper.selectByUserIdAndUserTypeAndSocialType(userId, userType, type) != null)
            throw new IllegalStateException("该账号已绑定其他企业微信身份");
        socialUserBindMapper.insert(SocialUserBindDO.builder().userId(userId).userType(userType)
                .socialUserId(socialUser.getId()).socialType(type).build());
    }
    @Override
    public List<SocialUserDO> getSocialUserList(Long userId, Integer userType) {
        // 获得绑定
        List<SocialUserBindDO> socialUserBinds = socialUserBindMapper.selectListByUserIdAndUserType(userId, userType);
@@ -115,8 +133,18 @@
        // 获得绑定用户
        SocialUserBindDO socialUserBind = socialUserBindMapper.selectByUserTypeAndSocialUserId(userType,
                socialUser.getId());
        return new SocialUserRespDTO(socialUser.getOpenid(), socialUser.getNickname(), socialUser.getAvatar(),
        SocialUserRespDTO result = new SocialUserRespDTO(socialUser.getOpenid(), socialUser.getNickname(), socialUser.getAvatar(),
                socialUserBind != null ? socialUserBind.getUserId() : null);
        if (socialType == 30 && cn.hutool.core.util.StrUtil.isNotBlank(socialUser.getRawUserInfo())) {
            try {
                cn.hutool.json.JSONObject raw = cn.hutool.json.JSONUtil.parseObj(socialUser.getRawUserInfo());
                result.setMobile(raw.getStr("mobile"));
                if (cn.hutool.core.util.StrUtil.isBlank(result.getNickname())) result.setNickname(raw.getStr("name"));
            } catch (Exception ignored) {
                // 敏感信息不可用时不影响扫码,申请使用随机账号方案。
            }
        }
        return result;
    }
    /**