Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎨 #3270【开放平台】同步官方获取授权方选项信息、设置授权方选项信息接口地址 #3277

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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