diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceHttpClientImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceHttpClientImpl.java index 6914977861..f0816fc85a 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceHttpClientImpl.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceHttpClientImpl.java @@ -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; diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceJoddHttpImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceJoddHttpImpl.java index 90ee6516ae..f14d8cd6dd 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceJoddHttpImpl.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceJoddHttpImpl.java @@ -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; diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceOkHttpImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceOkHttpImpl.java index 0fa49d9d07..6f1fdbfd9a 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceOkHttpImpl.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceOkHttpImpl.java @@ -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; diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/config/WxMaConfig.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/config/WxMaConfig.java index b8ba1e188b..208710b75f 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/config/WxMaConfig.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/config/WxMaConfig.java @@ -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); } diff --git a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/config/impl/WxMaDefaultConfigImpl.java b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/config/impl/WxMaDefaultConfigImpl.java index c05d6f1aa2..074603091c 100644 --- a/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/config/impl/WxMaDefaultConfigImpl.java +++ b/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/config/impl/WxMaDefaultConfigImpl.java @@ -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秒的时间 @@ -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; diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenInMemoryConfigStorage.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenInMemoryConfigStorage.java index 4a01dd4ec2..f8dd345ee7 100644 --- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenInMemoryConfigStorage.java +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenInMemoryConfigStorage.java @@ -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