Skip to content

Commit

Permalink
🎨 #3270【开放平台】修改获取授权方选项信息、设置授权方选项信息接口的地址
Browse files Browse the repository at this point in the history
  • Loading branch information
waitxy committed May 15, 2024
1 parent 01f8e81 commit 222882d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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
*/
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(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
Expand Down

0 comments on commit 222882d

Please sign in to comment.