微信登录
This commit is contained in:
parent
32ed751e3d
commit
0f4ed47422
|
@ -262,12 +262,9 @@ public class SysLoginService
|
|||
@Transactional
|
||||
public String wxLogin(WxLoginBody body) {
|
||||
|
||||
// 通过登录授权码获取到用户信息
|
||||
WxMaJscode2SessionResult wxMaJscode2SessionResult = wxAuthService.wxJsCode2Session(body.getLoginCode());
|
||||
ServiceUtil.assertion(wxMaJscode2SessionResult == null, "获取微信openId失败");
|
||||
|
||||
// 通过openId查询用户
|
||||
String openId = wxMaJscode2SessionResult.getOpenid();
|
||||
String openId = this.getWxOpenId(body.getLoginCode());
|
||||
ServiceUtil.assertion(openId == null, "获取微信openId失败");
|
||||
SmUser user = smUserService.selectSmUserByWxOpenId(openId);
|
||||
|
||||
// 若用户不存在,则使用openId进行注册
|
||||
|
@ -377,9 +374,14 @@ public class SysLoginService
|
|||
}
|
||||
|
||||
public String getWxOpenId(String loginCode) {
|
||||
if (loginCode == null) {
|
||||
return null;
|
||||
}
|
||||
// 通过登录授权码获取到用户信息
|
||||
WxMaJscode2SessionResult wxMaJscode2SessionResult = wxAuthService.wxJsCode2Session(loginCode);
|
||||
ServiceUtil.assertion(wxMaJscode2SessionResult == null, "获取微信openId失败");
|
||||
if (wxMaJscode2SessionResult == null) {
|
||||
return null;
|
||||
}
|
||||
return wxMaJscode2SessionResult.getOpenid();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ public class AppAuthController extends BaseController {
|
|||
// 获取微信openId
|
||||
String wxOpenId = loginService.getWxOpenId(body.getLoginCode());
|
||||
// 生成令牌
|
||||
String token = loginService.wxLogin(wxOpenId);
|
||||
String token = loginService.wxLogin(body);
|
||||
ajax.put(Constants.TOKEN, token);
|
||||
ajax.put("wxOpenId", wxOpenId);
|
||||
return ajax;
|
||||
|
|
Loading…
Reference in New Issue
Block a user