liujie
6 天以前 9828db9febf4ad5cb0b79a72eedca6922b466104
UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/UserInfoServiceImpl.java
@@ -16,16 +16,18 @@
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;
import com.stylefeng.guns.modular.taxi.service.ITransactionDetailsService;
import org.apache.commons.lang.time.DateUtils;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
@@ -49,6 +51,7 @@
import java.net.URLConnection;
import java.security.spec.AlgorithmParameterSpec;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
@@ -124,6 +127,10 @@
    @Autowired
    private PayMoneyUtil payMoneyUtil;
    @Autowired
    private TDriverPromotionActivityService driverPromotionActivityService;
    @Value("${callbackPath}")
    private String callbackPath;
@@ -142,25 +149,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 +175,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();
    }
@@ -207,20 +227,40 @@
     * @return
     */
    @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("验证码无效");
    public synchronized ResultUtil<LoginWarpper> captchaLogin(String phone, String code, String registIp, String registAreaCode,String loginType,Integer driverId) 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 == 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());
            }
        } 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.setPhone(phone);
            userInfo.setPassWord(ShiroKit.md5("", salt));
            userInfo.setNickName(this.getDefaultName());
            userInfo.setNickName(nickName);
            userInfo.setRegistIp(registIp);
            userInfo.setIsAuth(1);
            userInfo.setConsumption(0D);
@@ -235,6 +275,24 @@
            }else {
                userInfo.setCompanyId(1);
            }
            // 是否需要绑定司机
            TDriverPromotionActivity tDriverPromotionActivity = driverPromotionActivityService.selectOne(new EntityWrapper<TDriverPromotionActivity>().eq("districtCode", registAreaCode).ge("startTime", new Date()).lt("endTime", new Date()).last(" limit 1"));
            if(tDriverPromotionActivity!=null){
                Integer bindingDays = tDriverPromotionActivity.getBindingDays();
                // 当前时间+绑定天数
                Date endTime = DateUtils.addDays(new Date(), bindingDays);
                userInfo.setBindDriverId(driverId);
                userInfo.setBindExpireDate(endTime);
            }
            this.insert(userInfo);
            this.addCoupon(userInfo);//添加优惠券
@@ -250,20 +308,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("账号被冻结");
@@ -359,7 +403,7 @@
    }
    @Override
    public synchronized ResultUtil<LoginWarpper> captchaLogin(String phone, String code, Integer uid, Integer type, Integer userType,String loginType) throws Exception {
        ResultUtil<LoginWarpper> resultUtil = this.captchaLogin(phone, code, null, null,loginType);
        ResultUtil<LoginWarpper> resultUtil = this.captchaLogin(phone, code, null, null,loginType,null);
        if(resultUtil.getCode() == 200 && null != uid){
            if(type == 2){//司机分享
                Driver driver = driverMapper.selectById(uid);
@@ -471,6 +515,7 @@
        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());
@@ -547,15 +592,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);
@@ -837,30 +876,35 @@
     */
    @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();
        }
        //调中台接口查询用户
        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());
            }
        } else {
            boolean b = this.checkCaptcha(phone, code);
            if (!b) {
                return ResultUtil.error("验证码无效");
            }
        }
        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());
@@ -916,21 +960,6 @@
            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.setPhone(phone);
        userInfo.setUpdateTime(new Date());
@@ -1221,7 +1250,7 @@
            if(null == userInfo){
                return ResultUtil.error("获取用户信息失败");
            }
            return this.captchaLogin(userInfo.get("phone"), "1234", null, registAreaCode, loginType);
            return this.captchaLogin(userInfo.get("phone"), "1234", null, registAreaCode, loginType,null);
        }else{
            return ResultUtil.error(jsonObject.getString("msg"));
        }
@@ -1435,7 +1464,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);
    }
    /**