微信公众号开发者模式 定时任务 获取ACCESS_TOKEN

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/sinat_15114467/article/details/50635244
            Timer timer = new Timer();
            myTask = new MyTask();
            timer.schedule(myTask, 0, 1000 * 60 * 60);

/***
 * 一天有获取2000次的限制 ,设置1小时获取一次AccessToken防止超出请求限制
 * 
 * @author wWX323797
 *
 */

public class MyTask extends TimerTask {

    public static WechatUtil wechatUtil = new WechatUtil();
    public static JSONObject access_token_json;
    public static String ACCESS_TOKEN = null;

    @Override
    public void run() {
        // TODO Auto-generated method stub      
        access_token_json = wechatUtil.getAccess_token();
        ACCESS_TOKEN = access_token_json.getString("access_token");     
    }
}
    public JSONObject getAccess_token() {
        try {
            URL url = new URL("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appID + "&secret=" + appSecret + "");
            jsonObject = getFromWechat(url);// 发送http请求到微信端获取返回值

        } catch (Exception e) {
            e.printStackTrace();
        }
        return jsonObject;
    }
展开阅读全文

没有更多推荐了,返回首页