Skip to content

Commit 2082592

Browse files
committed
#367 增加对api调用次数清零的接口
1 parent 81ebe1a commit 2082592

File tree

3 files changed

+32
-125
lines changed

3 files changed

+32
-125
lines changed

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
66
import me.chanjar.weixin.common.util.http.RequestExecutor;
77
import me.chanjar.weixin.common.util.http.RequestHttp;
8-
import me.chanjar.weixin.mp.bean.*;
9-
import me.chanjar.weixin.mp.bean.result.*;
8+
import me.chanjar.weixin.mp.bean.WxMpSemanticQuery;
9+
import me.chanjar.weixin.mp.bean.result.WxMpCurrentAutoReplyInfo;
10+
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
11+
import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult;
12+
import me.chanjar.weixin.mp.bean.result.WxMpUser;
1013

1114
/**
1215
* 微信API的Service
@@ -62,6 +65,11 @@ public interface WxMpService {
6265
*/
6366
String GET_CURRENT_AUTOREPLY_INFO_URL = "https://api.weixin.qq.com/cgi-bin/get_current_autoreply_info";
6467

68+
/**
69+
* 公众号调用或第三方平台帮公众号调用对公众号的所有api调用(包括第三方帮其调用)次数进行清零
70+
*/
71+
String CLEAR_QUOTA_URL = "https://api.weixin.qq.com/cgi-bin/clear_quota";
72+
6573
/**
6674
* <pre>
6775
* 验证消息的确来自微信服务器
@@ -219,6 +227,18 @@ public interface WxMpService {
219227
*/
220228
WxMpCurrentAutoReplyInfo getCurrentAutoReplyInfo() throws WxErrorException;
221229

230+
/**
231+
* <pre>
232+
* 公众号调用或第三方平台帮公众号调用对公众号的所有api调用(包括第三方帮其调用)次数进行清零:
233+
* HTTP调用:https://api.weixin.qq.com/cgi-bin/clear_quota?access_token=ACCESS_TOKEN
234+
* 接口文档地址:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433744592
235+
*
236+
* </pre>
237+
*
238+
* @param appid 公众号的APPID
239+
*/
240+
void clearQuota(String appid) throws WxErrorException;
241+
222242
/**
223243
* 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的GET请求
224244
*/
@@ -376,6 +396,7 @@ public interface WxMpService {
376396

377397
/**
378398
* 返回群发消息相关接口方法的实现类对象,以方便调用其各个接口
399+
*
379400
* @return WxMpMassMessageService
380401
*/
381402
WxMpMassMessageService getMassMessageService();

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceAbstractImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,13 @@ public WxMpCurrentAutoReplyInfo getCurrentAutoReplyInfo() throws WxErrorExceptio
207207
return WxMpCurrentAutoReplyInfo.fromJson(this.get(GET_CURRENT_AUTOREPLY_INFO_URL, null));
208208
}
209209

210+
@Override
211+
public void clearQuota(String appid) throws WxErrorException {
212+
JsonObject o = new JsonObject();
213+
o.addProperty("appid", appid);
214+
this.post(CLEAR_QUOTA_URL, o.toString());
215+
}
216+
210217
@Override
211218
public String get(String url, String queryParam) throws WxErrorException {
212219
return execute(SimpleGetRequestExecutor.create(this), url, queryParam);

weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java

Lines changed: 2 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
@Test
1616
@Guice(modules = ApiTestModule.class)
1717
public class WxMpServiceImplTest {
18-
1918
@Inject
2019
private WxMpService wxService;
2120

@@ -28,88 +27,8 @@ public void testGetCurrentAutoReplyInfo() throws WxErrorException {
2827
}
2928

3029
@Test
31-
public void testCheckSignature() {
32-
Assert.fail("Not yet implemented");
33-
}
34-
35-
@Test
36-
public void testGetAccessToken() {
37-
Assert.fail("Not yet implemented");
38-
}
39-
40-
@Test
41-
public void testGetAccessTokenBoolean() {
42-
Assert.fail("Not yet implemented");
43-
}
44-
45-
@Test
46-
public void testGetJsapiTicket() {
47-
Assert.fail("Not yet implemented");
48-
}
49-
50-
@Test
51-
public void testGetJsapiTicketBoolean() {
52-
Assert.fail("Not yet implemented");
53-
}
54-
55-
@Test
56-
public void testCreateJsapiSignature() {
57-
Assert.fail("Not yet implemented");
58-
}
59-
60-
@Test
61-
public void testCustomMessageSend() {
62-
Assert.fail("Not yet implemented");
63-
}
64-
65-
@Test
66-
public void testMassNewsUpload() {
67-
Assert.fail("Not yet implemented");
68-
}
69-
70-
@Test
71-
public void testMassVideoUpload() {
72-
Assert.fail("Not yet implemented");
73-
}
74-
75-
@Test
76-
public void testMassGroupMessageSend() {
77-
Assert.fail("Not yet implemented");
78-
}
79-
80-
@Test
81-
public void testMassOpenIdsMessageSend() {
82-
Assert.fail("Not yet implemented");
83-
}
84-
85-
@Test
86-
public void testMassMessagePreview() {
87-
Assert.fail("Not yet implemented");
88-
}
89-
90-
@Test
91-
public void testShortUrl() {
92-
Assert.fail("Not yet implemented");
93-
}
94-
95-
@Test
96-
public void testSetIndustry() {
97-
Assert.fail("Not yet implemented");
98-
}
99-
100-
@Test
101-
public void testGetIndustry() {
102-
Assert.fail("Not yet implemented");
103-
}
104-
105-
@Test
106-
public void testSemanticQuery() {
107-
Assert.fail("Not yet implemented");
108-
}
109-
110-
@Test
111-
public void testOauth2buildAuthorizationUrl() {
112-
Assert.fail("Not yet implemented");
30+
public void testClearQuota() throws WxErrorException {
31+
this.wxService.clearQuota(wxService.getWxMpConfigStorage().getAppId());
11332
}
11433

11534
@Test
@@ -121,44 +40,4 @@ public void testBuildQrConnectUrl() {
12140
System.out.println(qrConnectUrl);
12241
}
12342

124-
@Test
125-
public void testOauth2getAccessToken() {
126-
Assert.fail("Not yet implemented");
127-
}
128-
129-
@Test
130-
public void testOauth2refreshAccessToken() {
131-
Assert.fail("Not yet implemented");
132-
}
133-
134-
@Test
135-
public void testOauth2getUserInfo() {
136-
Assert.fail("Not yet implemented");
137-
}
138-
139-
@Test
140-
public void testOauth2validateAccessToken() {
141-
Assert.fail("Not yet implemented");
142-
}
143-
144-
@Test
145-
public void testGetCallbackIP() {
146-
Assert.fail("Not yet implemented");
147-
}
148-
149-
@Test
150-
public void testGet() {
151-
Assert.fail("Not yet implemented");
152-
}
153-
154-
@Test
155-
public void testPost() {
156-
Assert.fail("Not yet implemented");
157-
}
158-
159-
@Test
160-
public void testExecute() {
161-
Assert.fail("Not yet implemented");
162-
}
163-
16443
}

0 commit comments

Comments
 (0)