|
|
@@ -55,15 +55,13 @@ public class WxLoginService
|
|
|
private UserMapper userMapper;
|
|
|
|
|
|
public String login(WxLoginBody loginBody) {
|
|
|
- String unionId = getWxUnionId(loginBody);
|
|
|
- /* User user = iUserService.queryByUnionId(unionId);
|
|
|
+ User user = getWxUnionIdUser(loginBody);
|
|
|
if(user==null){
|
|
|
- throw new CustomException("unionId不存在");
|
|
|
+ throw new CustomException("登录错误");
|
|
|
}
|
|
|
ClientLoginUser loginUser = new ClientLoginUser();
|
|
|
- loginUser.setUser(user);*/
|
|
|
- // return wxTokenService.createToken(loginUser);
|
|
|
- return unionId;
|
|
|
+ loginUser.setUser(user);
|
|
|
+ return wxTokenService.createToken(loginUser);
|
|
|
}
|
|
|
|
|
|
public String refreshToken(String unionId) {
|
|
|
@@ -104,7 +102,7 @@ public class WxLoginService
|
|
|
return iUserService.insertByAddBo(bo);
|
|
|
}
|
|
|
|
|
|
- public String getWxUnionId(WxLoginBody loginBody) {
|
|
|
+ public User getWxUnionIdUser(WxLoginBody loginBody) {
|
|
|
String param = String.format(wxAuthParam, appid, appsrcret, loginBody.getCode());
|
|
|
String resultString = HttpUtils.sendGet(wxAuthUrl,param);
|
|
|
//解析json
|
|
|
@@ -113,8 +111,15 @@ public class WxLoginService
|
|
|
String openId = String.valueOf(jsonObject.get("openid"));
|
|
|
String unionId = String.valueOf(jsonObject.get("unionid"));
|
|
|
// WxLoginResultBo wxLoginResult = restTemplate.getForObject(url, WxLoginResultBo.class);
|
|
|
- String wxResult = obtainWxPhone(loginBody.getIv(),loginBody.getEncryptedData(),session_key);
|
|
|
- return wxResult;
|
|
|
+ String phoneNumber = obtainWxPhone(loginBody.getIv(),loginBody.getEncryptedData(),session_key);
|
|
|
+ User user = iUserService.queryByUnionId(unionId);
|
|
|
+ if(user==null){
|
|
|
+ if(!register_small(openId,unionId,phoneNumber)){
|
|
|
+ throw new CustomException("注册失败");
|
|
|
+ }
|
|
|
+ user = iUserService.queryByUnionId(unionId);
|
|
|
+ }
|
|
|
+ return user;
|
|
|
}
|
|
|
|
|
|
public String obtainWxPhone(String iv, String encryptedData,String session_key){
|
|
|
@@ -127,7 +132,7 @@ public class WxLoginService
|
|
|
|
|
|
userInfo = new String(resultByte, "UTF-8");
|
|
|
userInfoJSON = JSON.parseObject(userInfo);
|
|
|
- return userInfo;
|
|
|
+ return String.valueOf(userInfoJSON.get("phoneNumber"));
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|