File tree Expand file tree Collapse file tree
main/java/cn/binarywang/wx/miniapp
test/java/cn/binarywang/wx/miniapp/api/impl Expand file tree Collapse file tree Original file line number Diff line number Diff 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 微信异常
Original file line number Diff line number Diff line change 2323public 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 }
Original file line number Diff line number Diff line change 1212@ Data
1313public 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}
Original file line number Diff line number Diff line change 22
33import cn .binarywang .wx .miniapp .api .WxMaService ;
44import cn .binarywang .wx .miniapp .bean .openapi .WxMiniGetApiQuotaResult ;
5+ import cn .binarywang .wx .miniapp .bean .openapi .WxMiniGetRidInfoResult ;
56import cn .binarywang .wx .miniapp .test .ApiTestModule ;
67import com .google .gson .Gson ;
78import 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 ();
You can’t perform that action at this time.
0 commit comments