Skip to content

Commit 222882d

Browse files
authored
🎨 binarywang#3270【开放平台】修改获取授权方选项信息、设置授权方选项信息接口的地址
1 parent 01f8e81 commit 222882d

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenComponentService.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ public interface WxOpenComponentService {
5555
*/
5656
String API_GET_AUTHORIZER_INFO_URL = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info";
5757
/**
58-
* The constant API_GET_AUTHORIZER_OPTION_URL.
58+
* The constant GET_AUTHORIZER_OPTION_URL.
5959
*/
60-
String API_GET_AUTHORIZER_OPTION_URL = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_option";
60+
String GET_AUTHORIZER_OPTION_URL = "https://api.weixin.qq.com/cgi-bin/component/get_authorizer_option";
6161
/**
62-
* The constant API_SET_AUTHORIZER_OPTION_URL.
62+
* The constant SET_AUTHORIZER_OPTION_URL.
6363
*/
64-
String API_SET_AUTHORIZER_OPTION_URL = "https://api.weixin.qq.com/cgi-bin/component/api_set_authorizer_option";
64+
String SET_AUTHORIZER_OPTION_URL = "https://api.weixin.qq.com/cgi-bin/component/set_authorizer_option";
6565
/**
6666
* The constant API_GET_AUTHORIZER_LIST.
6767
*/
@@ -202,6 +202,7 @@ public interface WxOpenComponentService {
202202
String BATCH_SHARE_ENV = "https://api.weixin.qq.com/componenttcb/batchshareenv";
203203

204204
String COMPONENT_CLEAR_QUOTA_URL = "https://api.weixin.qq.com/cgi-bin/component/clear_quota/v2";
205+
205206
/**
206207
* Gets wx mp service by appid.
207208
*
@@ -291,6 +292,8 @@ public interface WxOpenComponentService {
291292
*/
292293
String post(String uri, String postData, String accessTokenKey) throws WxErrorException;
293294

295+
String post(String uri, String postData, String accessTokenKey, String accessToken) throws WxErrorException;
296+
294297
/**
295298
* Get string.
296299
*
@@ -1092,7 +1095,7 @@ public interface WxOpenComponentService {
10921095
* 使用 AppSecret 重置第三方平台 API 调用次数
10931096
* https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/openapi/clearComponentQuotaByAppSecret.html
10941097
*
1095-
* @param appid 授权用户appid
1098+
* @param appid 授权用户appid
10961099
* @return
10971100
* @throws WxErrorException
10981101
*/

weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,20 @@ public String post(String uri, String postData, String accessTokenKey) throws Wx
231231
}
232232
}
233233

234+
@Override
235+
public String post(String uri, String postData, String accessTokenKey, String accessToken) throws WxErrorException {
236+
String uriWithComponentAccessToken = uri + (uri.contains("?") ? "&" : "?") + accessTokenKey + "=" + accessToken;
237+
try {
238+
return getWxOpenService().post(uriWithComponentAccessToken, postData);
239+
} catch (WxErrorException e) {
240+
WxError error = e.getError();
241+
if (error.getErrorCode() != 0) {
242+
throw new WxErrorException(error, e);
243+
}
244+
return error.getErrorMsg();
245+
}
246+
}
247+
234248
@Override
235249
public String get(String uri) throws WxErrorException {
236250
return get(uri, "component_access_token");
@@ -398,22 +412,24 @@ public WxOpenAuthorizerListResult getAuthorizerList(int begin, int len) throws W
398412

399413
@Override
400414
public WxOpenAuthorizerOptionResult getAuthorizerOption(String authorizerAppid, String optionName) throws WxErrorException {
415+
String authorizerAccessToken = this.getAuthorizerAccessToken(authorizerAppid, false);
401416
JsonObject jsonObject = new JsonObject();
402417
jsonObject.addProperty("component_appid", getWxOpenConfigStorage().getComponentAppId());
403418
jsonObject.addProperty("authorizer_appid", authorizerAppid);
404419
jsonObject.addProperty("option_name", optionName);
405-
String responseContent = post(API_GET_AUTHORIZER_OPTION_URL, jsonObject.toString());
420+
String responseContent = post(GET_AUTHORIZER_OPTION_URL, jsonObject.toString(), "access_token", authorizerAccessToken);
406421
return WxOpenGsonBuilder.create().fromJson(responseContent, WxOpenAuthorizerOptionResult.class);
407422
}
408423

409424
@Override
410425
public void setAuthorizerOption(String authorizerAppid, String optionName, String optionValue) throws WxErrorException {
426+
String authorizerAccessToken = this.getAuthorizerAccessToken(authorizerAppid, false);
411427
JsonObject jsonObject = new JsonObject();
412428
jsonObject.addProperty("component_appid", getWxOpenConfigStorage().getComponentAppId());
413429
jsonObject.addProperty("authorizer_appid", authorizerAppid);
414430
jsonObject.addProperty("option_name", optionName);
415431
jsonObject.addProperty("option_value", optionValue);
416-
post(API_SET_AUTHORIZER_OPTION_URL, jsonObject.toString());
432+
post(SET_AUTHORIZER_OPTION_URL, jsonObject.toString(), "access_token", authorizerAccessToken);
417433
}
418434

419435
@Override

0 commit comments

Comments
 (0)