Pu Zhibing
4 天以前 30f124fbe2c638eecda3d74c6dde053af5d574f0
user/guns-admin/src/main/java/com/supersavedriving/user/modular/system/service/impl/AppUserServiceImpl.java
@@ -23,6 +23,11 @@
import com.supersavedriving.user.modular.system.util.MallBook.model.QueryOrder;
import com.supersavedriving.user.modular.system.util.MallBook.util.Transfer;
import com.supersavedriving.user.modular.system.util.MallBook.util.TrhRequest;
import com.supersavedriving.user.modular.system.util.qianyuntong.AESUtils;
import com.supersavedriving.user.modular.system.util.qianyuntong.UserUtil;
import com.supersavedriving.user.modular.system.util.qianyuntong.model.QYTUserInfo;
import com.supersavedriving.user.modular.system.util.qianyuntong.model.RegisterViaMobile;
import com.supersavedriving.user.modular.system.util.qianyuntong.model.RegisterViaMobileRequest;
import com.supersavedriving.user.modular.system.util.weChat.WXCore;
import com.supersavedriving.user.modular.system.util.weChat.WeChatUtil;
import com.supersavedriving.user.modular.system.util.weChat.model.Code2Session;
@@ -143,8 +148,8 @@
        if (passwordTrueFlag) {
            String token = JwtTokenUtil.generateToken(phone);
            String key = token;
            if(token.length() > 16){
                key = token.substring(token.length() - 16);
            if(token.length() > 32){
                key = token.substring(token.length() - 32);
            }
            redisUtil.setStrValue(key, appUser.getId().toString(), 94608000);
            redisUtil.setStrValue("USER_" + appUser.getPhone(), key, 94608000);
@@ -189,7 +194,7 @@
            if(null == appUser){
                appUser = new AppUser();
                appUser.setNickname("亲爱的用户");
                appUser.setAvatar("https://csxdj.obs.cn-south-1.myhuaweicloud.com:443/9af2cadb5d0d42d5b9da37f0c6789a66.png");
                appUser.setAvatar("https://traffic.qytzt.cn/v1/AUTH_d8bef0a04db511f0b79d01a3e2b7587e/qyt20250702/imgs/management/d081e7a9-13d4-4eec-afb6-afd10885a664.png");
                appUser.setPhone(purePhoneNumber);
                appUser.setOpenid(openid);
                appUser.setUnionid(code2Session.getUnionid());
@@ -268,10 +273,41 @@
            }
            String openid = code2Session.getOpenid();
            AppUser appUser = this.selectOne(new EntityWrapper<AppUser>().eq("phone", phone).ne("status", 3));
            String nickName = null;
            if (null == appUser) {
                nickName = this.getDefaultName();
            } else {
                nickName = appUser.getNickname();
            }
            //调中台接口查询用户
            List<QYTUserInfo> infoByPhone = UserUtil.getUserInfoByPhone(phone);
            String onconUUID = null;
            if (null == infoByPhone || infoByPhone.isEmpty()) {
                RegisterViaMobileRequest request = new RegisterViaMobileRequest();
                request.setMobile(phone);
                request.setEncryptType("aesbase64");
                request.setPassword(AESUtils.encryptBase64("123456"));
                request.setNickname(nickName);
                request.setVerify_code(code);
                request.setVerify_code_type("0");
                RegisterViaMobile register = UserUtil.registerViaMobile(request);
                if (!"0".equals(register.getStatus())) {
                    return ResultUtil.error(register.getDesc());
                }
                onconUUID = register.getOnconUUID();
            } else {
                boolean b = AppUserUtil.checkCaptcha(phone, code);
                if (!b) {
                    return ResultUtil.error("验证码无效");
                }
            }
            if(null == appUser){
                appUser = new AppUser();
                appUser.setNickname("亲爱的用户");
                appUser.setAvatar("https://csxdj.obs.cn-south-1.myhuaweicloud.com:443/9af2cadb5d0d42d5b9da37f0c6789a66.png");
                appUser.setAvatar("https://traffic.qytzt.cn/v1/AUTH_d8bef0a04db511f0b79d01a3e2b7587e/qyt20250702/imgs/management/d081e7a9-13d4-4eec-afb6-afd10885a664.png");
                appUser.setPhone(phone);
                appUser.setOpenid(openid);
                appUser.setUnionid(code2Session.getUnionid());
@@ -283,8 +319,11 @@
                    appUser.setInviterId(verificationCodeLogin.getInviterId());
                    appUser.setInviterType(verificationCodeLogin.getInviterType());
                }
                if(null != onconUUID){
                    appUser.setOnconUUID(onconUUID);
                }
                //同步用户数据到打车系统
                String s = AppUserUtil.addUser(phone, code, verificationCodeLogin.getAreaCode());
                String s = AppUserUtil.addUser(phone, code, verificationCodeLogin.getAreaCode(), onconUUID);
                if(ToolUtil.isEmpty(s)){
                    return ResultUtil.error("登录失败");
                }
@@ -517,16 +556,38 @@
        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = servletRequestAttributes.getRequest();
        String requestHeader = request.getHeader(JwtConstants.AUTH_HEADER);
        String custom = request.getHeader("custom-header");
        if (ToolUtil.isNotEmpty(requestHeader) && requestHeader.startsWith("Bearer ")) {
            requestHeader = requestHeader.substring(requestHeader.indexOf(" ") + 1);
            String key = null;
            int length = requestHeader.length();
            if(length > 16){
                key = requestHeader.substring(length - 16);
            if(length > 32){
                key = requestHeader.substring(length - 32);
            }else{
                key = requestHeader;
            }
            String value = redisUtil.getValue(key);
            //从打车系统直接带过来的token
            if(ToolUtil.isNotEmpty(custom) && "1".equals(custom)){
                AppUser appUser = this.selectOne(new EntityWrapper<AppUser>().eq("taxiUserId", value));
                if(null != appUser){
                    value = appUser.getId().toString();
                }else{
                    String userPhone = AppUserUtil.getUserPhone(Integer.valueOf(value));
                    //创建新的用户
                    appUser = new AppUser();
                    appUser.setNickname("亲爱的用户");
                    appUser.setAvatar("https://traffic.qytzt.cn/v1/AUTH_d8bef0a04db511f0b79d01a3e2b7587e/qyt20250702/imgs/management/d081e7a9-13d4-4eec-afb6-afd10885a664.png");
                    appUser.setPhone(userPhone);
                    appUser.setAccountBalance(0D);
                    appUser.setStatus(1);
                    appUser.setCreateTime(new Date());
                    appUser.setIsException(1);
                    appUser.setTaxiUserId(Integer.valueOf(value));
                    this.insert(appUser);
                }
            }
            return null != value ? Integer.valueOf(value) : null;
        }else{
            return null;
@@ -755,4 +816,14 @@
    public List<CouponsWarpper> queryMyCoupons(Integer uid, Integer state, Integer pageNum, Integer pageSize) throws Exception {
        return null;
    }
    /**
     * 获取默认名称
     * @return
     */
    public String getDefaultName(){
        int num = this.selectCount(new EntityWrapper<AppUser>().ne("status", 3)) + 1000001;
        return "GRJY-DJ" + String.valueOf(num).substring(1);
    }
}