mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-05 17:38:05 +08:00
🎨 #3194 【小程序】优化openApi部分接口(getApiQuota 和 getRidInfo )响应类的部分字段信息
This commit is contained in:
parent
04a679cdd7
commit
80011c9b7e
@ -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
|
||||
@ -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对应的请求详情
|
||||
@ -51,7 +50,6 @@ public interface WxMaOpenApiService {
|
||||
|
||||
/**
|
||||
* 使用AppSecret重置 API 调用次数
|
||||
* HTTP调用:https://api.weixin.qq.com/cgi-bin/clear_quota/v2
|
||||
*
|
||||
* @return 是否成功
|
||||
* @throws WxErrorException 微信异常
|
||||
|
@ -23,7 +23,6 @@ import static me.chanjar.weixin.common.api.WxConsts.ERR_CODE;
|
||||
public class WxMaOpenApiServiceImpl implements WxMaOpenApiService {
|
||||
private final WxMaService wxMaService;
|
||||
|
||||
private static final String QUOTA = "quota";
|
||||
private static final String REQUEST = "request";
|
||||
|
||||
|
||||
@ -42,11 +41,7 @@ public class WxMaOpenApiServiceImpl implements WxMaOpenApiService {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -58,7 +53,7 @@ public class WxMaOpenApiServiceImpl implements WxMaOpenApiService {
|
||||
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;
|
||||
}
|
||||
|
@ -12,17 +12,73 @@ import lombok.Data;
|
||||
@Data
|
||||
public class WxMiniGetApiQuotaResult {
|
||||
|
||||
|
||||
/**
|
||||
* 当天该账号可调用该接口的次数
|
||||
* quota详情
|
||||
*/
|
||||
@SerializedName("daily_limit")
|
||||
private Integer dailyLimit;
|
||||
private WxMiniGetApiQuotaDetail quota;
|
||||
/**
|
||||
* 当天已经调用的次数
|
||||
* 普通调用频率限制
|
||||
*/
|
||||
private Integer used;
|
||||
private WxMiniGetApiQuotaRateLimit rateLimit;
|
||||
/**
|
||||
* 当天剩余调用次数
|
||||
* 代调用频率限制
|
||||
*/
|
||||
private Integer remain;
|
||||
private WxMiniGetApiQuotaComponentRateLimit componentRateLimit;
|
||||
|
||||
|
||||
/**
|
||||
* quota详情
|
||||
*/
|
||||
@Data
|
||||
private static class WxMiniGetApiQuotaDetail {
|
||||
/**
|
||||
* 当天该账号可调用该接口的次数
|
||||
*/
|
||||
@SerializedName("daily_limit")
|
||||
private Long dailyLimit;
|
||||
/**
|
||||
* 当天已经调用的次数
|
||||
*/
|
||||
private Long used;
|
||||
/**
|
||||
* 当天剩余调用次数
|
||||
*/
|
||||
private Long remain;
|
||||
}
|
||||
|
||||
/**
|
||||
* 普通调用频率限制
|
||||
*/
|
||||
@Data
|
||||
private static class WxMiniGetApiQuotaRateLimit {
|
||||
/**
|
||||
* 周期内可调用数量,单位 次
|
||||
*/
|
||||
@SerializedName("call_count")
|
||||
private Long callCount;
|
||||
/**
|
||||
* 更新周期,单位 秒
|
||||
*/
|
||||
@SerializedName("refresh_second")
|
||||
private Long refreshSecond;
|
||||
}
|
||||
|
||||
/**
|
||||
* 代调用频率限制
|
||||
*/
|
||||
@Data
|
||||
private static class WxMiniGetApiQuotaComponentRateLimit {
|
||||
/**
|
||||
* 周期内可调用数量,单位 次
|
||||
*/
|
||||
@SerializedName("call_count")
|
||||
private Long callCount;
|
||||
/**
|
||||
* 更新周期,单位 秒
|
||||
*/
|
||||
@SerializedName("refresh_second")
|
||||
private Long refreshSecond;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package cn.binarywang.wx.miniapp.api.impl;
|
||||
|
||||
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;
|
||||
@ -39,6 +40,15 @@ public class WxMaOpenApiServiceImplTest {
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user