Pu Zhibing
5 天以前 70211b41954df4ac1232f48420b89c13fb5fb451
UserQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/UserInfoServiceImpl.java
@@ -17,6 +17,11 @@
import com.stylefeng.guns.modular.system.service.*;
import com.stylefeng.guns.modular.system.util.*;
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.warpper.LoginWarpper;
import com.stylefeng.guns.modular.taxi.model.PaymentRecord;
import com.stylefeng.guns.modular.taxi.service.IPaymentRecordService;
@@ -59,8 +64,8 @@
    @Resource
    private UserActivityInviteMapper userActivityInviteMapper;
    
    @Autowired
    private RedisTemplate redisTemplate;
    @Resource
    private RedisTemplate<String, Object> redisTemplate;
    @Autowired
    private ALiSendSms aLiSendSms;
@@ -181,10 +186,10 @@
     */
    @Override
    public boolean checkCaptcha(String phone, String code) throws Exception {
        Object value = redisTemplate.opsForValue().get(phone);
        if("1234".equals(code)){
            return true;
        }
        Object value = redisTemplate.opsForValue().get(phone);
        System.out.println("phone:"+phone);
        System.out.println("code:"+code);
        System.out.println("code---"+String.valueOf(value));
@@ -246,6 +251,20 @@
            }).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("账号被冻结");
        }
@@ -283,6 +302,7 @@
            return ResultUtil.error("登录失败");
        }
        String phone = json.getJSONObject("data").getString("mobile");
        UserInfo userInfo = userInfoMapper.queryByPhone(phone);
        if(null == userInfo){
            userInfo = new UserInfo();
@@ -322,7 +342,6 @@
        if(userInfo.getState() == 2){
            return ResultUtil.error("账号被冻结");
        }
        //调用单点登录的逻辑
        this.singlePointLogin(userInfo.getId(),loginType);
@@ -428,6 +447,12 @@
     */
    @Override
    public ResultUtil<LoginWarpper> userLogin(String phone, String password,String loginType) throws Exception {
        //调中台接口查询用户
        List<QYTUserInfo> infoByPhone = UserUtil.getUserInfoByPhone(phone);
        if (null == infoByPhone || infoByPhone.isEmpty()) {
            return ResultUtil.error("账号无效");
        }
        UserInfo userInfo = this.queryByPhone(phone);
        if(null == userInfo){
            return ResultUtil.error("账号无效");
@@ -465,9 +490,6 @@
            unionid = map.get("unionid");
            sessionKey = map.get("sessionKey");
            userInfo = userInfoMapper.queryByOpenid2(openid);
        }else{//APP
            userInfo = userInfoMapper.queryByOpenid(openid);
        }
@@ -525,7 +547,29 @@
            }
            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();
            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);
            LoginWarpper loginWarpper = new LoginWarpper();
            loginWarpper.setId(userInfo.getId());
            loginWarpper.setToken(token);
            loginWarpper.setAppid(UUIDUtil.getRandomCode());
            loginWarpper.setPhone(ToolUtil.isNotEmpty(userInfo.getPhone()) ? 2 : 1);
            loginWarpper.setEmergencyContact(userInfo.getEmergencyContact());
            loginWarpper.setEmergencyContactNumber(userInfo.getEmergencyContactNumber());
            return ResultUtil.success(loginWarpper);
        }
        //调用单点登录的逻辑
        this.singlePointLogin(userInfo.getId(),loginType);
@@ -580,9 +624,6 @@
                userInfo.setPhone(phone1);
                userInfoMapper.updateById(userInfo);
            }
        }else{//APP
            userInfo = userInfoMapper.queryByOpenid(openid);
        }
@@ -646,8 +687,6 @@
            }
        }
        if(userInfo.getState() == 2){
            return ResultUtil.error("账号被冻结");
        }
@@ -662,6 +701,21 @@
            }
            jsonObject.put(userInfo.getId().toString(), userInfo.getAppletsOpenId());
            redisTemplate.opsForValue().set("appletOpenId", jsonObject.toJSONString());
            //调用单点登录的逻辑
            this.singlePointLogin(userInfo.getId(), loginType);
            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);
            LoginWarpper loginWarpper = new LoginWarpper();
            loginWarpper.setId(userInfo.getId());
            loginWarpper.setToken(token);
            loginWarpper.setAppid(UUIDUtil.getRandomCode());
            loginWarpper.setPhone(ToolUtil.isNotEmpty(userInfo.getPhone()) ? 2 : 1);
            loginWarpper.setEmergencyContact(userInfo.getEmergencyContact());
            loginWarpper.setEmergencyContactNumber(userInfo.getEmergencyContactNumber());
            return ResultUtil.success(loginWarpper);
        }
        //调用单点登录的逻辑
@@ -787,9 +841,26 @@
        if(!b){
            return ResultUtil.error("验证码无效");
        }
        UserInfo userInfo = this.selectById(uid);
        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());
@@ -845,6 +916,21 @@
            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());
@@ -996,6 +1082,8 @@
        if(!b){
            return ResultUtil.error("验证码无效");
        }
        UserInfo userInfo = this.selectById(uid);
        UserInfo userInfo1 = userInfoMapper.queryByPhone(phone);
        if(null != userInfo1){
@@ -1004,7 +1092,6 @@
        userInfo.setPhone(phone);
        this.updateById(userInfo);
//        smsrecordService.saveData(2, phone, code, "短信验证码【" + code + "】已发到您的手机,验证码将在5分钟后失效,请及时登录!");
        return ResultUtil.success();
    }