|
@@ -12,6 +12,7 @@ import com.zhongzheng.common.exception.CustomException;
|
|
|
import com.zhongzheng.common.utils.*;
|
|
|
import com.zhongzheng.common.utils.http.HttpUtils;
|
|
|
import com.zhongzheng.common.utils.ip.IpUtils;
|
|
|
+import com.zhongzheng.modules.alisms.service.IAliSmsService;
|
|
|
import com.zhongzheng.modules.course.mapper.CourseSectionMapper;
|
|
|
import com.zhongzheng.modules.user.bo.UserAddBo;
|
|
|
import com.zhongzheng.modules.user.domain.User;
|
|
@@ -75,6 +76,9 @@ public class WxLoginService
|
|
|
@Autowired
|
|
|
private UserMapper userMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IAliSmsService iSmsService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private UserSchoolInfoMapper userSchoolInfoMapper;
|
|
|
|
|
@@ -91,16 +95,17 @@ public class WxLoginService
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public Map<String,String> login(WxLoginBody loginBody) {
|
|
|
+ public Map<String,Object> login(WxLoginBody loginBody) {
|
|
|
User user = getWxUnionIdUser(loginBody);
|
|
|
if(user==null){
|
|
|
throw new CustomException("登录错误");
|
|
|
}
|
|
|
ClientLoginUser loginUser = new ClientLoginUser();
|
|
|
loginUser.setUser(user);
|
|
|
- Map<String,String> map = new HashMap<>();
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
map.put(Constants.TOKEN,wxTokenService.createToken(loginUser));
|
|
|
map.put("union_id",loginUser.getUser().getUnionId());
|
|
|
+ map.put("full_info",Validator.isEmpty(user.getIdCard())?false:true); //是否完善身份信息
|
|
|
return map;
|
|
|
}
|
|
|
|
|
@@ -169,7 +174,8 @@ public class WxLoginService
|
|
|
bo.setLastLoginTime(DateUtils.getNowTime());
|
|
|
bo.setCreateTime(DateUtils.getNowTime());
|
|
|
bo.setUpdateTime(DateUtils.getNowTime());
|
|
|
- bo.setStudentCode(ServletUtils.getEncoded("XY"));
|
|
|
+ String pwd = ToolsUtils.getSmsCode(); // 随机密码
|
|
|
+ bo.setPassword(SecurityUtils.encryptPassword(pwd));
|
|
|
if(inviteCode!=null){
|
|
|
User inviteUser = iUserService.queryByAccount(inviteCode);
|
|
|
if(inviteUser!=null){
|
|
@@ -177,11 +183,7 @@ public class WxLoginService
|
|
|
}
|
|
|
}
|
|
|
if(iUserService.save(bo)){
|
|
|
- UserSchoolInfo schoolInfo = new UserSchoolInfo();
|
|
|
- schoolInfo.setUserId(bo.getUserId());
|
|
|
- schoolInfo.setCreateTime(DateUtils.getNowTime());
|
|
|
- schoolInfo.setUpdateTime(DateUtils.getNowTime());
|
|
|
- userSchoolInfoMapper.insert(schoolInfo);
|
|
|
+ iSmsService.sendPwdSms(bo.getTelphone(),pwd);
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
@@ -215,12 +217,33 @@ public class WxLoginService
|
|
|
String openId = String.valueOf(jsonObject.get("openid"));
|
|
|
String unionId = String.valueOf(jsonObject.get("unionid"));
|
|
|
String phoneNumber = obtainWxPhone(loginBody.getIv(),loginBody.getEncryptedData(),session_key);
|
|
|
- User user = iUserService.queryByUnionId(unionId);
|
|
|
+ if(Validator.isEmpty(phoneNumber)){
|
|
|
+ throw new CustomException("该微信没有绑定手机号码");
|
|
|
+ }
|
|
|
+ User user = iUserService.getOne(new LambdaQueryWrapper<User>()
|
|
|
+ .eq(User::getTelphone,phoneNumber).last("limit 1"));
|
|
|
+ if(Validator.isNotEmpty(user)){
|
|
|
+ user.setOpenId(openId);
|
|
|
+ user.setUnionId(unionId);
|
|
|
+ user.setLastLoginTime(DateUtils.getNowTime());
|
|
|
+ user.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ iUserService.save(user);
|
|
|
+ }else{
|
|
|
+ //手机匹配不上再匹配openid
|
|
|
+ user = iUserService.getOne(new LambdaQueryWrapper<User>()
|
|
|
+ .eq(User::getOpenId,openId).last("limit 1"));
|
|
|
+ user.setTelphone(phoneNumber);
|
|
|
+ user.setUnionId(unionId);
|
|
|
+ user.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ user.setLastLoginTime(DateUtils.getNowTime());
|
|
|
+ iUserService.save(user);
|
|
|
+ }
|
|
|
if(user==null){
|
|
|
if(!register_small(openId,unionId,phoneNumber,loginBody.getInviteCode())){
|
|
|
throw new CustomException("注册失败");
|
|
|
}
|
|
|
- user = iUserService.queryByUnionId(unionId);
|
|
|
+ user = iUserService.getOne(new LambdaQueryWrapper<User>()
|
|
|
+ .eq(User::getTelphone,phoneNumber).last("limit 1"));
|
|
|
}
|
|
|
return user;
|
|
|
}
|