NutzCN Logo
问答 微信如何重写刷新accesstoken方法
发布于 1758天前 作者 FirstXiaoMaGe 1935 次浏览 复制 上一个帖子 下一个帖子
标签:
protected synchronized void reflushAccessToken() {
        String url = String.format("%s/token?grant_type=client_credential&appid=%s&secret=%s", base, appid, appsecret);
        if (log.isDebugEnabled())
            log.debugf("ATS: reflush access_token send: %s", url);

        Response resp = Http.get(url);
        if (!resp.isOK())
            throw new IllegalArgumentException("reflushAccessToken FAIL , openid=" + openid);
        String str = resp.getContent();

        if (log.isDebugEnabled())
            log.debugf("ATS: reflush access_token done: %s", str);

        NutMap re = Json.fromJson(NutMap.class, str);
        String token = re.getString("access_token");
        int expires = re.getInt("expires_in") - 200;//微信默认超时为7200秒,此处设置稍微短一点
        accessTokenStore.save(token, expires, System.currentTimeMillis());
    }
1 回复

为啥要重写呢?

添加回复
请先登陆
回到顶部