Skip to content

Commit d6a274b

Browse files
committed
🎨 binarywang#3270【开放平台】同步官方获取授权方选项信息、设置授权方选项信息接口地址
修改调用方法
1 parent d2b37eb commit d6a274b

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ public interface WxOpenComponentService {
292292
*/
293293
String post(String uri, String postData, String accessTokenKey) throws WxErrorException;
294294

295+
String post(String uri, String postData, String accessTokenKey, String accessToken) throws WxErrorException;
296+
295297
/**
296298
* Get string.
297299
*

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

+18-2
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(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(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)