|
|
@@ -45,14 +45,16 @@ public class WeChatService {
|
|
|
private String secretKey;
|
|
|
@Value("${app.wechat.appid}")
|
|
|
private String appid;
|
|
|
+ @Value("${app.wechat.api-base-url:https://api.weixin.qq.com}")
|
|
|
+ private String apiBaseUrl;
|
|
|
|
|
|
private String accessToken;
|
|
|
private LocalDateTime accessTokenExpireTime;
|
|
|
|
|
|
- private static final String WX_AUTH_PATH = "https://api.weixin.qq.com/sns/jscode2session";
|
|
|
- private static final String WX_ACCESS_KEY_PATH = "https://api.weixin.qq.com/cgi-bin/token";
|
|
|
- private static final String WX_ACODE_PATH = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=";
|
|
|
- private static final String WX_PHONE_PATH = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=";
|
|
|
+ private static final String WX_AUTH_PATH = "/sns/jscode2session";
|
|
|
+ private static final String WX_ACCESS_KEY_PATH = "/cgi-bin/token";
|
|
|
+ private static final String WX_ACODE_PATH = "/wxa/getwxacodeunlimit?access_token=";
|
|
|
+ private static final String WX_PHONE_PATH = "/wxa/business/getuserphonenumber?access_token=";
|
|
|
|
|
|
public Result wxLogin(String code) {
|
|
|
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
|
|
|
@@ -60,7 +62,7 @@ public class WeChatService {
|
|
|
params.add("secret", secretKey);
|
|
|
params.add("js_code", code);
|
|
|
params.add("grant_type", "authorization_code");
|
|
|
- String body = HttpUtil.requestGet(WX_AUTH_PATH, params, null);
|
|
|
+ String body = HttpUtil.requestGet(apiBaseUrl + WX_AUTH_PATH, params, null);
|
|
|
try {
|
|
|
JSONObject jsonObject = JSONObject.parseObject(body);
|
|
|
String openId = jsonObject.getString("openid");
|
|
|
@@ -77,7 +79,7 @@ public class WeChatService {
|
|
|
}
|
|
|
|
|
|
public PhoneResult wxPhoneLogin(String jsCode) {
|
|
|
- String currectUrl = WX_PHONE_PATH + getAccessToken();
|
|
|
+ String currectUrl = apiBaseUrl + WX_PHONE_PATH + getAccessToken();
|
|
|
|
|
|
Map<String, String> params = new HashMap<>();
|
|
|
params.put("code", jsCode);
|
|
|
@@ -104,7 +106,7 @@ public class WeChatService {
|
|
|
body.put("page", path);
|
|
|
body.put("scene", scene);
|
|
|
ResponseEntity<byte[]> res = HttpUtil.requestPostWithJson(
|
|
|
- WX_ACODE_PATH + getAccessToken(),
|
|
|
+ apiBaseUrl + WX_ACODE_PATH + getAccessToken(),
|
|
|
body,
|
|
|
null
|
|
|
);
|
|
|
@@ -117,7 +119,7 @@ public class WeChatService {
|
|
|
if (errcode != null && errcode.equals("40001")) {
|
|
|
refreshAccessToken();
|
|
|
res = HttpUtil.requestPostWithJson(
|
|
|
- WX_ACODE_PATH + getAccessToken(),
|
|
|
+ apiBaseUrl + WX_ACODE_PATH + getAccessToken(),
|
|
|
body,
|
|
|
null
|
|
|
);
|
|
|
@@ -158,7 +160,7 @@ public class WeChatService {
|
|
|
params.add("appid", appid);
|
|
|
params.add("secret", secretKey);
|
|
|
params.add("grant_type", "client_credential");
|
|
|
- String body = HttpUtil.requestGet(WX_ACCESS_KEY_PATH, params, null);
|
|
|
+ String body = HttpUtil.requestGet(apiBaseUrl + WX_ACCESS_KEY_PATH, params, null);
|
|
|
try {
|
|
|
JSONObject jsonObject = JSONObject.parseObject(body);
|
|
|
String accessToken = jsonObject.getString("access_token");
|