Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【微信小程序】设置自定义的获取accessToken地址 #2726

Merged
merged 1 commit into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ public HttpType getRequestType() {
@Override
protected String doGetAccessTokenRequest() throws IOException {

String url = StringUtils.isNotEmpty(this.getWxMaConfig().getApiHostUrl()) ?
String url = StringUtils.isNotEmpty(this.getWxMaConfig().getAccessTokenUrl()) ?
this.getWxMaConfig().getAccessTokenUrl() : StringUtils.isNotEmpty(this.getWxMaConfig().getApiHostUrl()) ?
WxMaService.GET_ACCESS_TOKEN_URL.replace("https://api.weixin.qq.com", this.getWxMaConfig().getApiHostUrl()) :
WxMaService.GET_ACCESS_TOKEN_URL;



url = String.format(url, this.getWxMaConfig().getAppid(), this.getWxMaConfig().getSecret());

HttpGet httpGet = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public HttpType getRequestType() {

@Override
protected String doGetAccessTokenRequest() throws IOException {
String url = StringUtils.isNotEmpty(this.getWxMaConfig().getApiHostUrl()) ?
String url = StringUtils.isNotEmpty(this.getWxMaConfig().getAccessTokenUrl()) ?
this.getWxMaConfig().getAccessTokenUrl() : StringUtils.isNotEmpty(this.getWxMaConfig().getApiHostUrl()) ?
WxMaService.GET_ACCESS_TOKEN_URL.replace("https://api.weixin.qq.com", this.getWxMaConfig().getApiHostUrl()) :
WxMaService.GET_ACCESS_TOKEN_URL;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public HttpType getRequestType() {

@Override
protected String doGetAccessTokenRequest() throws IOException {
String url = StringUtils.isNotEmpty(this.getWxMaConfig().getApiHostUrl()) ?
String url = StringUtils.isNotEmpty(this.getWxMaConfig().getAccessTokenUrl()) ?
this.getWxMaConfig().getAccessTokenUrl() : StringUtils.isNotEmpty(this.getWxMaConfig().getApiHostUrl()) ?
WxMaService.GET_ACCESS_TOKEN_URL.replace("https://api.weixin.qq.com", this.getWxMaConfig().getApiHostUrl()) :
WxMaService.GET_ACCESS_TOKEN_URL;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,19 @@ public interface WxMaConfig {
* @return 自定义的api域名地址
*/
String getApiHostUrl();

/**
* 获取自定义的获取accessToken地址,用于向自定义统一服务获取accessToken
*
* @return 自定义的获取accessToken地址
*/
String getAccessTokenUrl();

/**
* 设置自定义的获取accessToken地址
* 可用于设置获取accessToken的自定义服务
*
* @param accessTokenUrl 自定义的获取accessToken地址
*/
void setAccessTokenUrl(String accessTokenUrl);
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class WxMaDefaultConfigImpl implements WxMaConfig {
protected volatile Lock cardApiTicketLock = new ReentrantLock();
private volatile ApacheHttpClientBuilder apacheHttpClientBuilder;
private String apiHostUrl;
private String accessTokenUrl;

/**
* 会过期的数据提前过期时间,默认预留200秒的时间
Expand Down Expand Up @@ -303,6 +304,11 @@ public void setApiHostUrl(String apiHostUrl) {
this.apiHostUrl = apiHostUrl;
}

@Override
public void setAccessTokenUrl(String accessTokenUrl) {
this.accessTokenUrl = accessTokenUrl;
}

@Override
public String getAppid() {
return appid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ private static class WxOpenInnerConfigStorage implements WxMpConfigStorage, WxMa
private final String appId;
private WxMpHostConfig hostConfig;
private String apiHostUrl;
private String accessTokenUrl;

/**
* 小程序原始ID
Expand Down