|
@@ -144,11 +144,10 @@ public class SysLoginController
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 用户 openid登录
|
|
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
@PostMapping("/login/code")
|
|
@PostMapping("/login/code")
|
|
- @ApiOperation("微信用户授权码模式登录")
|
|
|
|
|
|
+ @ApiOperation("app微信用户授权码模式登录")
|
|
public Response<TokenDTO> loginByWxAuthorizationCode(String authorizationCode ){
|
|
public Response<TokenDTO> loginByWxAuthorizationCode(String authorizationCode ){
|
|
String wxResultStr = wxService.getWxToken(appid, appSecret, authorizationCode, "authorization_code");
|
|
String wxResultStr = wxService.getWxToken(appid, appSecret, authorizationCode, "authorization_code");
|
|
logger.info("微信授权码登录返回值:"+wxResultStr);
|
|
logger.info("微信授权码登录返回值:"+wxResultStr);
|
|
@@ -163,7 +162,6 @@ public class SysLoginController
|
|
WxUserInfo wxUserInfo = JSONObject.parseObject(userInfoStr,WxUserInfo.class);
|
|
WxUserInfo wxUserInfo = JSONObject.parseObject(userInfoStr,WxUserInfo.class);
|
|
ServletUtils.getRequest().setAttribute("headImage",wxUserInfo.getHeadimgurl());
|
|
ServletUtils.getRequest().setAttribute("headImage",wxUserInfo.getHeadimgurl());
|
|
ServletUtils.getRequest().setAttribute("nickName",wxUserInfo.getNickname());
|
|
ServletUtils.getRequest().setAttribute("nickName",wxUserInfo.getNickname());
|
|
- ServletUtils.getRequest().setAttribute("third","weixin");
|
|
|
|
ServletUtils.getRequest().setAttribute("openid",wxUserInfo.getOpenid());
|
|
ServletUtils.getRequest().setAttribute("openid",wxUserInfo.getOpenid());
|
|
String token = loginService.login(wxUserInfo.getUnionid(),null, StudentLoginTypeEnum.AUTHORIZATION_XCX_LOGIN.getCode());
|
|
String token = loginService.login(wxUserInfo.getUnionid(),null, StudentLoginTypeEnum.AUTHORIZATION_XCX_LOGIN.getCode());
|
|
TokenDTO tokenDTO = new TokenDTO();
|
|
TokenDTO tokenDTO = new TokenDTO();
|
|
@@ -173,6 +171,36 @@ public class SysLoginController
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 用户 openid登录
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+ @PostMapping("/login/gzhcode")
|
|
|
|
+ @ApiOperation("公众号h5用户授权码模式登录")
|
|
|
|
+ public Response<TokenDTO> loginByAuthorizationCode(String authorizationCode ){
|
|
|
|
+ String wxResultStr = wxService.getWxToken(appid, appSecret, authorizationCode, "authorization_code");
|
|
|
|
+ logger.info("微信授权码登录返回值:"+wxResultStr);
|
|
|
|
+ WxResult wxResult = JSONObject.parseObject(wxResultStr,WxResult.class);
|
|
|
|
+
|
|
|
|
+ // 生成令牌
|
|
|
|
+ if (wxResult.getErrcode() != null){
|
|
|
|
+ throw new CustomException("微信授权无效,请重新授权");
|
|
|
|
+ }
|
|
|
|
+ String userInfoStr = wxService.getUserInfo("zh_CN", wxResult.getAccess_token(), wxResult.getOpenid());
|
|
|
|
+ WxUserInfo wxUserInfo = JSONObject.parseObject(userInfoStr,WxUserInfo.class);
|
|
|
|
+ ServletUtils.getRequest().setAttribute("headImage",wxUserInfo.getHeadimgurl());
|
|
|
|
+ ServletUtils.getRequest().setAttribute("nickName",wxUserInfo.getNickname());
|
|
|
|
+ ServletUtils.getRequest().setAttribute("openid",wxUserInfo.getOpenid());
|
|
|
|
+ String token = loginService.login(wxUserInfo.getUnionid(),null, StudentLoginTypeEnum.AUTHORIZATION_H5_LOGIN.getCode());
|
|
|
|
+ TokenDTO tokenDTO = new TokenDTO();
|
|
|
|
+ tokenDTO.setToken(token);
|
|
|
|
+ tokenDTO.setThirdResult(wxUserInfo);
|
|
|
|
+ return Response.success(tokenDTO) ;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -198,6 +226,7 @@ public class SysLoginController
|
|
ServletUtils.getRequest().setAttribute("xcxOpenid",wxUserInfo.getOpenid());
|
|
ServletUtils.getRequest().setAttribute("xcxOpenid",wxUserInfo.getOpenid());
|
|
String token = loginService.login(wxUserInfo.getUnionid(),null, StudentLoginTypeEnum.AUTHORIZATION_XCX_LOGIN.getCode());
|
|
String token = loginService.login(wxUserInfo.getUnionid(),null, StudentLoginTypeEnum.AUTHORIZATION_XCX_LOGIN.getCode());
|
|
tokenDTO.setToken(token);
|
|
tokenDTO.setToken(token);
|
|
|
|
+ tokenDTO.setThirdResult(wxUserInfo);
|
|
return Response.success(tokenDTO) ;
|
|
return Response.success(tokenDTO) ;
|
|
}
|
|
}
|
|
else{
|
|
else{
|