|
@@ -85,7 +85,11 @@ public class SysLoginController
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(SysLoginController.class);
|
|
|
|
|
|
+ @Value("${zzgzh.appId}")
|
|
|
+ private String gzhAppid;
|
|
|
|
|
|
+ @Value("${zzgzh.appSecret}")
|
|
|
+ private String gzhAppSecret;
|
|
|
|
|
|
|
|
|
@Value("${app.appId}")
|
|
@@ -327,22 +331,37 @@ public class SysLoginController
|
|
|
|
|
|
}
|
|
|
|
|
|
-//
|
|
|
-// /**
|
|
|
-// * 用户 jscode登录
|
|
|
-// *
|
|
|
-// */
|
|
|
-// @PostMapping("/login/jscode-test")
|
|
|
-// @ApiOperation("用户jscode登录(测试,固定openid)")
|
|
|
-// public Response<TokenDTO> getInfoTest(String jscode){
|
|
|
-// TokenDTO tokenDTO = new TokenDTO();
|
|
|
-// // 生成令牌
|
|
|
-// String token = loginService.login("oO7PJ5CPQJo62kZWA3uiUX2KG2s4",null, StudentLoginTypeEnum.AUTHORIZATION_CODE_LOGIN.getCode());
|
|
|
-// tokenDTO.setToken(token);
|
|
|
-// return Response.success(tokenDTO) ;
|
|
|
-//
|
|
|
-//
|
|
|
-// }
|
|
|
+ /**
|
|
|
+ * 用户 openid登录
|
|
|
+ *
|
|
|
+ */
|
|
|
+ @PostMapping("/login/gzhcode")
|
|
|
+ @ApiOperation("公众号微信用户授权码模式登录")
|
|
|
+ public Response<TokenDTO> loginByAuthorizationGzhCode(String authorizationCode ){
|
|
|
+ String wxResultStr = wxService.getWxToken(gzhAppid, gzhAppSecret, 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("openid",wxUserInfo.getOpenid());
|
|
|
+ ServletUtils.getRequest().setAttribute("headImage",wxUserInfo.getHeadimgurl());
|
|
|
+ ServletUtils.getRequest().setAttribute("nickName",wxUserInfo.getNickname());
|
|
|
+ String token = loginService.login(wxUserInfo.getUnionid(),null, StudentLoginTypeEnum.AUTHORIZATION_CODE_GZH_LOGIN.getCode());
|
|
|
+ TokenDTO tokenDTO = new TokenDTO();
|
|
|
+ tokenDTO.setToken(token);
|
|
|
+ tokenDTO.setThirdResult(wxUserInfo);
|
|
|
+ return Response.success(tokenDTO) ;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
|
|
|
/**
|