admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserAccountServiceImpl.java
@@ -8,11 +8,14 @@
import javax.servlet.http.HttpSession;
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.entity.config.SMSConfig;
import com.yeshi.fanli.entity.system.BusinessSystem;
import com.yeshi.fanli.entity.system.ConfigKeyEnum;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.config.SystemConfigService;
import com.yeshi.fanli.util.*;
import com.yeshi.fanli.vo.taobao.TaoBaoUser;
import com.yeshi.fanli.vo.user.QQUserInfoVO;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -104,6 +107,10 @@
    @Resource
    private UserInfoModifyRecordService userInfoModifyRecordService;
    @Resource
    private SystemConfigService systemConfigService;
    @Transactional(rollbackFor = Exception.class)
    @Override
    public LoginResult login(HttpServletRequest request, AcceptData acceptData, Boolean first, String appId,
@@ -123,7 +130,10 @@
        if (first != null && first == true) {
            session.removeAttribute("LAST_LOGIN_USER");
        }
            // 会话中上次登录的用户
        String defaultPortrait = userInfoService.getDefaultPortrait(acceptData.getSystem());
        // 会话中上次登录的用户
        if (wxinstall) {// 安装了微信的状态
            UserInfo lastUser = (UserInfo) session.getAttribute("LAST_LOGIN_USER");
            UserInfo userInfo = null;
@@ -328,8 +338,8 @@
                    if (userInfo == null) {// 原先的账号不存在
                        userInfo = new UserInfo();
                        userInfo.setAppId(appId);
                        userInfo.setNickName(Constant.systemCommonConfig.getDefaultNickName());
                        userInfo.setPortrait(Constant.systemCommonConfig.getDefaultPortrait());
                        userInfo.setNickName(null);
                        userInfo.setPortrait(defaultPortrait);
                        userInfo.setPhone(phone);
                        userInfo.setLoginType(loginType);
                        userInfo.setSystem(SystemInfoUtil.getSystem(acceptData));
@@ -372,6 +382,8 @@
            logInfo.put("tbUserInfo", tbUserInfo.getId());
        logInfo.put("loginType", loginType);
        LogHelper.lgoinInfo(logInfo.toString());
        String defaultPortrait = userInfoService.getDefaultPortrait(acceptData.getSystem());
        UserInfo userInfo = null;
        WeiXinUser weiXinUser = null;
@@ -440,8 +452,8 @@
                    break;
                case 3:// 手机号码
                    // 默认头像与昵称
                    userInfo.setPortrait(Constant.systemCommonConfig.getDefaultPortrait());
                    userInfo.setNickName(Constant.systemCommonConfig.getDefaultNickName());
                    userInfo.setPortrait(defaultPortrait);
                    userInfo.setNickName(null);
                    userInfo.setPhone(phone);
                    break;
            }
@@ -574,13 +586,16 @@
    public void addUser(UserInfo user) {
        user.setCreatetime(System.currentTimeMillis());
        user.setRank(0);
        if (StringUtil.isNullOrEmpty(user.getPortrait()))
            user.setPortrait(Constant.systemCommonConfig.getDefaultPortrait());
        if (StringUtil.isNullOrEmpty(user.getPortrait())) {
            String defaultPortrait = userInfoService.getDefaultPortrait(user.getSystem());
            user.setPortrait(defaultPortrait);
        }
        userInfoService.createUser(user, user.getSystem());
        // 昵称为空时 默认昵称
        if (StringUtil.isNullOrEmpty(user.getNickName())) {
            UserInfo updateUserInfo = new UserInfo(user.getId());
            updateUserInfo.setNickName(Constant.systemCommonConfig.getDefaultNickName() + user.getId());
            String defaultNickName = userInfoService.getDefaultNickName(user.getSystem(), user.getId());
            updateUserInfo.setNickName(defaultNickName);
            userInfoService.updateByPrimaryKeySelective(updateUserInfo);
        }
@@ -694,8 +709,8 @@
        update.setTbPic("");
        // 判断是否有微信绑定
        if (StringUtil.isNullOrEmpty(user.getWxUnionId())) {
            update.setNickName(Constant.systemCommonConfig.getDefaultNickName() + user.getId());
            update.setPortrait(Constant.systemCommonConfig.getDefaultPortrait());
            update.setNickName(userInfoService.getDefaultNickName(user.getSystem(), user.getId()));
            update.setPortrait(userInfoService.getDefaultPortrait(user.getSystem()));
        }
        userInfoService.updateByPrimaryKeySelective(update);
@@ -729,16 +744,15 @@
        updateUserInfo.setWxUnionId(weiXinUser.getUnionid());
        // 将默认昵称替换成微信昵称
        String defaultNickName = Constant.systemCommonConfig.getDefaultNickName();
        if (!StringUtil.isNullOrEmpty(defaultNickName) && !StringUtil.isNullOrEmpty(weiXinUser.getNickname())) {
            defaultNickName = defaultNickName + uid;
        if (!StringUtil.isNullOrEmpty(weiXinUser.getNickname())) {
            String defaultNickName = userInfoService.getDefaultNickName(user.getSystem(), uid);
            if ((defaultNickName.equals(user.getNickName()) || "板栗快省".equals(user.getNickName()))) {
                updateUserInfo.setNickName(weiXinUser.getNickname());
            }
        }
        // 将默认头像替换成微信头像
        String defaultPortrait = Constant.systemCommonConfig.getDefaultPortrait();
        String defaultPortrait = userInfoService.getDefaultPortrait(user.getSystem());
        if (!StringUtil.isNullOrEmpty(weiXinUser.getHeadimgurl()) && !StringUtil.isNullOrEmpty(defaultPortrait)
                && defaultPortrait.equals(user.getPortrait())) {
            updateUserInfo.setPortrait(weiXinUser.getHeadimgurl());
@@ -795,72 +809,82 @@
                return portrait;
            }
        }
        return user.getPortrait();
    }
    @Override
    public String getMobile(String vcode, String phone, String aliAccessToken, SystemEnum system, int vcodeType) throws UserAccountException {
        if (!StringUtil.isNullOrEmpty(aliAccessToken)) {
            String mobile = AliyunOneKeyLoginUtil.getMobile(aliAccessToken, "");
            if (StringUtil.isNullOrEmpty(mobile)) {
                throw new UserAccountException(1, "手机号获取失败");
            }
            return mobile;
        } else {
            // 空额清理
            if (phone == null || phone.trim().length() == 0) {
                throw new UserAccountException(1, "请输入手机号码");
            }
            phone = phone.replaceAll(" ", "");
            boolean isDemo = false;
            //查询上线测试的号码与验证码
            String demoLogin = configService.getValue(ConfigKeyEnum.demoLoginUser, system);
            if (!StringUtil.isNullOrEmpty(demoLogin)) {
                String demoPhone = demoLogin.split("#")[0];
                String demoCode = demoLogin.split("#")[1];
                if (phone.equalsIgnoreCase(demoPhone) && demoCode.equalsIgnoreCase(vcode)) {
                    isDemo = true;
                }
            }
            // 苹果应用商店上线测试号码
            if (!isDemo) {
                if (StringUtil.isNullOrEmpty(vcode)) {
                    throw new UserAccountException(1, "请输入验证码");
                }
                String oldVcode = redisManager.getSMSVCode(phone, vcodeType);
                LogHelper.test("----------------------登录验证码: " + oldVcode);
                if (!Constant.IS_TEST)
                    if (StringUtil.isNullOrEmpty(oldVcode) || !oldVcode.equalsIgnoreCase(vcode)) {
                        throw new UserAccountException(1, "验证码错误,重新输入");
                    } else {// 验证码输入正确
                        redisManager.clearSMSVCode(phone, vcodeType);
                    }
            }
            return phone;
        }
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public UserInfo loginPhone(ProxyIP ipInfo, int loginType, String vcode, String phone, BusinessSystem businessSystem)
    public UserInfo loginPhone(ProxyIP ipInfo, int loginType, String vcode, String phone, String aliAccessToken, BusinessSystem businessSystem)
            throws UserAccountException {
        // 空额清理
        if (phone == null || phone.trim().length() == 0) {
            throw new UserAccountException(1, "请输入手机号码");
        }
        phone = phone.replaceAll(" ", "");
        boolean isDemo=false;
        //查询上线测试的号码与验证码
        String demoLogin = configService.getValue(ConfigKeyEnum.demoLoginUser, businessSystem.getSystem());
        if (!StringUtil.isNullOrEmpty(demoLogin)) {
            String demoPhone = demoLogin.split("#")[0];
            String demoCode = demoLogin.split("#")[1];
            if(phone.equalsIgnoreCase(demoPhone)&&demoCode.equalsIgnoreCase(vcode)){
                isDemo=true;
            }
        }
//        "17316780233".equalsIgnoreCase(phone) && "2581".equalsIgnoreCase(vcode);
        // 苹果应用商店上线测试号码
        if (isDemo) {//测试号码
            ;
        } else {
            if (StringUtil.isNullOrEmpty(vcode)) {
                throw new UserAccountException(1, "请输入验证码");
            }
            String oldVcode = redisManager.getSMSVCode(phone, SMSHistory.TYPE_LOGIN);
            LogHelper.test("----------------------登录验证码: " + oldVcode);
            if (!Constant.IS_TEST)
                if (StringUtil.isNullOrEmpty(oldVcode) || !oldVcode.equalsIgnoreCase(vcode)) {
                    throw new UserAccountException(1, "验证码错误,重新输入");
                } else {// 验证码输入正确
                    redisManager.clearSMSVCode(phone, SMSHistory.TYPE_LOGIN);
                }
        }
        String mobile = getMobile(vcode, phone, aliAccessToken, businessSystem.getSystem(), SMSHistory.TYPE_LOGIN);
        JSONObject logInfo = new JSONObject();
        logInfo.put("appId", businessSystem.getAppid());
        logInfo.put("phone", phone);
        logInfo.put("phone", mobile);
        logInfo.put("loginType", loginType);
        LogHelper.lgoinInfo(logInfo.toString());
        // 判断手机号码是否被封禁
        ForbiddenUserIdentifyCode identifyCode1 = forbiddenUserIdentifyCodeService
                .listByTypeAndIdentifyCode(ForbiddenUserIdentifyCodeTypeEnum.phone, phone);
                .listByTypeAndIdentifyCode(ForbiddenUserIdentifyCodeTypeEnum.phone, mobile);
        if (identifyCode1 != null && identifyCode1.getEffective() != null && identifyCode1.getEffective()) {
            throw new UserAccountException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC);
        }
        // 清空限制
        redisManager.clearSMSFrequencyLimit(phone, SMSHistory.TYPE_LOGIN);
        redisManager.clearSMSFrequencyLimit(mobile, SMSHistory.TYPE_LOGIN);
        // 清理次数
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSLoginCount, phone);
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.SMSLoginCount, mobile);
        redisManager.removeCommonString(key);
        // 采用redis事务防止一个手机号多次注册问题
        String watchKey = StringUtil.Md5("REGISTER:" + phone);
        String watchKey = StringUtil.Md5("REGISTER:" + mobile);
        Jedis jedis = redisManager.getJedis();
        try {
            jedis.watch(watchKey);
@@ -874,15 +898,15 @@
            } else {
                // 查询是否存在该电话历史用户
                UserInfo userInfo = userInfoService.getEffectiveUserInfoByPhone(phone, businessSystem.getSystem());
                UserInfo userInfo = userInfoService.getEffectiveUserInfoByPhone(mobile, businessSystem.getSystem());
                if (userInfo != null) {
                    // 更新账户登录信息
                    updateLonginInfo(userInfo, loginType, ipInfo);
                } else {
                    userInfo = new UserInfo();
                    userInfo.setAppId(businessSystem.getAppid());
                    userInfo.setPortrait(Constant.systemCommonConfig.getDefaultPortrait());
                    userInfo.setPhone(phone);
                    userInfo.setPortrait(null);
                    userInfo.setPhone(mobile);
                    userInfo.setLoginType(loginType);
                    userInfo.setState(UserInfo.STATE_NORMAL);
                    userInfo.setSystem(businessSystem.getSystem());
@@ -895,7 +919,7 @@
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    userInfoModifyRecordService.addModifyRecord(userInfo.getId(), ModifyTypeEnum.bindPhone, phone);
                    userInfoModifyRecordService.addModifyRecord(userInfo.getId(), ModifyTypeEnum.bindPhone, mobile);
                }
                return userInfo;
            }
@@ -1090,7 +1114,7 @@
                    }
                    if (StringUtil.isNullOrEmpty(portrait))
                        portrait = Constant.systemCommonConfig.getDefaultPortrait();
                        portrait = userInfoService.getDefaultPortrait(businessSystem.getSystem());
                    // 创建新账户
                    userInfo = new UserInfo();
@@ -1158,9 +1182,35 @@
        UserInfo userInfo = userInfoService.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid(), businessSystem.getSystem());
        if (userInfo == null) {
            String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.emptyKey,
                    StringUtil.Md5("WXLogin:" + weiXinUser.getUnionid()));
                    "WXLogin#" + StringUtil.Md5(weiXinUser.getUnionid()));
            redisManager.cacheCommonString(key, JsonUtil.getSimpleGson().toJson(weiXinUser), 60 * 20);
            throw new UserAccountException(101, key);
            throw new UserAccountException(UserAccountException.CODE_NEED_BIND_PHONE, key);
        }
        // 更新账户登录信息
        updateLonginInfo(userInfo, loginType, ipInfo);
        Long uid = userInfo.getId();
        ThreadUtil.run(new Runnable() {
            public void run() {
                // 删除邀请分享图
                spreadUserImgService.deleteImgUrl(uid);
            }
        });
        return userInfo;
    }
    @Override
    public UserInfo loginQQ(ProxyIP ipInfo, int loginType, QQUserInfoVO qqUserInfo, BusinessSystem businessSystem) throws UserAccountException {
        // 通过Code换取信息
        if (qqUserInfo == null) {
            throw new UserAccountException(1, "QQ信息为空");
        }
        UserInfo userInfo = userInfoService.getEffectiveUserInfoByQQOpenId(qqUserInfo.getOpenid(), businessSystem.getSystem());
        if (userInfo == null) {
            String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.emptyKey,
                    "QQLogin#" + StringUtil.Md5(qqUserInfo.getOpenid()));
            redisManager.cacheCommonString(key, JsonUtil.getSimpleGson().toJson(qqUserInfo), 60 * 20);
            throw new UserAccountException(UserAccountException.CODE_NEED_BIND_PHONE, key);
        }
        // 更新账户登录信息
        updateLonginInfo(userInfo, loginType, ipInfo);
@@ -1233,9 +1283,8 @@
    @Transactional(rollbackFor = UserAccountException.class)
    @Override
    public void bindWeiXin(AcceptData acceptData, Long uid, String code) throws UserAccountException {
        WXAccountInfoDTO wxAccount = Constant.getWXAccount(acceptData.getPlatform(), acceptData.getVersion());
        WeiXinUser weiXinUser = WXAppLoginUtil.getWeiXinUser(code, wxAccount.getAppId(), wxAccount.getAppSecret());
    public void bindWeiXin(BusinessSystem system, Long uid, String code) throws UserAccountException {
        WeiXinUser weiXinUser = WXAppLoginUtil.getWeiXinUser(code, system.getWxAppId(), system.getWxAppSecret());
        if (weiXinUser == null) {
            throw new UserAccountException(2, "微信帐号授权失败");
        }
@@ -1285,7 +1334,7 @@
        updateUserInfo.setWxUnionId(weiXinUser.getUnionid());
        // 将默认昵称替换成微信昵称
        String defaultNickName = Constant.systemCommonConfig.getDefaultNickName();
        String defaultNickName = userInfoService.getDefaultNickName(user.getSystem(), user.getId());
        if (!StringUtil.isNullOrEmpty(defaultNickName) && !StringUtil.isNullOrEmpty(weiXinUser.getNickname())) {
            defaultNickName = defaultNickName + uid;
            if ((defaultNickName.equals(user.getNickName()) || "板栗快省".equals(user.getNickName()))) {
@@ -1294,7 +1343,7 @@
        }
        // 将默认头像替换成微信头像
        String defaultPortrait = Constant.systemCommonConfig.getDefaultPortrait();
        String defaultPortrait = userInfoService.getDefaultPortrait(user.getSystem());
        if (!StringUtil.isNullOrEmpty(weiXinUser.getHeadimgurl()) && !StringUtil.isNullOrEmpty(defaultPortrait)
                && defaultPortrait.equals(user.getPortrait())) {
            String headimgurl = weiXinUser.getHeadimgurl();
@@ -1334,6 +1383,73 @@
    }
    @Override
    public void bindQQ(Long uid, QQUserInfoVO qqUser) throws UserAccountException {
        UserInfo user = userInfoService.selectAvailableByPrimaryKey(uid);
        if (user == null) {
            throw new UserAccountException(1, "用户不存在");
        }
        if (qqUser == null || StringUtil.isNullOrEmpty(qqUser.getOpenid())) {
            throw new UserAccountException(2, "qq用户信息为空");
        }
        String qqOpenIdExist = user.getQqOpenId();
        if (StringUtil.isNullOrEmpty(qqOpenIdExist)) {
            UserInfo newUser = userInfoService.getEffectiveUserInfoByQQOpenId(qqUser.getOpenid(), user.getSystem());
            if (newUser != null) {
                throw new UserAccountException(4, "该QQ号已被其他帐号绑定");
            }
        } else if (qqUser.getOpenid().equalsIgnoreCase(qqOpenIdExist)) {
            throw new UserAccountException(3, "QQ帐号一致无需更换");
        }
        if (StringUtil.isNullOrEmpty(user.getPhone())) {
            throw new UserAccountException(5, "该帐号没有绑定手机号码,需绑定手机号码才能完成QQ更换");
        }
        UserInfo updateUserInfo = new UserInfo(uid);
        updateUserInfo.setQqNickName(qqUser.getNickname());
        updateUserInfo.setQqOpenId(qqUser.getOpenid());
        // 将默认昵称替换成微信昵称
        String defaultNickName = userInfoService.getDefaultNickName(user.getSystem(), user.getId());
        if (!StringUtil.isNullOrEmpty(defaultNickName) && !StringUtil.isNullOrEmpty(qqUser.getNickname())) {
            defaultNickName = defaultNickName + uid;
            if ((defaultNickName.equals(user.getNickName()) || "板栗快省".equals(user.getNickName()))) {
                updateUserInfo.setNickName(qqUser.getNickname());
            }
        }
        // 将默认头像替换成QQ头像
        String defaultPortrait = userInfoService.getDefaultPortrait(user.getSystem());
        if (!StringUtil.isNullOrEmpty(qqUser.getFigureurl_2()) && !StringUtil.isNullOrEmpty(defaultPortrait)
                && defaultPortrait.equals(user.getPortrait())) {
            String headimgurl = qqUser.getFigureurl_2();
            updateUserInfo.setPortrait(headimgurl);
        }
        userInfoService.updateByPrimaryKeySelective(updateUserInfo);
        // 加入绑定记录
        UserAccountBindingHistory history = new UserAccountBindingHistory();
        history.setContent(qqUser.getOpenid());
        history.setType(UserAccountBindingHistory.TYPE_QQ);
        history.setUid(uid);
        // 之前已经绑定电话号码
        if (!StringUtil.isNullOrEmpty(user.getQqOpenId()))
            history.setFirst(false);
        else
            history.setFirst(true);
        userAccountBindingHistoryService.addUserAccountBindingHistory(history);
        userAccountMsgNotificationService.bindingSuccess(uid, MsgAccountDetailFactory.TYPE_QQ);
        userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindQQ, user.getQqOpenId());
    }
    @Override
    public UserInfo bindPhoneToLogin(ProxyIP ipinfo, AcceptData acceptData, String phone, String key)
            throws UserAccountException {
@@ -1343,51 +1459,111 @@
        if (identifyCode1 != null && identifyCode1.getEffective() != null && identifyCode1.getEffective())
            throw new UserAccountException(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC);
        int loginType = 0;
        String loginName = "";
        if (key.contains("QQLogin#")) {
            //qq登录
            loginType = 4;
            loginName = "QQ";
        } else {
            //微信登录
            loginType = 2;
            loginName = "微信";
        }
        String value = redisManager.getCommonString(key);
        if (StringUtil.isNullOrEmpty(value))
            throw new UserAccountException(1, "微信授权失效,请使用微信重新登录");
        WeiXinUser weiXinUser = JsonUtil.getSimpleGson().fromJson(value, WeiXinUser.class);
        if (weiXinUser == null)
            throw new UserAccountException(1, "微信授权失效,请使用微信重新登录");
            throw new UserAccountException(1, String.format("%s授权失效,请使用%s重新登录", loginName, loginName));
        SystemEnum system = SystemInfoUtil.getSystem(acceptData);
        String thirdPortrait;
        String thirdCode;
        String thirdNickName;
        QQUserInfoVO qqUser = null;
        WeiXinUser weiXinUser = null;
        if (loginType == 4) {
            qqUser = JsonUtil.getSimpleGson().fromJson(value, QQUserInfoVO.class);
        UserInfo userInfo = userInfoService.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid(), system);
        // 直接用的微信登录
        if (userInfo != null)
            throw new UserAccountException(10, "该微信号已被占用");
            if (qqUser == null)
                throw new UserAccountException(1, "QQ授权失效,请使用QQ重新授权登录");
            thirdPortrait = qqUser.getFigureurl_2();
            thirdCode = qqUser.getOpenid();
            thirdNickName = qqUser.getNickname();
            UserInfo userInfo = userInfoService.getEffectiveUserInfoByQQOpenId(qqUser.getOpenid(), system);
            // 直接用的QQ登录
            if (userInfo != null)
                throw new UserAccountException(10, "该QQ号已被占用");
        } else {
            weiXinUser = JsonUtil.getSimpleGson().fromJson(value, WeiXinUser.class);
            if (weiXinUser == null)
                throw new UserAccountException(1, "三方授权失效,请使用三方重新授权登录");
            thirdPortrait = weiXinUser.getHeadimgurl();
            thirdCode = weiXinUser.getUnionid();
            thirdNickName = weiXinUser.getNickname();
            UserInfo userInfo = userInfoService.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid(), system);
            // 直接用的微信登录
            if (userInfo != null)
                throw new UserAccountException(10, "该微信号已被占用");
        }
        String portrait = null;
        if (!StringUtil.isNullOrEmpty(weiXinUser.getHeadimgurl())) {
            InputStream asInputStream = HttpUtil.getAsInputStream(weiXinUser.getHeadimgurl());
        if (!StringUtil.isNullOrEmpty(thirdPortrait)) {
            InputStream asInputStream = HttpUtil.getAsInputStream(thirdPortrait);
            if (asInputStream != null) {
                FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream,
                        String.format(FilePathEnum.userWXPortrait.getPath() + "%s_%s.jpg", weiXinUser.getUnionid(),
                                System.currentTimeMillis() + ""));
                String path = "";
                if (loginType == 4) {
                    path = String.format(FilePathEnum.userQQPortrait.getPath() + "%s_%s.jpg", thirdCode,
                            System.currentTimeMillis() + "");
                } else {
                    path = String.format(FilePathEnum.userWXPortrait.getPath() + "%s_%s.jpg", thirdCode,
                            System.currentTimeMillis() + "");
                }
                FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream, path);
                if (result != null && !StringUtil.isNullOrEmpty(result.getUrl()))
                    portrait = result.getUrl();
            } else {
                portrait = weiXinUser.getHeadimgurl();
                portrait = thirdPortrait;
            }
        }
        if (StringUtil.isNullOrEmpty(portrait))
            portrait = Constant.systemCommonConfig.getDefaultPortrait();
        if (StringUtil.isNullOrEmpty(portrait)) {
            portrait = userInfoService.getDefaultPortrait(system);
        }
        // 是否需要创建新账户
        UserInfo phoneUser = userInfoService.getEffectiveUserInfoByPhone(phone, system);
        UserInfo userInfo = null;
        if (phoneUser != null) {
            // 绑定微信
            if (StringUtil.isNullOrEmpty(phoneUser.getWxUnionId())) {
                try {
                    bindWeiXin(phoneUser.getId(), weiXinUser);
                } catch (Exception e) {
                    throw new UserAccountException(1, "微信绑定失败");
            if (weiXinUser != null) {
                if (StringUtil.isNullOrEmpty(phoneUser.getWxUnionId())) {
                    try {
                        bindWeiXin(phoneUser.getId(), weiXinUser);
                    } catch (Exception e) {
                        throw new UserAccountException(1, "微信绑定失败");
                    }
                } else {
                    throw new UserAccountException(1, "该微信已被绑定");
                }
            } else {
                throw new UserAccountException(1, "该微信已被绑定");
            }
            if (qqUser != null) {
                if (StringUtil.isNullOrEmpty(phoneUser.getQqOpenId())) {
                    try {
                        bindQQ(phoneUser.getId(), qqUser);
                    } catch (Exception e) {
                        throw new UserAccountException(1, "QQ绑定失败");
                    }
                } else {
                    throw new UserAccountException(1, "该QQ已被绑定");
                }
            }
            userInfo = userInfoService.selectAvailableByPrimaryKey(phoneUser.getId());
        } else {
            // 创建新账户
@@ -1395,13 +1571,21 @@
            userInfo.setPhone(phone);
            userInfo.setPortrait(portrait);
            userInfo.setAppId(null);
            userInfo.setNickName(weiXinUser.getNickname());
            userInfo.setWxName(weiXinUser.getNickname());
            userInfo.setWxOpenId(weiXinUser.getOpenid());
            userInfo.setWxUnionId(weiXinUser.getUnionid());
            userInfo.setWxPic(weiXinUser.getHeadimgurl());
            if (weiXinUser != null) {
                userInfo.setNickName(weiXinUser.getNickname());
                userInfo.setWxName(weiXinUser.getNickname());
                userInfo.setWxOpenId(weiXinUser.getOpenid());
                userInfo.setWxUnionId(weiXinUser.getUnionid());
                userInfo.setWxPic(weiXinUser.getHeadimgurl());
                userInfo.setLoginType(2);
            }
            if (qqUser != null) {
                userInfo.setQqOpenId(qqUser.getOpenid());
                userInfo.setQqNickName(qqUser.getNickname());
                userInfo.setLoginType(4);
            }
            userInfo.setLastLoginTime(System.currentTimeMillis());
            userInfo.setLoginType(2);
            userInfo.setLastLoginIp(ipinfo.getIp());
            userInfo.setState(UserInfo.STATE_NORMAL);
            userInfo.setSystem(system);
@@ -1409,6 +1593,8 @@
        }
        Long uid = userInfo.getId();
        final WeiXinUser tempWeiXinUser = weiXinUser;
        final QQUserInfoVO tempQQUser = qqUser;
        ThreadUtil.run(new Runnable() {
            public void run() {
                try {
@@ -1427,7 +1613,10 @@
                userAccountBindingHistoryService.addUserAccountBindingHistory(history);
                userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindPhone, phone);
                userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindWeiXin, weiXinUser.getUnionid());
                if (tempWeiXinUser != null)
                    userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindWeiXin, tempWeiXinUser.getUnionid());
                if (tempQQUser != null)
                    userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindQQ, tempQQUser.getOpenid());
            }
        });
        // 删除缓存
@@ -1508,9 +1697,9 @@
                        }
                    }
                    if (StringUtil.isNullOrEmpty(portrait))
                        portrait = Constant.systemCommonConfig.getDefaultPortrait();
                    if (StringUtil.isNullOrEmpty(portrait)) {
                        portrait = userInfoService.getDefaultPortrait(system);
                    }
                    // 创建新账户
                    userInfo = new UserInfo();
                    userInfo.setPhone(phone);
@@ -1632,6 +1821,24 @@
    }
    @Override
    public void unRegisterUser(Long uid,String reason) {
        UserInfo currentInfo = userInfoService.selectByPKey(uid);
        if (currentInfo == null) {
            return;
        }
        if (currentInfo.getState() != UserInfo.STATE_NORMAL) {
            return;
        }
        currentInfo.setState(UserInfo.STATE_FORBIDDEN);
        currentInfo.setStateDesc(reason);
        userInfoService.updateByPrimaryKeySelective(currentInfo);
        // 插入记录
        userInfoDeleteRecordService.addDeleteRecord(uid, UserInfo.STATE_DELETE, reason);
    }
    @Override
    public void forbiddenUser(Long uid, String reason) {
        UserInfo currentInfo = userInfoService.selectByPKey(uid);
        if (currentInfo == null) {