300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 微信接口请求次数_公众号API接口调用次数清零

微信接口请求次数_公众号API接口调用次数清零

时间:2018-11-28 19:48:47

相关推荐

微信接口请求次数_公众号API接口调用次数清零

最近在做微信公众号开发,过程中遇到了下面的问题:{"errcode":45009,"errmsg":"reach max api daily quota limit hint: [_1qXIa02861466]"}

package com.zkdx.hangul_service.test;

import com.alibaba.fastjson.JSON;

import net.sf.json.JSONObject;

import mons.httpclient.HttpStatus;

import org.apache.http.HttpEntity;

import org.apache.http.client.config.RequestConfig;

import org.apache.http.client.methods.CloseableHttpResponse;

import org.apache.http.client.methods.HttpPost;

import org.apache.http.entity.StringEntity;

import org.apache.http.impl.client.CloseableHttpClient;

import org.apache.http.impl.client.HttpClients;

import org.apache.http.protocol.BasicHttpContext;

import org.apache.http.util.EntityUtils;

import java.io.IOException;

import java.util.HashMap;

import java.util.Map;

public class ResetWechatAPICall {

private static JSONObject sendPost(String accessToken,String appid) {

String url = "https://api./cgi-bin/clear_quota?access_token=" + accessToken;

net.sf.json.JSONObject jsonObject = null;

//0.准备好json请求参数

Map paramMap = new HashMap();

paramMap.put("appid", appid);

Object data = com.alibaba.fastjson.JSON.toJSON(paramMap);

//1.生成一个请求

HttpPost httpPost = new HttpPost(url);

//2.配置请求属性

//2.1 设置请求超时时间

RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(100000).setConnectTimeout(100000).build();

httpPost.setConfig(requestConfig);

//2.2 设置数据传输格式-json

httpPost.addHeader("Content-Type", "application/json");

//2.3 设置请求参数

StringEntity requestEntity = new StringEntity(JSON.toJSONString(data), "utf-8");

httpPost.setEntity(requestEntity);

//3.发起请求,获取响应信息

//3.1 创建httpClient

CloseableHttpClient httpClient = HttpClients.createDefault();

CloseableHttpResponse response = null;

try {

//4. 发起请求,获取响应信息

response = httpClient.execute(httpPost, new BasicHttpContext());

// 请求成功

if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) {

// 5. 取得请求内容

HttpEntity entity = response.getEntity();

if (entity != null) {

String result = EntityUtils.toString(entity, "UTF-8");

jsonObject = net.sf.json.JSONObject.fromObject(result);

}

if (entity != null) {

entity.consumeContent();

}

}

} catch (IOException e) {

e.printStackTrace();

} finally {

if (response != null) {

try {

// 6. 释放资源

response.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

try {

if (jsonObject.has("errcode") && jsonObject.get("errcode").equals("48006")) {

throw new Exception("forbid to clear quota because of reaching the limit");

}

} catch (Exception e) {

e.printStackTrace();

}

return jsonObject;

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。