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

Commit 1f74c37a authored by 张国柄's avatar 张国柄

fix:config:adam wechat;

parent 1f9e3da0
package com.liquidnet.service.adam.constant;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
@Configuration
public class AdamWechatConst {
/* =============================================================== | 变量配置 */
public static String zhengzaiAppletAppid;
public static String zhengzaiAppletSecret;
public static String zhengzaiServiceAppid;
public static String zhengzaiServiceSecret;
/* =============================================================== | API常量配置 */
public static final String API_URL_JS_CODE2SESSION = "https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code";
public static final String API_URL_OAUTH2_ACCESS_TOKEN = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code";
/* =============================================================== | */
/* =============================================================== | */
@Value("${liquidnet.wechat.zhengzai.applet.appid}")
public void setZhengzaiAppletAppid(String zhengzaiAppletAppid) {
AdamWechatConst.zhengzaiAppletAppid = zhengzaiAppletAppid;
}
@Value("${liquidnet.wechat.zhengzai.applet.secret}")
public void setZhengzaiAppletSecret(String zhengzaiAppletSecret) {
AdamWechatConst.zhengzaiAppletSecret = zhengzaiAppletSecret;
}
@Value("${liquidnet.wechat.zhengzai.service.appid}")
public void setZhengzaiServiceAppid(String zhengzaiServiceAppid) {
AdamWechatConst.zhengzaiServiceAppid = zhengzaiServiceAppid;
}
@Value("${liquidnet.wechat.zhengzai.service.secret}")
public void setZhengzaiServiceSecret(String zhengzaiServiceSecret) {
AdamWechatConst.zhengzaiServiceSecret = zhengzaiServiceSecret;
}
}
......@@ -87,6 +87,14 @@ liquidnet:
dysms:
accessKeyId: LTAI5tHt7yvm97G8zxackcMK
accessKeySecret: xC3i5qEptJ3JIIRaYLaKvhk4gVASfl
wechat:
zhengzai:
applet:
appid: wx4732efeaa2b08086
secret: 94562c1f92da1b6cb3f1327c8842c6d3
service:
appid: wx3498304dda39c5a1
secret: a1307fab0a5f2380086a7c636f7339ea
#application-dev-end
......@@ -87,6 +87,14 @@ liquidnet:
dysms:
accessKeyId: LTAI5tHt7yvm97G8zxackcMK
accessKeySecret: xC3i5qEptJ3JIIRaYLaKvhk4gVASfl
wechat:
zhengzai:
applet:
appid: wx4732efeaa2b08086
secret: 94562c1f92da1b6cb3f1327c8842c6d3
service:
appid: wx3498304dda39c5a1
secret: a1307fab0a5f2380086a7c636f7339ea
#application-test-end
\ No newline at end of file
......@@ -16,6 +16,7 @@ import com.liquidnet.commons.lang.constant.LnsEnum;
import com.liquidnet.commons.lang.core.JwtValidator;
import com.liquidnet.commons.lang.util.*;
import com.liquidnet.service.adam.constant.AdamRedisConst;
import com.liquidnet.service.adam.constant.AdamWechatConst;
import com.liquidnet.service.adam.dto.AdamThirdPartParam;
import com.liquidnet.service.adam.dto.vo.AdamLoginInfoVo;
import com.liquidnet.service.adam.dto.vo.AdamUserInfoVo;
......@@ -331,13 +332,14 @@ public class AdamLoginController {
}
@ApiOperationSupport(order = 9)
@ApiOperation(value = "微信登录凭证校验", notes = "登录凭证校验。通过 wx.login 接口获得临时登录凭证 code 后传到开发者服务器调用此接口完成登录流程。更多使用方法详见 https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html")
@ApiOperation(value = "微信小程序登录凭证校验", notes = "这里仅用于获取OPENID使用。登录凭证校验。通过 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) {
public ResponseDto<String> 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 url = "https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code";
String url = AdamWechatConst.API_URL_JS_CODE2SESSION.replace("APPID", AdamWechatConst.zhengzaiAppletAppid)
.replace("SECRET", AdamWechatConst.zhengzaiAppletSecret).replace("JSCODE", jsCode);
String respJStr = HttpUtil.get(url, null);
JsonNode respJNode = JsonUtils.fromJson(respJStr, JsonNode.class);
if (null == respJNode) {
......@@ -345,19 +347,20 @@ public class AdamLoginController {
}
openId = respJNode.get("openid").asText();
} catch (Exception e) {
log.error("WX.API调用异常", e);
log.error("WX.API调用异常[jsCode:{}]", jsCode, 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")
@ApiOperation(value = "微信网站应用登录", notes = "这里仅用于获取OPENID使用。方法详见 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 url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code";
String url = AdamWechatConst.API_URL_OAUTH2_ACCESS_TOKEN.replace("APPID", AdamWechatConst.zhengzaiServiceAppid)
.replace("SECRET", AdamWechatConst.zhengzaiServiceSecret).replace("CODE", code);
String respJStr = HttpUtil.get(url, null);
JsonNode respJNode = JsonUtils.fromJson(respJStr, JsonNode.class);
if (null == respJNode || !respJNode.get("errcode").isEmpty()) {
......@@ -365,7 +368,7 @@ public class AdamLoginController {
}
openId = respJNode.get("openid").asText();
} catch (Exception e) {
log.error("WX.API调用异常", e);
log.error("WX.API调用异常[code:{}]", code, e);
}
return ResponseDto.success(openId);
}
......
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