Skip to content

Commit

Permalink
🎨 Wechat-Group#3270【开放平台】同步官方获取授权方选项信息、设置授权方选项信息接口地址
Browse files Browse the repository at this point in the history
修改调用方法
  • Loading branch information
waitxy committed May 9, 2024
1 parent d2b37eb commit d6a274b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,20 @@ public String post(String uri, String postData, String accessTokenKey) throws Wx
}
}

@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");
Expand Down Expand Up @@ -398,22 +412,24 @@ public WxOpenAuthorizerListResult getAuthorizerList(int begin, int len) throws W

@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(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(SET_AUTHORIZER_OPTION_URL, jsonObject.toString());
post(SET_AUTHORIZER_OPTION_URL, jsonObject.toString(), "access_token", authorizerAccessToken);
}

@Override
Expand Down

0 comments on commit d6a274b

Please sign in to comment.