From 20825922ce42788896546d4e0385dbadc48423c5 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Wed, 22 Nov 2017 23:15:18 +0800 Subject: [PATCH] =?UTF-8?q?#367=20=E5=A2=9E=E5=8A=A0=E5=AF=B9api=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E6=AC=A1=E6=95=B0=E6=B8=85=E9=9B=B6=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/chanjar/weixin/mp/api/WxMpService.java | 25 +++- .../mp/api/impl/WxMpServiceAbstractImpl.java | 7 + .../mp/api/impl/WxMpServiceImplTest.java | 125 +----------------- 3 files changed, 32 insertions(+), 125 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java index 914c902d..0dd5a66b 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java @@ -5,8 +5,11 @@ import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor; import me.chanjar.weixin.common.util.http.RequestExecutor; import me.chanjar.weixin.common.util.http.RequestHttp; -import me.chanjar.weixin.mp.bean.*; -import me.chanjar.weixin.mp.bean.result.*; +import me.chanjar.weixin.mp.bean.WxMpSemanticQuery; +import me.chanjar.weixin.mp.bean.result.WxMpCurrentAutoReplyInfo; +import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; +import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult; +import me.chanjar.weixin.mp.bean.result.WxMpUser; /** * 微信API的Service @@ -62,6 +65,11 @@ public interface WxMpService { */ String GET_CURRENT_AUTOREPLY_INFO_URL = "https://api.weixin.qq.com/cgi-bin/get_current_autoreply_info"; + /** + * 公众号调用或第三方平台帮公众号调用对公众号的所有api调用(包括第三方帮其调用)次数进行清零 + */ + String CLEAR_QUOTA_URL = "https://api.weixin.qq.com/cgi-bin/clear_quota"; + /** *
    * 验证消息的确来自微信服务器
@@ -219,6 +227,18 @@ public interface WxMpService {
    */
   WxMpCurrentAutoReplyInfo getCurrentAutoReplyInfo() throws WxErrorException;
 
+  /**
+   * 
+   *  公众号调用或第三方平台帮公众号调用对公众号的所有api调用(包括第三方帮其调用)次数进行清零:
+   *  HTTP调用:https://api.weixin.qq.com/cgi-bin/clear_quota?access_token=ACCESS_TOKEN
+   *  接口文档地址:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433744592
+   *
+   * 
+ * + * @param appid 公众号的APPID + */ + void clearQuota(String appid) throws WxErrorException; + /** * 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的GET请求 */ @@ -376,6 +396,7 @@ public interface WxMpService { /** * 返回群发消息相关接口方法的实现类对象,以方便调用其各个接口 + * * @return WxMpMassMessageService */ WxMpMassMessageService getMassMessageService(); diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceAbstractImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceAbstractImpl.java index 420cb252..54b4c360 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceAbstractImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceAbstractImpl.java @@ -207,6 +207,13 @@ public abstract class WxMpServiceAbstractImpl implements WxMpService, Requ return WxMpCurrentAutoReplyInfo.fromJson(this.get(GET_CURRENT_AUTOREPLY_INFO_URL, null)); } + @Override + public void clearQuota(String appid) throws WxErrorException { + JsonObject o = new JsonObject(); + o.addProperty("appid", appid); + this.post(CLEAR_QUOTA_URL, o.toString()); + } + @Override public String get(String url, String queryParam) throws WxErrorException { return execute(SimpleGetRequestExecutor.create(this), url, queryParam); diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java index 9cb9e1d1..89060a6e 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java @@ -15,7 +15,6 @@ import static org.testng.Assert.*; @Test @Guice(modules = ApiTestModule.class) public class WxMpServiceImplTest { - @Inject private WxMpService wxService; @@ -28,88 +27,8 @@ public class WxMpServiceImplTest { } @Test - public void testCheckSignature() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testGetAccessToken() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testGetAccessTokenBoolean() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testGetJsapiTicket() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testGetJsapiTicketBoolean() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testCreateJsapiSignature() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testCustomMessageSend() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testMassNewsUpload() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testMassVideoUpload() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testMassGroupMessageSend() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testMassOpenIdsMessageSend() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testMassMessagePreview() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testShortUrl() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testSetIndustry() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testGetIndustry() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testSemanticQuery() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testOauth2buildAuthorizationUrl() { - Assert.fail("Not yet implemented"); + public void testClearQuota() throws WxErrorException { + this.wxService.clearQuota(wxService.getWxMpConfigStorage().getAppId()); } @Test @@ -121,44 +40,4 @@ public class WxMpServiceImplTest { System.out.println(qrConnectUrl); } - @Test - public void testOauth2getAccessToken() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testOauth2refreshAccessToken() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testOauth2getUserInfo() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testOauth2validateAccessToken() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testGetCallbackIP() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testGet() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testPost() { - Assert.fail("Not yet implemented"); - } - - @Test - public void testExecute() { - Assert.fail("Not yet implemented"); - } - }