From 0a8d28436b2f7229ecdf40c6b003902002c8947f Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期四, 16 十月 2025 17:37:08 +0800 Subject: [PATCH] 修改bug --- UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/UserInfoServiceImpl.java | 308 ++++++++++++++++++++++++++++++++++----------------- 1 files changed, 204 insertions(+), 104 deletions(-) diff --git a/UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/UserInfoServiceImpl.java b/UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/UserInfoServiceImpl.java index 12cf97d..bcd202b 100644 --- a/UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/UserInfoServiceImpl.java +++ b/UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/UserInfoServiceImpl.java @@ -16,12 +16,13 @@ import com.stylefeng.guns.modular.system.model.*; import com.stylefeng.guns.modular.system.service.*; import com.stylefeng.guns.modular.system.util.*; +import com.stylefeng.guns.modular.system.util.qianyuntong.AESUtils; import com.stylefeng.guns.modular.system.util.qianyuntong.SMSUtil; import com.stylefeng.guns.modular.system.util.qianyuntong.UserUtil; -import com.stylefeng.guns.modular.system.util.qianyuntong.model.LoginWeChatXiao; import com.stylefeng.guns.modular.system.util.qianyuntong.model.QYTUserInfo; import com.stylefeng.guns.modular.system.util.qianyuntong.model.RegisterViaMobile; import com.stylefeng.guns.modular.system.util.qianyuntong.model.RegisterViaMobileRequest; +import com.stylefeng.guns.modular.system.util.qianyuntong.model.SendSmsRequest; import com.stylefeng.guns.modular.system.warpper.LoginWarpper; import com.stylefeng.guns.modular.taxi.model.PaymentRecord; import com.stylefeng.guns.modular.taxi.service.IPaymentRecordService; @@ -124,6 +125,9 @@ @Autowired private PayMoneyUtil payMoneyUtil; + + + @Value("${callbackPath}") private String callbackPath; @@ -142,25 +146,25 @@ public ResultUtil queryCaptcha(String phone, Integer type) throws Exception { Random random = new Random(); StringBuffer sb = new StringBuffer(); - for(int i = 0; i < 4; i++){ + for (int i = 0; i < 4; i++) { sb.append((int) (random.nextDouble() * 10)); } String authCode = sb.toString(); - String templateCode = ""; - switch (type){ - case 1: - templateCode = "SMS_154775435";//身份验证 - break; - case 2: - templateCode = "SMS_154775434";//登录确认 - break; - case 3: - templateCode = "SMS_154775432";//用户注册 - break; - case 4: - templateCode = "SMS_154775431";//修改密码 - break; - } +// String templateCode = ""; +// switch (type){ +// case 1: +// templateCode = "SMS_154775435";//身份验证 +// break; +// case 2: +// templateCode = "SMS_154775434";//登录确认 +// break; +// case 3: +// templateCode = "SMS_154775432";//用户注册 +// break; +// case 4: +// templateCode = "SMS_154775431";//修改密码 +// break; +// } // String sData = aLiSendSms.sendSms(phone, "SMS_229715276", "{\"code\":\"" + authCode + "\"}"); // JSONObject jsonObject = JSON.parseObject(sData); // String message = jsonObject.getString("Message"); @@ -168,11 +172,24 @@ // System.err.println(message); // return ResultUtil.error(message); // } - SMSUtil.sendVerifyCode(phone); - String sms = "短信验证码【" + authCode + "】已发到您的手机,验证码将在5分钟后失效,请及时登录!"; - //发送验证码短信 - redisTemplate.opsForValue().set(phone, authCode, 5, TimeUnit.MINUTES);//设置五分钟过期 - System.out.println("【" + phone + "】" + sms); + + //中台没有用户数据,需要走注册接口,验证码校验走中台 + List<QYTUserInfo> infoByPhone = UserUtil.getUserInfoByPhone(phone); + if (null == infoByPhone || infoByPhone.isEmpty()) { + SMSUtil.sendVerifyCode(phone); + } else { + SendSmsRequest request = new SendSmsRequest(); + request.setDestAddress(phone); + request.setTemplateId("TPL202410290001"); + Map<String, String> templateParams = new HashMap<>(); + templateParams.put("code", authCode); + request.setTemplateParams(templateParams); + request.setCode("code"); + request.setSpId("T8d5hdfg"); + SMSUtil.sendSms(request); + //发送验证码短信 + redisTemplate.opsForValue().set(phone, authCode, 5, TimeUnit.MINUTES);//设置五分钟过期 + } return ResultUtil.success(); } @@ -208,24 +225,50 @@ */ @Override public synchronized ResultUtil<LoginWarpper> captchaLogin(String phone, String code, String registIp, String registAreaCode,String loginType) throws Exception { - boolean b = this.checkCaptcha(phone, code); - if (!b) { - return ResultUtil.error("验证码无效"); + UserInfo userInfo = userInfoMapper.queryByPhone(phone); + String nickName = null; + if (null == userInfo) { + nickName = this.getDefaultName(); + } else { + nickName = userInfo.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 = this.checkCaptcha(phone, code); + if (!b) { + return ResultUtil.error("验证码无效"); + } } - UserInfo userInfo = userInfoMapper.queryByPhone(phone); if (null == userInfo) { - ArrayList<UserBankAccount> userBankAccounts = new ArrayList<>(); - userInfo = new UserInfo(); + userInfo.setAvatar("https://traffic.qytzt.cn/v1/AUTH_d8bef0a04db511f0b79d01a3e2b7587e/qyt20250702/imgs/management/d081e7a9-13d4-4eec-afb6-afd10885a664.png"); userInfo.setPhone(phone); userInfo.setPassWord(ShiroKit.md5("", salt)); - userInfo.setNickName(this.getDefaultName()); + userInfo.setNickName(nickName); userInfo.setRegistIp(registIp); userInfo.setIsAuth(1); userInfo.setConsumption(0D); userInfo.setBalance(0D); userInfo.setState(1); + if(null != onconUUID){ + userInfo.setOnconUUID(onconUUID); + } //用户所属企业 if(null != registAreaCode){ @@ -235,6 +278,7 @@ }else { userInfo.setCompanyId(1); } + this.insert(userInfo); this.addCoupon(userInfo);//添加优惠券 @@ -250,20 +294,6 @@ } }).start(); - } - //调中台接口查询用户 - List<QYTUserInfo> infoByPhone = UserUtil.getUserInfoByPhone(phone); - if (null == infoByPhone || infoByPhone.isEmpty()) { - RegisterViaMobileRequest request = new RegisterViaMobileRequest(); - request.setMobile(phone); - request.setPassword("123456"); - request.setNickname(userInfo.getNickName()); - request.setVerify_code(code); - request.setVerify_code_type("1"); - RegisterViaMobile register = UserUtil.registerViaMobile(request); - if (!"0".equals(register.getStatus())) { - return ResultUtil.error(register.getDesc()); - } } if (userInfo.getState() == 2) { return ResultUtil.error("账号被冻结"); @@ -285,7 +315,7 @@ return ResultUtil.success(loginWarpper); } /** - * 手机验证码登录 + * 手机一键登录 * @param accessToken * @return */ @@ -302,18 +332,39 @@ return ResultUtil.error("登录失败"); } String phone = json.getJSONObject("data").getString("mobile"); - + + //调中台接口查询用户 + List<QYTUserInfo> infoByPhone = UserUtil.getUserInfoByPhone(phone); + String onconUUID = null; + String nickName = this.getDefaultName(); + if (null == infoByPhone || infoByPhone.isEmpty()) { + RegisterViaMobileRequest request = new RegisterViaMobileRequest(); + request.setMobile(phone); + request.setEncryptType("aesbase64"); + request.setPassword(AESUtils.encryptBase64("123456")); + request.setNickname(nickName); + RegisterViaMobile register = UserUtil.registerViaMobile(request); + if (!"0".equals(register.getStatus())) { + return ResultUtil.error(register.getDesc()); + } + onconUUID = register.getOnconUUID(); + }else{ + onconUUID = UserUtil.getOnconUUIDByMobile(phone); + } + UserInfo userInfo = userInfoMapper.queryByPhone(phone); if (null == userInfo) { userInfo = new UserInfo(); + userInfo.setAvatar("https://traffic.qytzt.cn/v1/AUTH_d8bef0a04db511f0b79d01a3e2b7587e/qyt20250702/imgs/management/d081e7a9-13d4-4eec-afb6-afd10885a664.png"); userInfo.setPhone(phone); userInfo.setPassWord(ShiroKit.md5("", salt)); - userInfo.setNickName(this.getDefaultName()); + userInfo.setNickName(nickName); userInfo.setRegistIp(registIp); userInfo.setIsAuth(1); userInfo.setConsumption(0D); userInfo.setBalance(0D); userInfo.setState(1); + userInfo.setOnconUUID(onconUUID); //用户所属企业 if(null != registAreaCode){ @@ -353,8 +404,6 @@ loginWarpper.setEmergencyContact(userInfo.getEmergencyContact()); loginWarpper.setEmergencyContactNumber(userInfo.getEmergencyContactNumber()); loginWarpper.setPhone(2); - - //smsrecordService.saveData(1, phone, code, "短信验证码【" + code + "】已发到您的手机,验证码将在5分钟后失效,请及时登录!"); return ResultUtil.success(loginWarpper); } @Override @@ -471,11 +520,15 @@ LoginWarpper loginWarpper = new LoginWarpper(); loginWarpper.setId(userInfo.getId()); loginWarpper.setToken(token); + loginWarpper.setExpirationTime(15552000L); loginWarpper.setAppid(UUIDUtil.getRandomCode()); loginWarpper.setEmergencyContact(userInfo.getEmergencyContact()); loginWarpper.setEmergencyContactNumber(userInfo.getEmergencyContactNumber()); return ResultUtil.success(loginWarpper); } + + + @Override public ResultUtil<LoginWarpper> wxLogin(Integer type, String openid, String unionid, String jscode, String registIp, String registAreaCode, Integer sex, String nickName, String avatar,String loginType) throws Exception { @@ -495,6 +548,7 @@ } if (null == userInfo) { userInfo = new UserInfo(); + userInfo.setAvatar("https://traffic.qytzt.cn/v1/AUTH_d8bef0a04db511f0b79d01a3e2b7587e/qyt20250702/imgs/management/d081e7a9-13d4-4eec-afb6-afd10885a664.png"); userInfo.setPassWord(ShiroKit.md5("", salt)); userInfo.setRegistIp(registIp); userInfo.setSex(sex); @@ -547,15 +601,9 @@ } jsonObject.put(userInfo.getId().toString(), userInfo.getAppletsOpenId()); redisTemplate.opsForValue().set("appletOpenId", jsonObject.toJSONString()); - - //调中台微信登录接口 - LoginWeChatXiao loginWeChatXiao = UserUtil.loginWeChatXiao(jscode); - if (null == loginWeChatXiao) { - return ResultUtil.error("微信登录请求失败,请重试"); - } //调用单点登录的逻辑 this.singlePointLogin(userInfo.getId(), loginType); - String token = loginWeChatXiao.getToken(); + String token = this.getToken(userInfo, "", loginType); redisTemplate.opsForValue().set(token.substring(token.length() - 32), String.valueOf(userInfo.getId()), 180, TimeUnit.DAYS); redisTemplate.opsForValue().set("USER_" + type + "_" + userInfo.getPhone(), token.substring(token.length() - 32)); redisTemplate.opsForValue().set("USER_" + type + "_" + userInfo.getId(), token); @@ -607,6 +655,10 @@ openid = map.get("openid"); unionid = map.get("unionid"); sessionKey = map.get("sessionKey"); + if(ToolUtil.isEmpty(phone)){ + phone = getPhone(sessionKey, encryptedData, iv); + } + if(ToolUtil.isNotEmpty(phone)){ List<UserInfo> phone1 = userInfoMapper.selectList(new EntityWrapper<UserInfo>().eq("phone", phone).eq("state",1).ne("flag",3)); if(phone1.size()>0){ @@ -618,21 +670,34 @@ }else { userInfo = userInfoMapper.queryByOpenid2(openid); } - System.out.println(userInfo); - if(ToolUtil.isEmpty(phone) && ToolUtil.isNotEmpty(userInfo) && ToolUtil.isEmpty(userInfo.getPhone())){ - String phone1 = getPhone(sessionKey, encryptedData, iv); - userInfo.setPhone(phone1); - userInfoMapper.updateById(userInfo); - } }else{//APP userInfo = userInfoMapper.queryByOpenid(openid); } + //调中台接口查询用户 + List<QYTUserInfo> infoByPhone = UserUtil.getUserInfoByPhone(phone); + String onconUUID = null; + nickName = this.getDefaultName(); + if (null == infoByPhone || infoByPhone.isEmpty()) { + RegisterViaMobileRequest request = new RegisterViaMobileRequest(); + request.setMobile(phone); + request.setEncryptType("aesbase64"); + request.setPassword(AESUtils.encryptBase64("123456")); + request.setNickname(nickName); + RegisterViaMobile register = UserUtil.registerViaMobile(request); + if (!"0".equals(register.getStatus())) { + return ResultUtil.error(register.getDesc()); + } + onconUUID = register.getOnconUUID(); + }else{ + onconUUID = UserUtil.getOnconUUIDByMobile(phone); + } + int i =0; if(null == userInfo){ userInfo = new UserInfo(); + userInfo.setAvatar("https://traffic.qytzt.cn/v1/AUTH_d8bef0a04db511f0b79d01a3e2b7587e/qyt20250702/imgs/management/d081e7a9-13d4-4eec-afb6-afd10885a664.png"); if(ToolUtil.isEmpty(phone)){ - String phone2 = getPhone(sessionKey, encryptedData, iv); - List<UserInfo> phone1 = userInfoMapper.selectList(new EntityWrapper<UserInfo>().eq("phone", phone2).eq("state",1).ne("flag",3)); + List<UserInfo> phone1 = userInfoMapper.selectList(new EntityWrapper<UserInfo>().eq("phone", phone).eq("state",1).ne("flag",3)); if(phone1.size()>0){ userInfo = phone1.get(0); userInfo.setUnionid(unionid); @@ -640,7 +705,7 @@ userInfoMapper.updateById(userInfo); i=1; }else { - userInfo.setPhone(phone2); + userInfo.setPhone(phone); } }else { userInfo.setPhone(phone); @@ -650,8 +715,9 @@ userInfo.setRegistIp(registIp); userInfo.setSex(sex); - userInfo.setNickName(ToolUtil.isNotEmpty(nickName) ? nickName : this.getDefaultName()); + userInfo.setNickName(nickName); userInfo.setAvatar(avatar); + userInfo.setOnconUUID(onconUUID); if(type == 2){ userInfo.setAppletsOpenId(openid); @@ -837,36 +903,45 @@ */ @Override public ResultUtil bindingPhone(Integer uid, String phone, String code,String loginType) throws Exception { - boolean b = this.checkCaptcha(phone, code); - if (!b) { - return ResultUtil.error("验证码无效"); - } - - UserInfo userInfo = this.selectById(uid); + String nickName = null; + if (null == userInfo) { + nickName = this.getDefaultName(); + } else { + nickName = userInfo.getNickName(); + } + //调中台接口查询用户 + String onconUUID = null; + List<QYTUserInfo> infoByPhone = UserUtil.getUserInfoByPhone(phone); + 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 = this.checkCaptcha(phone, code); + if (!b) { + return ResultUtil.error("验证码无效"); + } + onconUUID = UserUtil.getOnconUUIDByMobile(phone); + } UserInfo userInfo1 = userInfoMapper.queryByPhone(phone); if (null != userInfo1) { - //调中台接口查询用户 - List<QYTUserInfo> infoByPhone = UserUtil.getUserInfoByPhone(phone); - if (null == infoByPhone || infoByPhone.isEmpty()) { - RegisterViaMobileRequest request = new RegisterViaMobileRequest(); - request.setMobile(phone); - request.setPassword("123456"); - request.setNickname(userInfo.getNickName()); - request.setVerify_code(code); - request.setVerify_code_type("1"); - RegisterViaMobile register = UserUtil.registerViaMobile(request); - if (!"0".equals(register.getStatus())) { - return ResultUtil.error(register.getDesc()); - } - } - userInfo1.setOpenId(userInfo.getOpenId()); userInfo1.setUnionid(userInfo.getUnionid()); userInfo1.setAppletsOpenId(userInfo.getAppletsOpenId()); userInfo1.setAvatar(userInfo.getAvatar()); userInfo1.setSex(userInfo.getSex()); userInfo1.setNickName(userInfo.getNickName()); + userInfo1.setOnconUUID(onconUUID); this.updateById(userInfo1); if (ToolUtil.isNotEmpty(loginType) && loginType.equals("Applets")) {//小程序登录后绑定手机号码 @@ -916,22 +991,7 @@ loginWarpper.setPhone(2); return ResultUtil.success(loginWarpper); } - //调中台接口查询用户 - List<QYTUserInfo> infoByPhone = UserUtil.getUserInfoByPhone(phone); - if (null == infoByPhone || infoByPhone.isEmpty()) { - RegisterViaMobileRequest request = new RegisterViaMobileRequest(); - request.setMobile(phone); - request.setPassword("123456"); - request.setNickname(userInfo.getNickName()); - request.setVerify_code(code); - request.setVerify_code_type("1"); - RegisterViaMobile register = UserUtil.registerViaMobile(request); - if (!"0".equals(register.getStatus())) { - return ResultUtil.error(register.getDesc()); - } - } - - + userInfo.setOnconUUID(onconUUID); userInfo.setPhone(phone); userInfo.setUpdateTime(new Date()); userInfo.setUpdateUser(userInfo.getId()); @@ -1435,7 +1495,7 @@ */ public String getDefaultName(){ int num = this.selectCount(new EntityWrapper<UserInfo>().ne("flag", 3)) + 1000001; - return "JYX" + String.valueOf(num).substring(1); + return "GRJY" + String.valueOf(num).substring(1); } /** @@ -1539,7 +1599,7 @@ boolean passwordTrueFlag = md5CredentialsMatcher.doCredentialsMatch( usernamePasswordToken, simpleAuthenticationInfo); String s = JwtTokenUtil.generateToken(String.valueOf(userInfo.getId())); - redisTemplate.opsForValue().set(s.substring(s.length() - 32), String.valueOf(userInfo.getId()), 180, TimeUnit.DAYS); + redisTemplate.opsForValue().set(s.substring(s.length() - 32), String.valueOf(userInfo.getId()), 30, TimeUnit.DAYS); redisTemplate.opsForValue().set("USER_" + type + "_" + userInfo.getPhone(), s.substring(s.length() - 32)); redisTemplate.opsForValue().set("USER_" + type + "_" + userInfo.getId(), s); return s; @@ -1614,4 +1674,44 @@ } return ResultUtil.success(loginWarpper); } + + + @Override + public String addAppUser(String phone, String code, String areaCode, String onconUUID) throws Exception { + UserInfo userInfo = userInfoMapper.queryByPhone(phone); + String nickName = null; + if (null == userInfo) { + nickName = this.getDefaultName(); + } else { + nickName = userInfo.getNickName(); + } + //调中台接口查询用户 + List<QYTUserInfo> infoByPhone = UserUtil.getUserInfoByPhone(phone); + if (null == userInfo) { + userInfo = new UserInfo(); + userInfo.setAvatar("https://traffic.qytzt.cn/v1/AUTH_d8bef0a04db511f0b79d01a3e2b7587e/qyt20250702/imgs/management/d081e7a9-13d4-4eec-afb6-afd10885a664.png"); + userInfo.setPhone(phone); + userInfo.setPassWord(ShiroKit.md5("", salt)); + userInfo.setNickName(nickName); + userInfo.setIsAuth(1); + userInfo.setConsumption(0D); + userInfo.setBalance(0D); + userInfo.setState(1); + if(null != onconUUID){ + userInfo.setOnconUUID(onconUUID); + } + + //用户所属企业 + if(null != areaCode){ + Company query = companyCityService.query(areaCode); + userInfo.setCompanyId(null != query ? query.getId() : 1); + userInfo.setRegistAreaCode(areaCode); + }else { + userInfo.setCompanyId(1); + } + + this.insert(userInfo); + } + return userInfo.getId().toString(); + } } -- Gitblit v1.7.1