| | |
| | | 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; |
| | |
| | | |
| | | @Service |
| | | public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements IUserInfoService { |
| | | |
| | | |
| | | @Resource |
| | | private UserInfoMapper userInfoMapper; |
| | | |
| | | |
| | | @Resource |
| | | private UserActivityInviteMapper userActivityInviteMapper; |
| | | |
| | | @Autowired |
| | | private RedisTemplate redisTemplate; |
| | | |
| | | @Resource |
| | | private RedisTemplate<String, Object> redisTemplate; |
| | | |
| | | @Autowired |
| | | private ALiSendSms aLiSendSms; |
| | | |
| | | |
| | | @Autowired |
| | | private WeChatUtil weChatUtil; |
| | | |
| | | |
| | | @Autowired |
| | | private IPaymentRecordService paymentRecordService; |
| | | |
| | | |
| | | @Autowired |
| | | private ICompanyCityService companyCityService; |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public boolean checkCaptcha(String phone, String code) throws Exception { |
| | | Object value = redisTemplate.opsForValue().get(phone); |
| | | if("1234".equals(code)){ |
| | | if ("1234".equals(code)) { |
| | | return true; |
| | | } |
| | | System.out.println("phone:"+phone); |
| | | System.out.println("code:"+code); |
| | | System.out.println("code---"+String.valueOf(value)); |
| | | if(null != value && code.equals(String.valueOf(value))){ |
| | | Object value = redisTemplate.opsForValue().get(phone); |
| | | System.out.println("phone:" + phone); |
| | | System.out.println("code:" + code); |
| | | System.out.println("code---" + String.valueOf(value)); |
| | | if (null != value && code.equals(String.valueOf(value))) { |
| | | return true; |
| | | }else{ |
| | | } else { |
| | | return false; |
| | | } |
| | | } |
| | |
| | | @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){ |
| | | if (!b) { |
| | | return ResultUtil.error("验证码无效"); |
| | | } |
| | | |
| | | |
| | | UserInfo userInfo = userInfoMapper.queryByPhone(phone); |
| | | if(null == userInfo){ |
| | | if (null == userInfo) { |
| | | ArrayList<UserBankAccount> userBankAccounts = new ArrayList<>(); |
| | | |
| | | |
| | | userInfo = new UserInfo(); |
| | | userInfo.setPhone(phone); |
| | | userInfo.setPassWord(ShiroKit.md5("", salt)); |
| | |
| | | this.insert(userInfo); |
| | | |
| | | this.addCoupon(userInfo);//添加优惠券 |
| | | |
| | | |
| | | UserInfo finalUserInfo = userInfo; |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | if(pushMinistryOfTransport){ |
| | | if (pushMinistryOfTransport) { |
| | | //上传数据 |
| | | pushMinistryOfTransportUtil.baseInfoPassenger(finalUserInfo.getId()); |
| | | } |
| | | } |
| | | }).start(); |
| | | |
| | | |
| | | } |
| | | if(userInfo.getState() == 2){ |
| | | //调中台接口查询用户 |
| | | 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("账号被冻结"); |
| | | } |
| | | |
| | | |
| | | //调用单点登录的逻辑 |
| | | this.singlePointLogin(userInfo.getId(),loginType); |
| | | |
| | | String token = this.getToken(userInfo, "",loginType); |
| | | this.singlePointLogin(userInfo.getId(), loginType); |
| | | |
| | | String token = this.getToken(userInfo, "", loginType); |
| | | LoginWarpper loginWarpper = new LoginWarpper(); |
| | | loginWarpper.setId(userInfo.getId()); |
| | | loginWarpper.setToken(token); |
| | |
| | | loginWarpper.setEmergencyContact(userInfo.getEmergencyContact()); |
| | | loginWarpper.setEmergencyContactNumber(userInfo.getEmergencyContactNumber()); |
| | | loginWarpper.setPhone(2); |
| | | |
| | | |
| | | smsrecordService.saveData(1, phone, code, "短信验证码【" + code + "】已发到您的手机,验证码将在5分钟后失效,请及时登录!"); |
| | | return ResultUtil.success(loginWarpper); |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | public ResultUtil<LoginWarpper> oneClickLogin(String accessToken, String registIp, String registAreaCode,String loginType,String androidOrIos) throws Exception { |
| | | String response = GetMobile.getPhone(accessToken,androidOrIos); |
| | | |
| | | if(response==null){ |
| | | String response = GetMobile.getPhone(accessToken, androidOrIos); |
| | | |
| | | if (response == null) { |
| | | return ResultUtil.error("登录失败"); |
| | | } |
| | | System.out.println( response); |
| | | System.out.println(response); |
| | | JSONObject json = JSONObject.parseObject(response); |
| | | if(!json.getBoolean("success")){ |
| | | if (!json.getBoolean("success")) { |
| | | return ResultUtil.error("登录失败"); |
| | | } |
| | | String phone = json.getJSONObject("data").getString("mobile"); |
| | | |
| | | UserInfo userInfo = userInfoMapper.queryByPhone(phone); |
| | | if(null == userInfo){ |
| | | if (null == userInfo) { |
| | | userInfo = new UserInfo(); |
| | | userInfo.setPhone(phone); |
| | | userInfo.setPassWord(ShiroKit.md5("", salt)); |
| | |
| | | userInfo.setConsumption(0D); |
| | | userInfo.setBalance(0D); |
| | | userInfo.setState(1); |
| | | |
| | | |
| | | //用户所属企业 |
| | | if(null != registAreaCode){ |
| | | Company query = companyCityService.query(registAreaCode); |
| | |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | if(pushMinistryOfTransport){ |
| | | if (pushMinistryOfTransport) { |
| | | //上传数据 |
| | | pushMinistryOfTransportUtil.baseInfoPassenger(finalUserInfo.getId()); |
| | | } |
| | | } |
| | | }).start(); |
| | | |
| | | |
| | | } |
| | | if(userInfo.getState() == 2){ |
| | | if (userInfo.getState() == 2) { |
| | | return ResultUtil.error("账号被冻结"); |
| | | } |
| | | |
| | | //调用单点登录的逻辑 |
| | | this.singlePointLogin(userInfo.getId(),loginType); |
| | | |
| | | String token = this.getToken(userInfo, "",loginType); |
| | | this.singlePointLogin(userInfo.getId(), loginType); |
| | | |
| | | String token = this.getToken(userInfo, "", loginType); |
| | | LoginWarpper loginWarpper = new LoginWarpper(); |
| | | loginWarpper.setId(userInfo.getId()); |
| | | loginWarpper.setToken(token); |
| | |
| | | loginWarpper.setEmergencyContact(userInfo.getEmergencyContact()); |
| | | loginWarpper.setEmergencyContactNumber(userInfo.getEmergencyContactNumber()); |
| | | loginWarpper.setPhone(2); |
| | | |
| | | |
| | | //smsrecordService.saveData(1, phone, code, "短信验证码【" + code + "】已发到您的手机,验证码将在5分钟后失效,请及时登录!"); |
| | | return ResultUtil.success(loginWarpper); |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | public ResultUtil<LoginWarpper> userLogin(String phone, String password,String loginType) throws Exception { |
| | | UserInfo userInfo = this.queryByPhone(phone); |
| | | if(null == userInfo){ |
| | | //调中台接口查询用户 |
| | | List<QYTUserInfo> infoByPhone = UserUtil.getUserInfoByPhone(phone); |
| | | if (null == infoByPhone || infoByPhone.isEmpty()) { |
| | | return ResultUtil.error("账号无效"); |
| | | } |
| | | if(userInfo.getState() == 2){ |
| | | |
| | | UserInfo userInfo = this.queryByPhone(phone); |
| | | if (null == userInfo) { |
| | | return ResultUtil.error("账号无效"); |
| | | } |
| | | if (userInfo.getState() == 2) { |
| | | return ResultUtil.error("账号被冻结"); |
| | | } |
| | | if(!ShiroKit.md5(password, salt).equals(userInfo.getPassWord())){ |
| | | if (!ShiroKit.md5(password, salt).equals(userInfo.getPassWord())) { |
| | | return ResultUtil.error("密码错误"); |
| | | } |
| | | |
| | |
| | | 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 { |
| | | UserInfo userInfo = null; |
| | | String sessionKey=null; |
| | | if(type == 2){//小程序 |
| | | if(ToolUtil.isEmpty(jscode)){ |
| | | String sessionKey = null; |
| | | if (type == 2) {//小程序 |
| | | if (ToolUtil.isEmpty(jscode)) { |
| | | return ResultUtil.error("微信登录请求失败,请重试"); |
| | | } |
| | | Map<String, String> map = weChatUtil.code2Session(jscode); |
| | |
| | | unionid = map.get("unionid"); |
| | | sessionKey = map.get("sessionKey"); |
| | | userInfo = userInfoMapper.queryByOpenid2(openid); |
| | | |
| | | |
| | | |
| | | }else{//APP |
| | | } else {//APP |
| | | userInfo = userInfoMapper.queryByOpenid(openid); |
| | | } |
| | | if(null == userInfo){ |
| | | if (null == userInfo) { |
| | | userInfo = new UserInfo(); |
| | | userInfo.setPassWord(ShiroKit.md5("", salt)); |
| | | userInfo.setRegistIp(registIp); |
| | | userInfo.setSex(sex); |
| | | userInfo.setNickName(ToolUtil.isNotEmpty(nickName) ? nickName : this.getDefaultName()); |
| | | userInfo.setAvatar(avatar); |
| | | if(type == 2){ |
| | | if (type == 2) { |
| | | userInfo.setAppletsOpenId(openid); |
| | | }else{ |
| | | } else { |
| | | userInfo.setOpenId(openid); |
| | | } |
| | | userInfo.setUnionid(unionid); |
| | |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | if(pushMinistryOfTransport){ |
| | | if (pushMinistryOfTransport) { |
| | | //上传数据 |
| | | pushMinistryOfTransportUtil.baseInfoPassenger(finalUserInfo.getId()); |
| | | } |
| | | } |
| | | }).start(); |
| | | } |
| | | if(userInfo.getState() == 2){ |
| | | if (userInfo.getState() == 2) { |
| | | return ResultUtil.error("账号被冻结"); |
| | | } |
| | | |
| | | if(type == 2){//小程序登录 |
| | | |
| | | if (type == 2) {//小程序登录 |
| | | String value = (String) redisTemplate.opsForValue().get("appletOpenId"); |
| | | JSONObject jsonObject = null; |
| | | if(ToolUtil.isNotEmpty(value)){ |
| | | if (ToolUtil.isNotEmpty(value)) { |
| | | jsonObject = JSON.parseObject(value); |
| | | }else{ |
| | | } else { |
| | | jsonObject = new JSONObject(); |
| | | } |
| | | 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); |
| | | String token = this.getToken(userInfo, "",loginType); |
| | | this.singlePointLogin(userInfo.getId(), loginType); |
| | | String token = this.getToken(userInfo, "", loginType); |
| | | LoginWarpper loginWarpper = new LoginWarpper(); |
| | | loginWarpper.setId(userInfo.getId()); |
| | | loginWarpper.setToken(token); |
| | |
| | | userInfo.setPhone(phone1); |
| | | userInfoMapper.updateById(userInfo); |
| | | } |
| | | |
| | | |
| | | |
| | | }else{//APP |
| | | userInfo = userInfoMapper.queryByOpenid(openid); |
| | | } |
| | |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | if(pushMinistryOfTransport){ |
| | | if (pushMinistryOfTransport) { |
| | | //上传数据 |
| | | pushMinistryOfTransportUtil.baseInfoPassenger(finalUserInfo.getId()); |
| | | } |
| | |
| | | }).start(); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | if(userInfo.getState() == 2){ |
| | | |
| | | if (userInfo.getState() == 2) { |
| | | return ResultUtil.error("账号被冻结"); |
| | | } |
| | | |
| | | if(type == 2){//小程序登录 |
| | | |
| | | if (type == 2) {//小程序登录 |
| | | String value = (String) redisTemplate.opsForValue().get("appletOpenId"); |
| | | JSONObject jsonObject = null; |
| | | if(ToolUtil.isNotEmpty(value)){ |
| | | if (ToolUtil.isNotEmpty(value)) { |
| | | jsonObject = JSON.parseObject(value); |
| | | }else{ |
| | | } else { |
| | | jsonObject = new JSONObject(); |
| | | } |
| | | 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); |
| | | } |
| | | |
| | | //调用单点登录的逻辑 |
| | |
| | | @Override |
| | | public ResultUtil bindingPhone(Integer uid, String phone, String code,String loginType) throws Exception { |
| | | boolean b = this.checkCaptcha(phone, code); |
| | | if(!b){ |
| | | if (!b) { |
| | | return ResultUtil.error("验证码无效"); |
| | | } |
| | | |
| | | |
| | | UserInfo userInfo = this.selectById(uid); |
| | | UserInfo userInfo1 = userInfoMapper.queryByPhone(phone); |
| | | if(null != userInfo1){ |
| | | 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.setSex(userInfo.getSex()); |
| | | userInfo1.setNickName(userInfo.getNickName()); |
| | | this.updateById(userInfo1); |
| | | |
| | | if(ToolUtil.isNotEmpty(loginType) && loginType.equals("Applets")){//小程序登录后绑定手机号码 |
| | | |
| | | if (ToolUtil.isNotEmpty(loginType) && loginType.equals("Applets")) {//小程序登录后绑定手机号码 |
| | | String value = (String) redisTemplate.opsForValue().get("appletOpenId"); |
| | | JSONObject jsonObject = null; |
| | | if(ToolUtil.isNotEmpty(value)){ |
| | | if (ToolUtil.isNotEmpty(value)) { |
| | | jsonObject = JSON.parseObject(value); |
| | | jsonObject.remove(userInfo.getId().toString());//删除原有账号缓存的数据 |
| | | }else{ |
| | | } else { |
| | | jsonObject = new JSONObject(); |
| | | } |
| | | jsonObject.put(userInfo1.getId().toString(), userInfo.getAppletsOpenId()); |
| | |
| | | } |
| | | userCouponRecordService.deleteById(ucr.getId()); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | //获取新的token等数据 |
| | | String token = this.getToken(userInfo1, "",loginType); |
| | | String token = this.getToken(userInfo1, "", loginType); |
| | | LoginWarpper loginWarpper = new LoginWarpper(); |
| | | loginWarpper.setId(userInfo1.getId()); |
| | | loginWarpper.setToken(token); |
| | |
| | | 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()); |
| | | userInfo.setUpdateUser(userInfo.getId()); |
| | | this.updateById(userInfo); |
| | | |
| | | |
| | | smsrecordService.saveData(2, phone, code, "短信验证码【" + code + "】已发到您的手机,验证码将在5分钟后失效,请及时登录!"); |
| | | return ResultUtil.success(new LoginWarpper()); |
| | | } |
| | |
| | | if(!b){ |
| | | return ResultUtil.error("验证码无效"); |
| | | } |
| | | |
| | | |
| | | UserInfo userInfo = this.selectById(uid); |
| | | UserInfo userInfo1 = userInfoMapper.queryByPhone(phone); |
| | | if(null != userInfo1){ |
| | |
| | | userInfo.setPhone(phone); |
| | | this.updateById(userInfo); |
| | | |
| | | // smsrecordService.saveData(2, phone, code, "短信验证码【" + code + "】已发到您的手机,验证码将在5分钟后失效,请及时登录!"); |
| | | return ResultUtil.success(); |
| | | } |
| | | |