yujian
2019-04-19 e61108b9d44f0afc0c303db8914ebcc590c7013d
微信激活、绑定优化
2个文件已修改
71 ■■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserAccountServiceImpl.java 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoExtraServiceImpl.java 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserAccountServiceImpl.java
@@ -1100,18 +1100,23 @@
        if (weiXinUser == null) {
            throw new UserAccountException(2, "微信帐号授权失败");
        }
        if (weiXinUser.getUnionid().equalsIgnoreCase(user.getWxUnionId())) {
        String wxUnionId = weiXinUser.getUnionid();
        if (StringUtil.isNullOrEmpty(wxUnionId)) {
            throw new UserAccountException(2, "微信帐号授权失败");
        }
        String wxUnionIdExist = user.getWxUnionId();
        if (StringUtil.isNullOrEmpty(wxUnionIdExist)) {
            UserInfo newUser = userInfoMapper.getEffectiveUserInfoByWXUnionId(wxUnionId);
            if (newUser != null) {
                throw new UserAccountException(4, "该微信号已被其他帐号绑定");
            }
        } else if (wxUnionId.equals(wxUnionIdExist)) {
            throw new UserAccountException(3, "微信帐号一致无需更换");
        }
        UserInfo newUser = userInfoMapper.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid());
        if (newUser != null) {
            throw new UserAccountException(4, "该微信号已被其他帐号绑定");
        }
        String wxUnionId = user.getWxUnionId();
        if (!StringUtil.isNullOrEmpty(wxUnionId) && StringUtil.isNullOrEmpty(user.getPhone())) {
        if (StringUtil.isNullOrEmpty(user.getPhone())) {
            throw new UserAccountException(5, "该帐号没有绑定手机号码,需绑定手机号码才能完成微信更换");
        }
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoExtraServiceImpl.java
@@ -385,7 +385,7 @@
    @Override
    public void activationInviteWX(Long uid, String code) throws UserInfoExtraException{
        if (uid == null || code == null) {
            throw new UserInfoExtraException(1, "用户id、邀请码不能为空");
            throw new UserInfoExtraException(1, "激活信息不完整");
        }
        
        // 用户信息
@@ -403,7 +403,6 @@
            }
        }
        
        // 获取微信信息
        WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(code);
        if (weiXinUser == null) {
@@ -414,24 +413,31 @@
            throw new UserInfoExtraException(1, "微信授权失败");
        }
        
        // 自动绑定微信
        UserInfo updateUserInfo = new UserInfo(uid);
        updateUserInfo.setWxName(weiXinUser.getNickname());
        updateUserInfo.setWxOpenId(weiXinUser.getOpenid());
        updateUserInfo.setWxPic(weiXinUser.getHeadimgurl());
        updateUserInfo.setWxUnionId(weiXinUser.getUnionid());
        updateUserInfo.setNickName(weiXinUser.getNickname());
        updateUserInfo.setPortrait(weiXinUser.getHeadimgurl());
        if (StringUtil.isNullOrEmpty(weiXinUser.getNickname())) {
            updateUserInfo.setNickName(Constant.systemCommonConfig.getDefaultNickName());
        // 验证数据
        String wxUnionIdExist = invitee.getWxUnionId();
        if (StringUtil.isNullOrEmpty(wxUnionIdExist)) {
            UserInfo newUser = userInfoService.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid());
            if (newUser != null) {
                throw new UserInfoExtraException(1, "此微信已被其他帐号绑定");
            }
            // 自动绑定微信
            UserInfo updateUserInfo = new UserInfo(uid);
            updateUserInfo.setWxOpenId(weiXinUser.getOpenid());
            updateUserInfo.setWxUnionId(weiXinUser.getUnionid());
            if (!StringUtil.isNullOrEmpty(weiXinUser.getNickname())) {
                updateUserInfo.setWxName(weiXinUser.getNickname());
                updateUserInfo.setNickName(weiXinUser.getNickname());
            }
            if (!StringUtil.isNullOrEmpty(weiXinUser.getHeadimgurl())) {
                updateUserInfo.setWxPic(weiXinUser.getHeadimgurl());
                updateUserInfo.setPortrait(weiXinUser.getHeadimgurl());
            }
            userInfoService.updateByPrimaryKeySelective(updateUserInfo);
        } else if (!wxUnionId.equals(wxUnionIdExist)){
            throw new UserInfoExtraException(1, "绑定微信与激活微信不一致");
        }
        if (StringUtil.isNullOrEmpty(weiXinUser.getHeadimgurl())) {
            updateUserInfo.setPortrait(Constant.systemCommonConfig.getDefaultPortrait());
        }
        userInfoService.updateByPrimaryKeySelective(updateUserInfo);
        
        
        // 邀请人ID -1.5.3新版
@@ -453,7 +459,7 @@
        
        // 没有被邀请过
        if (inviterId == null && threeSale == null) {
            throw new UserInfoExtraException(1, "微信激活失败");
            throw new UserInfoExtraException(1, "没有对应的邀请关系");
        }
        
        // 绑定关系
@@ -465,7 +471,7 @@
            } catch (Exception e1) {
                e1.printStackTrace();
            }
            throw new UserInfoExtraException(1, "激活失败");
            throw new UserInfoExtraException(1, "关系绑定时失败");
        }