|
@@ -57,40 +57,36 @@ public class WeChatTokenGranter implements ITokenGranter {
|
|
|
// 获取openId
|
|
|
JSONObject jsonObject = userWeChatService.getopenId(code);
|
|
|
String openId = jsonObject.getString("openid");
|
|
|
+ String unionId = jsonObject.getString("unionid");
|
|
|
User user = new User();
|
|
|
UserWeChat userWeChat = userWeChatService.lambdaQuery().eq(UserWeChat::getOpenId, openId).one();
|
|
|
|
|
|
if (userWeChat == null){
|
|
|
- User byAccount = userService.getByAccount(phoneNumber);
|
|
|
- if (byAccount == null){
|
|
|
- //该微信号未注册 注册用户
|
|
|
- user.setName("微信用户");
|
|
|
- user.setAccount(phoneNumber);
|
|
|
- user.setPhone(phoneNumber);
|
|
|
- user.setRealName("用户" + phoneNumber.substring(7));
|
|
|
- user.setSex(1);
|
|
|
- user.setUserType(2);//app
|
|
|
- userService.save(user);
|
|
|
-
|
|
|
- UserApp userApp = new UserApp();
|
|
|
- userApp.setUserId(user.getId());
|
|
|
- userApp.setState(YesOrNoEnum.YES.getValue());
|
|
|
- userApp.setNowMoney(new BigDecimal(0));
|
|
|
- userApp.setLivingHall(YesOrNoEnum.NO.getValue());
|
|
|
- userApp.setIsStore(YesOrNoEnum.NO.getValue());
|
|
|
- userAppService.save(userApp);
|
|
|
- userWeChat = new UserWeChat();
|
|
|
- userWeChat.setOpenId(openId);
|
|
|
- userWeChat.setUnionId(jsonObject.getString("unionid"));
|
|
|
- userWeChat.setUserId(user.getId());
|
|
|
- }else{
|
|
|
- //手机号已被注册。给该用户绑定openId
|
|
|
- userWeChat = new UserWeChat();
|
|
|
- userWeChat.setOpenId(openId);
|
|
|
- userWeChat.setUnionId(jsonObject.getString("unionid"));
|
|
|
- userWeChat.setUserId(byAccount.getId());
|
|
|
+// User byAccount = userService.getByAccount(phoneNumber);
|
|
|
+ User byAccount = userService.getByAccountAndType(phoneNumber,UserEnum.APP.getCategory());
|
|
|
+ if (Objects.nonNull(byAccount)){
|
|
|
+ throw new ServiceException("您提供的手机号已注册,请更换手机号!");
|
|
|
}
|
|
|
+ //注册用户
|
|
|
+ user.setName("微信用户");
|
|
|
+ user.setAccount(phoneNumber);
|
|
|
+ user.setPhone(phoneNumber);
|
|
|
+ user.setRealName("用户" + phoneNumber.substring(7));
|
|
|
+ user.setSex(1);
|
|
|
+ user.setUserType(UserEnum.APP.getCategory());//app
|
|
|
+ userService.save(user);
|
|
|
|
|
|
+ UserApp userApp = new UserApp();
|
|
|
+ userApp.setUserId(user.getId());
|
|
|
+ userApp.setState(YesOrNoEnum.YES.getValue());
|
|
|
+ userApp.setNowMoney(new BigDecimal(0));
|
|
|
+ userApp.setLivingHall(YesOrNoEnum.NO.getValue());
|
|
|
+ userApp.setIsStore(YesOrNoEnum.NO.getValue());
|
|
|
+ userAppService.save(userApp);
|
|
|
+ userWeChat = new UserWeChat();
|
|
|
+ userWeChat.setOpenId(openId);
|
|
|
+ userWeChat.setUnionId(unionId);
|
|
|
+ userWeChat.setUserId(user.getId());
|
|
|
}
|
|
|
user = userService.getById(userWeChat.getUserId());
|
|
|
userWeChat.setSessionKey(jsonObject.getString("session_key"));
|