记得上下班打卡 | git大法好,push需谨慎

Commit 95aa5610 authored by 张国柄's avatar 张国柄

+API:wx get openID;

parent c9b58d89
...@@ -134,6 +134,8 @@ global-auth: ...@@ -134,6 +134,8 @@ global-auth:
- ${liquidnet.info.context}/addr/query/depth - ${liquidnet.info.context}/addr/query/depth
- ${liquidnet.info.context}/member/check/depth - ${liquidnet.info.context}/member/check/depth
- ${liquidnet.info.context}/plz/ad - ${liquidnet.info.context}/plz/ad
- ${liquidnet.info.context}/wxa/code2session
- ${liquidnet.info.context}/wx/oauth2/access_token
# ----------------------------------------------------------- # -----------------------------------------------------------
......
...@@ -284,6 +284,46 @@ public class AdamLoginController { ...@@ -284,6 +284,46 @@ public class AdamLoginController {
return ResponseDto.success(LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli()); return ResponseDto.success(LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli());
} }
@ApiOperationSupport(order = 9)
@ApiOperation(value = "微信登录凭证校验", notes = "登录凭证校验。通过 wx.login 接口获得临时登录凭证 code 后传到开发者服务器调用此接口完成登录流程。更多使用方法详见 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html")
@GetMapping(value = {"wxa/code2session"})
public ResponseDto<Object> wxaCode2Session(@RequestParam String jsCode) {
String openId = null;
try {
String url = "https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code";
url = url.replace("APPID", "wx4732efeaa2b08086").replace("SECRET", "94562c1f92da1b6cb3f1327c8842c6d3").replace("JSCODE", jsCode);
String respJStr = HttpUtil.get(url, null);
JsonNode respJNode = JsonUtils.fromJson(respJStr, JsonNode.class);
if (null == respJNode) {
return ResponseDto.success(null);
}
openId = String.valueOf(respJNode.get("openid"));
} catch (Exception e) {
log.error("WX.API调用异常", e);
}
return ResponseDto.success(openId);
}
@ApiOperationSupport(order = 10)
@ApiOperation(value = "微信网站应用登录", notes = "方法详见 https://developers.weixin.qq.com/doc/oplatform/Website_App/WeChat_Login/Wechat_Login.html")
@GetMapping(value = {"wx/oauth2/access_token"})
public ResponseDto<String> wxOauth2AccessToken(@RequestParam String code) {
String openId = null;
try {
String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code";
url = url.replace("APPID", "wx3498304dda39c5a1").replace("SECRET", "a1307fab0a5f2380086a7c636f7339ea").replace("CODE", code);
String respJStr = HttpUtil.get(url, null);
JsonNode respJNode = JsonUtils.fromJson(respJStr, JsonNode.class);
if (null == respJNode || !respJNode.get("errcode").isEmpty()) {
return ResponseDto.success(null);
}
openId = String.valueOf(respJNode.get("openid"));
} catch (Exception e) {
log.error("WX.API调用异常", e);
}
return ResponseDto.success(openId);
}
/* ---------------------------- Internal Method ---------------------------- */ /* ---------------------------- Internal Method ---------------------------- */
private boolean checkSmsCode(String mobile, String code) { private boolean checkSmsCode(String mobile, String code) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment