Skip to content

🎨 【小程序】优化openApi相关接口响应变更 #3194

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

Merged
merged 1 commit into from
Dec 26, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public interface WxMaOpenApiService {

/**
* 本接口用于清空公众号/小程序/第三方平台等接口的每日调用接口次数
* HTTP调用:https://api.weixin.qq.com/cgi-bin/clear_quota?access_token=ACCESS_TOKEN
*
* @return 是否成功
* @throws WxErrorException the wx error exception
Expand All @@ -28,18 +27,18 @@ public interface WxMaOpenApiService {

/**
* 查询API调用额度
* HTTP调用:https://api.weixin.qq.com/cgi-bin/openapi/quota/get?access_token=ACCESS_TOKEN
*
* @param cgiPath api的请求地址,例如"/cgi-bin/message/custom/send";不要前缀“https://api.weixin.qq.com” ,也不要漏了"/",否则都会76003的报错
* @param cgiPath api的请求地址,
* 例如"/cgi-bin/message/custom/send";不要前缀“https://api.weixin.qq.com” ,也不要漏了"/",否则都会76003的报错;
* @return 额度详情
* @throws WxErrorException 微信异常
* @apiNote "/xxx/sns/xxx" 这类接口不支持使用该接口,会出现76022报错。
* @see <a href="https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/openApi-mgnt/getApiQuota.html">注意事项参考微信文档</a>
*/
WxMiniGetApiQuotaResult getApiQuota(String cgiPath) throws WxErrorException;

/**
* 查询rid信息
* HTTP调用:https://api.weixin.qq.com/cgi-bin/openapi/rid/get?access_token=ACCESS_TOKEN
*
* @param rid 调用接口报错返回的rid
* @return 该rid对应的请求详情
Expand All @@ -51,7 +50,6 @@ public interface WxMaOpenApiService {

/**
* 使用AppSecret重置 API 调用次数
* HTTP调用:https://api.weixin.qq.com/cgi-bin/clear_quota/v2
*
* @return 是否成功
* @throws WxErrorException 微信异常
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
public class WxMaOpenApiServiceImpl implements WxMaOpenApiService {
private final WxMaService wxMaService;

private static final String QUOTA = "quota";
private static final String REQUEST = "request";


Expand All @@ -42,11 +41,7 @@ public WxMiniGetApiQuotaResult getApiQuota(String cgiPath) throws WxErrorExcepti
params.addProperty("cgi_path", cgiPath);
String responseContent = this.wxMaService.post(WxMaApiUrlConstants.OpenApi.GET_API_QUOTA, params.toString());
parseErrorResponse(responseContent);
JsonObject response = GsonParser.parse(responseContent);
if (response.has(QUOTA)) {
return WxMaGsonBuilder.create().fromJson(response.getAsJsonObject(QUOTA), WxMiniGetApiQuotaResult.class);
}
return null;
return WxMaGsonBuilder.create().fromJson(GsonParser.parse(responseContent), WxMiniGetApiQuotaResult.class);
}


Expand All @@ -58,7 +53,7 @@ public WxMiniGetRidInfoResult getRidInfo(String rid) throws WxErrorException {
parseErrorResponse(responseContent);
JsonObject response = GsonParser.parse(responseContent);
if (response.has(REQUEST)) {
return WxMaGsonBuilder.create().fromJson(response.getAsJsonObject(QUOTA), WxMiniGetRidInfoResult.class);
return WxMaGsonBuilder.create().fromJson(response.getAsJsonObject(REQUEST), WxMiniGetRidInfoResult.class);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,73 @@
@Data
public class WxMiniGetApiQuotaResult {


/**
* quota详情
*/
private WxMiniGetApiQuotaDetail quota;
/**
* 普通调用频率限制
*/
private WxMiniGetApiQuotaRateLimit rateLimit;
/**
* 代调用频率限制
*/
private WxMiniGetApiQuotaComponentRateLimit componentRateLimit;


/**
* 当天该账号可调用该接口的次数
* quota详情
*/
@SerializedName("daily_limit")
private Integer dailyLimit;
@Data
private static class WxMiniGetApiQuotaDetail {
/**
* 当天该账号可调用该接口的次数
*/
@SerializedName("daily_limit")
private Long dailyLimit;
/**
* 当天已经调用的次数
*/
private Long used;
/**
* 当天剩余调用次数
*/
private Long remain;
}

/**
* 当天已经调用的次数
* 普通调用频率限制
*/
private Integer used;
@Data
private static class WxMiniGetApiQuotaRateLimit {
/**
* 周期内可调用数量,单位 次
*/
@SerializedName("call_count")
private Long callCount;
/**
* 更新周期,单位 秒
*/
@SerializedName("refresh_second")
private Long refreshSecond;
}

/**
* 当天剩余调用次数
* 代调用频率限制
*/
private Integer remain;
@Data
private static class WxMiniGetApiQuotaComponentRateLimit {
/**
* 周期内可调用数量,单位 次
*/
@SerializedName("call_count")
private Long callCount;
/**
* 更新周期,单位 秒
*/
@SerializedName("refresh_second")
private Long refreshSecond;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.openapi.WxMiniGetApiQuotaResult;
import cn.binarywang.wx.miniapp.bean.openapi.WxMiniGetRidInfoResult;
import cn.binarywang.wx.miniapp.test.ApiTestModule;
import com.google.gson.Gson;
import com.google.inject.Inject;
Expand Down Expand Up @@ -39,6 +40,15 @@ public void getApiQuota() throws WxErrorException {
assertNotNull(apiQuota);
System.out.println(new Gson().toJson(apiQuota));
}

@Test
public void getApiQuotaInfo() throws WxErrorException {
String rid = "658723fa-2d3a0086-64bc7215";
final WxMiniGetRidInfoResult ridInfo = wxMaService.getWxMaOpenApiService().getRidInfo(rid);
assertNotNull(ridInfo);
System.out.println(new Gson().toJson(ridInfo));
}

@Test
public void clearQuotaByAppSecret() throws WxErrorException {
final boolean result = wxMaService.getWxMaOpenApiService().clearQuotaByAppSecret();
Expand Down