新增接口调用次数清零接口

This commit is contained in:
jinyu 2016-05-30 16:45:29 +08:00
parent d518eef5f8
commit ecdaf72069
5 changed files with 57 additions and 2 deletions

View File

@ -705,4 +705,12 @@
* 2016-05-28
+ 重构Cache实现
+ 重构Cache实现
* 2016-05-30
+ 优化Weixin4jSettings
+ 优化PayOldApi
+ weixin4j-mp:新增接口调用次数清零接口

View File

@ -1485,6 +1485,22 @@ public class WeixinProxy {
return helperApi.getWechatServerIp();
}
/**
* 接口调用次数调用清零公众号调用接口并不是无限制的为了防止公众号的程序错误而引发微信服务器负载异常默认情况下
* 每个公众号调用接口都不能超过一定限制
* 当超过一定限制时调用对应接口会收到{"errcode":45009,"errmsg":"api freq out of limit"
* }错误返回码
*
* @see <a
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433744592&token=&lang=zh_CN">接口清零</a>
* @see com.foxinmy.weixin4j.mp.api.HelperApi
* @return 操作结果
* @throws WeixinException
*/
public JsonResult clearQuota() throws WeixinException {
return helperApi.clearQuota(getWeixinAccount().getId());
}
/**
* 获取公众号当前使用的自定义菜单的配置如果公众号是通过API调用设置的菜单则返回菜单的开发配置
* 而如果公众号是在公众平台官网通过网站功能发布菜单则本接口返回运营者设置的菜单配置

View File

@ -10,6 +10,7 @@ import com.alibaba.fastjson.JSONPath;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.parser.deserializer.ExtraProcessor;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.http.weixin.JsonResult;
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
import com.foxinmy.weixin4j.model.Button;
import com.foxinmy.weixin4j.model.Token;
@ -105,7 +106,7 @@ public class HelperApi extends MpApi {
* 获取公众号当前使用的自定义菜单的配置如果公众号是通过API调用设置的菜单则返回菜单的开发配置
* 而如果公众号是在公众平台官网通过网站功能发布菜单则本接口返回运营者设置的菜单配置
*
* @return 菜单集合
* @return 菜单配置信息
* @see {@link MenuApi#getMenu()}
* @see <a
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1434698695&token=&lang=zh_CN">获取自定义菜单配置</a>
@ -176,6 +177,7 @@ public class HelperApi extends MpApi {
* @see com.foxinmy.weixin4j.mp.model.AutoReplySetting
* @see <a
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433751299&token=&lang=zh_CN">获取自动回复规则</a>
* @return 自定义回复配置信息
* @throws WeixinException
*/
public AutoReplySetting getAutoReplySetting() throws WeixinException {
@ -221,4 +223,26 @@ public class HelperApi extends MpApi {
replySetting.setKeywordReplyList(ruleList);
return replySetting;
}
/**
* 接口调用次数调用清零公众号调用接口并不是无限制的为了防止公众号的程序错误而引发微信服务器负载异常默认情况下
* 每个公众号调用接口都不能超过一定限制
* 当超过一定限制时调用对应接口会收到{"errcode":45009,"errmsg":"api freq out of limit"
* }错误返回码
*
* @param appId
* 公众号ID
* @see <a
* href="https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433744592&token=&lang=zh_CN">接口清零</a>
* @return 操作结果
* @throws WeixinException
*/
public JsonResult clearQuota(String appId) throws WeixinException {
String clearquota_uri = getRequestUri("clearquota_uri");
String body = String.format("{\"appid\":\"%s\"}", appId);
WeixinResponse response = weixinExecutor.post(
String.format(clearquota_uri, tokenManager.getAccessToken()),
body);
return response.getAsJsonResult();
}
}

View File

@ -124,6 +124,8 @@ template_send_uri={api_cgi_url}/message/template/send?access_token=%s
semantic_uri={api_base_url}/semantic/semproxy/search?access_token=%s
# \u5fae\u4fe1\u670d\u52a1\u5730\u5740
getcallbackip_uri={api_cgi_url}/getcallbackip?access_token=%s
# \u63a5\u53e3\u8c03\u7528\u6b21\u6570\u6e05\u96f6
clearquota_uri={api_cgi_url}/clear_quota?access_token=%s
# \u6570\u636e\u7edf\u8ba1
datacube_uri={api_base_url}/datacube/%s?access_token=%s

View File

@ -41,4 +41,9 @@ public class HelperTest extends TokenTest {
public void getAutoReplySetting() throws WeixinException {
System.err.println(helperApi.getAutoReplySetting());
}
@Test
public void clearQuota() throws WeixinException {
System.err.println(helperApi.clearQuota(settings.getAccount().getId()));
}
}