Commit 245334b8 authored by shiyu's avatar shiyu

获取token

parent 62569629
...@@ -19,7 +19,7 @@ dts: ...@@ -19,7 +19,7 @@ dts:
officialaccount-secret: daecb3de53841fe1a787bc9849ac3406 officialaccount-secret: daecb3de53841fe1a787bc9849ac3406
officialaccount-token: Uu6GHYOiP1xJ6GaBMyXfnITufAGJTe3Q officialaccount-token: Uu6GHYOiP1xJ6GaBMyXfnITufAGJTe3Q
officialaccount-key: noeN1amYRvzrVmE2GnC5VnsIfgPEmv6bhX54wJOARlM officialaccount-key: noeN1amYRvzrVmE2GnC5VnsIfgPEmv6bhX54wJOARlM
get-officialaccount-accesstoken-url: https://api.weixin.qq.com/cgi-bin/stable_token?grant_type=client_credential&appid=%s&secret=%s get-officialaccount-accesstoken-url: https://api.weixin.qq.com/cgi-bin/stable_token
#腾讯IM配置 #腾讯IM配置
im: im:
......
...@@ -159,15 +159,22 @@ public class WxLoginManager { ...@@ -159,15 +159,22 @@ public class WxLoginManager {
public String refreshAccessToken() { public String refreshAccessToken() {
logger.info("开始获取小程序access_token----------------"); logger.info("开始获取小程序access_token----------------");
try { try {
String accessTokenUrl = String.format(GET_ACCESS_TOKEN_URL, APPLET_APPID, APPLET_APP_SECRET); String accessTokenUrl = null;
String res = null; String res = null;
logger.info("取调用凭证access_token url :{}", accessTokenUrl);
//正式环境的url中包含了"stable_token", 要使用post请求, 测试环境是get请求 //正式环境的url中包含了"stable_token", 要使用post请求, 测试环境是get请求
if (!GET_ACCESS_TOKEN_URL.contains("stable_token")) { if (!GET_ACCESS_TOKEN_URL.contains("stable_token")) {
accessTokenUrl = String.format(GET_ACCESS_TOKEN_URL, APPLET_APPID, APPLET_APP_SECRET);
logger.info("取调用凭证access_token url :{}", accessTokenUrl);
res = OkHttpUtil.builder().url(accessTokenUrl) res = OkHttpUtil.builder().url(accessTokenUrl)
.get().sync(); .get().sync();
} else { } else {
res = OkHttpUtil.builder().url(accessTokenUrl) accessTokenUrl = GET_ACCESS_TOKEN_URL;
logger.info("取调用凭证access_token url :{}", accessTokenUrl);
Map<String, Object> map = new HashMap<>();
map.put("grant_type", "client_credential");
map.put("appid", APPLET_APPID);
map.put("secret", APPLET_APP_SECRET);
res = OkHttpUtil.builder().addParams(map).url(accessTokenUrl)
.post(true).sync(); .post(true).sync();
} }
logger.info("获取小程序access_token结果:" + res); logger.info("获取小程序access_token结果:" + res);
......
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