File tree 4 files changed +78
-19
lines changed
main/java/cn/binarywang/wx/miniapp
test/java/cn/binarywang/wx/miniapp/api/impl
4 files changed +78
-19
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,6 @@ public interface WxMaOpenApiService {
15
15
16
16
/**
17
17
* 本接口用于清空公众号/小程序/第三方平台等接口的每日调用接口次数
18
- * HTTP调用:https://api.weixin.qq.com/cgi-bin/clear_quota?access_token=ACCESS_TOKEN
19
18
*
20
19
* @return 是否成功
21
20
* @throws WxErrorException the wx error exception
@@ -28,18 +27,18 @@ public interface WxMaOpenApiService {
28
27
29
28
/**
30
29
* 查询API调用额度
31
- * HTTP调用:https://api.weixin.qq.com/cgi-bin/openapi/quota/get?access_token=ACCESS_TOKEN
32
30
*
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的报错;
34
33
* @return 额度详情
35
34
* @throws WxErrorException 微信异常
35
+ * @apiNote "/xxx/sns/xxx" 这类接口不支持使用该接口,会出现76022报错。
36
36
* @see <a href="https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/openApi-mgnt/getApiQuota.html">注意事项参考微信文档</a>
37
37
*/
38
38
WxMiniGetApiQuotaResult getApiQuota (String cgiPath ) throws WxErrorException ;
39
39
40
40
/**
41
41
* 查询rid信息
42
- * HTTP调用:https://api.weixin.qq.com/cgi-bin/openapi/rid/get?access_token=ACCESS_TOKEN
43
42
*
44
43
* @param rid 调用接口报错返回的rid
45
44
* @return 该rid对应的请求详情
@@ -51,7 +50,6 @@ public interface WxMaOpenApiService {
51
50
52
51
/**
53
52
* 使用AppSecret重置 API 调用次数
54
- * HTTP调用:https://api.weixin.qq.com/cgi-bin/clear_quota/v2
55
53
*
56
54
* @return 是否成功
57
55
* @throws WxErrorException 微信异常
Original file line number Diff line number Diff line change 23
23
public class WxMaOpenApiServiceImpl implements WxMaOpenApiService {
24
24
private final WxMaService wxMaService ;
25
25
26
- private static final String QUOTA = "quota" ;
27
26
private static final String REQUEST = "request" ;
28
27
29
28
@@ -42,11 +41,7 @@ public WxMiniGetApiQuotaResult getApiQuota(String cgiPath) throws WxErrorExcepti
42
41
params .addProperty ("cgi_path" , cgiPath );
43
42
String responseContent = this .wxMaService .post (WxMaApiUrlConstants .OpenApi .GET_API_QUOTA , params .toString ());
44
43
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 );
50
45
}
51
46
52
47
@@ -58,7 +53,7 @@ public WxMiniGetRidInfoResult getRidInfo(String rid) throws WxErrorException {
58
53
parseErrorResponse (responseContent );
59
54
JsonObject response = GsonParser .parse (responseContent );
60
55
if (response .has (REQUEST )) {
61
- return WxMaGsonBuilder .create ().fromJson (response .getAsJsonObject (QUOTA ), WxMiniGetRidInfoResult .class );
56
+ return WxMaGsonBuilder .create ().fromJson (response .getAsJsonObject (REQUEST ), WxMiniGetRidInfoResult .class );
62
57
}
63
58
return null ;
64
59
}
Original file line number Diff line number Diff line change 12
12
@ Data
13
13
public class WxMiniGetApiQuotaResult {
14
14
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
+
15
30
/**
16
- * 当天该账号可调用该接口的次数
31
+ * quota详情
17
32
*/
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
+
20
50
/**
21
- * 当天已经调用的次数
51
+ * 普通调用频率限制
22
52
*/
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
+
24
67
/**
25
- * 当天剩余调用次数
68
+ * 代调用频率限制
26
69
*/
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
+
28
84
}
Original file line number Diff line number Diff line change 2
2
3
3
import cn .binarywang .wx .miniapp .api .WxMaService ;
4
4
import cn .binarywang .wx .miniapp .bean .openapi .WxMiniGetApiQuotaResult ;
5
+ import cn .binarywang .wx .miniapp .bean .openapi .WxMiniGetRidInfoResult ;
5
6
import cn .binarywang .wx .miniapp .test .ApiTestModule ;
6
7
import com .google .gson .Gson ;
7
8
import com .google .inject .Inject ;
@@ -39,6 +40,15 @@ public void getApiQuota() throws WxErrorException {
39
40
assertNotNull (apiQuota );
40
41
System .out .println (new Gson ().toJson (apiQuota ));
41
42
}
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
+
42
52
@ Test
43
53
public void clearQuotaByAppSecret () throws WxErrorException {
44
54
final boolean result = wxMaService .getWxMaOpenApiService ().clearQuotaByAppSecret ();
You can’t perform that action at this time.
0 commit comments