From 222882d00339aebb4823600f31bb807541155ca8 Mon Sep 17 00:00:00 2001 From: waitxy <61042128+waitxy@users.noreply.github.com> Date: Wed, 15 May 2024 23:05:58 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20#3270=E3=80=90=E5=BC=80=E6=94=BE?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E3=80=91=E4=BF=AE=E6=94=B9=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=8E=88=E6=9D=83=E6=96=B9=E9=80=89=E9=A1=B9=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E3=80=81=E8=AE=BE=E7=BD=AE=E6=8E=88=E6=9D=83=E6=96=B9=E9=80=89?= =?UTF-8?q?=E9=A1=B9=E4=BF=A1=E6=81=AF=E6=8E=A5=E5=8F=A3=E7=9A=84=E5=9C=B0?= =?UTF-8?q?=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../open/api/WxOpenComponentService.java | 13 +++++++----- .../api/impl/WxOpenComponentServiceImpl.java | 20 +++++++++++++++++-- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenComponentService.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenComponentService.java index dbc36c261..d8e1795e0 100644 --- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenComponentService.java +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenComponentService.java @@ -55,13 +55,13 @@ public interface WxOpenComponentService { */ String API_GET_AUTHORIZER_INFO_URL = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info"; /** - * The constant API_GET_AUTHORIZER_OPTION_URL. + * The constant GET_AUTHORIZER_OPTION_URL. */ - String API_GET_AUTHORIZER_OPTION_URL = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_option"; + String GET_AUTHORIZER_OPTION_URL = "https://api.weixin.qq.com/cgi-bin/component/get_authorizer_option"; /** - * The constant API_SET_AUTHORIZER_OPTION_URL. + * The constant SET_AUTHORIZER_OPTION_URL. */ - String API_SET_AUTHORIZER_OPTION_URL = "https://api.weixin.qq.com/cgi-bin/component/api_set_authorizer_option"; + String SET_AUTHORIZER_OPTION_URL = "https://api.weixin.qq.com/cgi-bin/component/set_authorizer_option"; /** * The constant API_GET_AUTHORIZER_LIST. */ @@ -202,6 +202,7 @@ public interface WxOpenComponentService { String BATCH_SHARE_ENV = "https://api.weixin.qq.com/componenttcb/batchshareenv"; String COMPONENT_CLEAR_QUOTA_URL = "https://api.weixin.qq.com/cgi-bin/component/clear_quota/v2"; + /** * Gets wx mp service by appid. * @@ -291,6 +292,8 @@ public interface WxOpenComponentService { */ String post(String uri, String postData, String accessTokenKey) throws WxErrorException; + String post(String uri, String postData, String accessTokenKey, String accessToken) throws WxErrorException; + /** * Get string. * @@ -1092,7 +1095,7 @@ public interface WxOpenComponentService { * 使用 AppSecret 重置第三方平台 API 调用次数 * https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/openapi/clearComponentQuotaByAppSecret.html * - * @param appid 授权用户appid + * @param appid 授权用户appid * @return * @throws WxErrorException */ diff --git a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java index 4633153cd..1c0e7f16f 100644 --- a/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java +++ b/weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java @@ -231,6 +231,20 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService { } } + @Override + public String post(String uri, String postData, String accessTokenKey, String accessToken) throws WxErrorException { + String uriWithComponentAccessToken = uri + (uri.contains("?") ? "&" : "?") + accessTokenKey + "=" + accessToken; + try { + return getWxOpenService().post(uriWithComponentAccessToken, postData); + } catch (WxErrorException e) { + WxError error = e.getError(); + if (error.getErrorCode() != 0) { + throw new WxErrorException(error, e); + } + return error.getErrorMsg(); + } + } + @Override public String get(String uri) throws WxErrorException { return get(uri, "component_access_token"); @@ -398,22 +412,24 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService { @Override public WxOpenAuthorizerOptionResult getAuthorizerOption(String authorizerAppid, String optionName) throws WxErrorException { + String authorizerAccessToken = this.getAuthorizerAccessToken(authorizerAppid, false); JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("component_appid", getWxOpenConfigStorage().getComponentAppId()); jsonObject.addProperty("authorizer_appid", authorizerAppid); jsonObject.addProperty("option_name", optionName); - String responseContent = post(API_GET_AUTHORIZER_OPTION_URL, jsonObject.toString()); + String responseContent = post(GET_AUTHORIZER_OPTION_URL, jsonObject.toString(), "access_token", authorizerAccessToken); return WxOpenGsonBuilder.create().fromJson(responseContent, WxOpenAuthorizerOptionResult.class); } @Override public void setAuthorizerOption(String authorizerAppid, String optionName, String optionValue) throws WxErrorException { + String authorizerAccessToken = this.getAuthorizerAccessToken(authorizerAppid, false); JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("component_appid", getWxOpenConfigStorage().getComponentAppId()); jsonObject.addProperty("authorizer_appid", authorizerAppid); jsonObject.addProperty("option_name", optionName); jsonObject.addProperty("option_value", optionValue); - post(API_SET_AUTHORIZER_OPTION_URL, jsonObject.toString()); + post(SET_AUTHORIZER_OPTION_URL, jsonObject.toString(), "access_token", authorizerAccessToken); } @Override