|
|
@@ -52,14 +52,15 @@ public class WxLoginService
|
|
|
private UserMapper userMapper;
|
|
|
|
|
|
public String login(WxLoginBody loginBody) {
|
|
|
- String unionId = getWxUnionId(loginBody.getCode());
|
|
|
+ String unionId = getWxUnionId(loginBody);
|
|
|
User user = iUserService.queryByUnionId(unionId);
|
|
|
if(user==null){
|
|
|
throw new CustomException("unionId不存在");
|
|
|
}
|
|
|
ClientLoginUser loginUser = new ClientLoginUser();
|
|
|
loginUser.setUser(user);
|
|
|
- return wxTokenService.createToken(loginUser);
|
|
|
+ // return wxTokenService.createToken(loginUser);
|
|
|
+ return unionId;
|
|
|
}
|
|
|
|
|
|
public String refreshToken(String unionId) {
|
|
|
@@ -100,13 +101,14 @@ public class WxLoginService
|
|
|
return iUserService.insertByAddBo(bo);
|
|
|
}
|
|
|
|
|
|
- public String getWxUnionId(String code) {
|
|
|
- String url = String.format(wxAuthUrl, appid, appsrcret, code);
|
|
|
- // WxLoginResultBo wxLoginResult = restTemplate.getForObject(url, WxLoginResultBo.class);
|
|
|
- return "cba";
|
|
|
+ public String getWxUnionId(WxLoginBody loginBody) {
|
|
|
+ String url = String.format(wxAuthUrl, appid, appsrcret, loginBody.getCode());
|
|
|
+ WxLoginResultBo wxLoginResult = restTemplate.getForObject(url, WxLoginResultBo.class);
|
|
|
+ String wxResult = obtainWxPhone(loginBody.getIv(),loginBody.getEncryptedData(),wxLoginResult.getSession_key());
|
|
|
+ return wxResult;
|
|
|
}
|
|
|
|
|
|
- public void obtainWxPhone(String iv, String encryptedData,String session_key){
|
|
|
+ public String obtainWxPhone(String iv, String encryptedData,String session_key){
|
|
|
String userInfo = null;
|
|
|
JSONObject userInfoJSON = null;
|
|
|
try {
|
|
|
@@ -116,8 +118,10 @@ public class WxLoginService
|
|
|
|
|
|
userInfo = new String(resultByte, "UTF-8");
|
|
|
userInfoJSON = JSON.parseObject(userInfo);
|
|
|
+ return userInfo;
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|