Skip to content

Commit 8a63f02

Browse files
shuiyihan12boris.bao
authored and
boris.bao
committed
🎨 binarywang#3194 【小程序】优化openApi部分接口(getApiQuota 和 getRidInfo )响应类的部分字段信息
1 parent b14ff56 commit 8a63f02

File tree

4 files changed

+78
-19
lines changed

4 files changed

+78
-19
lines changed

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaOpenApiService.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public interface WxMaOpenApiService {
1515

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

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

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

5251
/**
5352
* 使用AppSecret重置 API 调用次数
54-
* HTTP调用:https://api.weixin.qq.com/cgi-bin/clear_quota/v2
5553
*
5654
* @return 是否成功
5755
* @throws WxErrorException 微信异常

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaOpenApiServiceImpl.java

+2-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
public class WxMaOpenApiServiceImpl implements WxMaOpenApiService {
2424
private final WxMaService wxMaService;
2525

26-
private static final String QUOTA = "quota";
2726
private static final String REQUEST = "request";
2827

2928

@@ -42,11 +41,7 @@ public WxMiniGetApiQuotaResult getApiQuota(String cgiPath) throws WxErrorExcepti
4241
params.addProperty("cgi_path", cgiPath);
4342
String responseContent = this.wxMaService.post(WxMaApiUrlConstants.OpenApi.GET_API_QUOTA, params.toString());
4443
parseErrorResponse(responseContent);
45-
JsonObject response = GsonParser.parse(responseContent);
46-
if (response.has(QUOTA)) {
47-
return WxMaGsonBuilder.create().fromJson(response.getAsJsonObject(QUOTA), WxMiniGetApiQuotaResult.class);
48-
}
49-
return null;
44+
return WxMaGsonBuilder.create().fromJson(GsonParser.parse(responseContent), WxMiniGetApiQuotaResult.class);
5045
}
5146

5247

@@ -58,7 +53,7 @@ public WxMiniGetRidInfoResult getRidInfo(String rid) throws WxErrorException {
5853
parseErrorResponse(responseContent);
5954
JsonObject response = GsonParser.parse(responseContent);
6055
if (response.has(REQUEST)) {
61-
return WxMaGsonBuilder.create().fromJson(response.getAsJsonObject(QUOTA), WxMiniGetRidInfoResult.class);
56+
return WxMaGsonBuilder.create().fromJson(response.getAsJsonObject(REQUEST), WxMiniGetRidInfoResult.class);
6257
}
6358
return null;
6459
}

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/openapi/WxMiniGetApiQuotaResult.java

+63-7
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,73 @@
1212
@Data
1313
public class WxMiniGetApiQuotaResult {
1414

15+
16+
/**
17+
* quota详情
18+
*/
19+
private WxMiniGetApiQuotaDetail quota;
20+
/**
21+
* 普通调用频率限制
22+
*/
23+
private WxMiniGetApiQuotaRateLimit rateLimit;
24+
/**
25+
* 代调用频率限制
26+
*/
27+
private WxMiniGetApiQuotaComponentRateLimit componentRateLimit;
28+
29+
1530
/**
16-
* 当天该账号可调用该接口的次数
31+
* quota详情
1732
*/
18-
@SerializedName("daily_limit")
19-
private Integer dailyLimit;
33+
@Data
34+
private static class WxMiniGetApiQuotaDetail {
35+
/**
36+
* 当天该账号可调用该接口的次数
37+
*/
38+
@SerializedName("daily_limit")
39+
private Long dailyLimit;
40+
/**
41+
* 当天已经调用的次数
42+
*/
43+
private Long used;
44+
/**
45+
* 当天剩余调用次数
46+
*/
47+
private Long remain;
48+
}
49+
2050
/**
21-
* 当天已经调用的次数
51+
* 普通调用频率限制
2252
*/
23-
private Integer used;
53+
@Data
54+
private static class WxMiniGetApiQuotaRateLimit {
55+
/**
56+
* 周期内可调用数量,单位 次
57+
*/
58+
@SerializedName("call_count")
59+
private Long callCount;
60+
/**
61+
* 更新周期,单位 秒
62+
*/
63+
@SerializedName("refresh_second")
64+
private Long refreshSecond;
65+
}
66+
2467
/**
25-
* 当天剩余调用次数
68+
* 代调用频率限制
2669
*/
27-
private Integer remain;
70+
@Data
71+
private static class WxMiniGetApiQuotaComponentRateLimit {
72+
/**
73+
* 周期内可调用数量,单位 次
74+
*/
75+
@SerializedName("call_count")
76+
private Long callCount;
77+
/**
78+
* 更新周期,单位 秒
79+
*/
80+
@SerializedName("refresh_second")
81+
private Long refreshSecond;
82+
}
83+
2884
}

weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaOpenApiServiceImplTest.java

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import cn.binarywang.wx.miniapp.api.WxMaService;
44
import cn.binarywang.wx.miniapp.bean.openapi.WxMiniGetApiQuotaResult;
5+
import cn.binarywang.wx.miniapp.bean.openapi.WxMiniGetRidInfoResult;
56
import cn.binarywang.wx.miniapp.test.ApiTestModule;
67
import com.google.gson.Gson;
78
import com.google.inject.Inject;
@@ -39,6 +40,15 @@ public void getApiQuota() throws WxErrorException {
3940
assertNotNull(apiQuota);
4041
System.out.println(new Gson().toJson(apiQuota));
4142
}
43+
44+
@Test
45+
public void getApiQuotaInfo() throws WxErrorException {
46+
String rid = "658723fa-2d3a0086-64bc7215";
47+
final WxMiniGetRidInfoResult ridInfo = wxMaService.getWxMaOpenApiService().getRidInfo(rid);
48+
assertNotNull(ridInfo);
49+
System.out.println(new Gson().toJson(ridInfo));
50+
}
51+
4252
@Test
4353
public void clearQuotaByAppSecret() throws WxErrorException {
4454
final boolean result = wxMaService.getWxMaOpenApiService().clearQuotaByAppSecret();

0 commit comments

Comments
 (0)