详细请教一下 AccessToken 过期失效的问题!

企业微信 文章 2021-04-01 10:41 144 0 全屏看文

详细请教一下 AccessToken 过期失效的问题!Please tell me more about the expiration of AccessToken!

详细请教一下 AccessToken 过期失效的问题!


请问一下:获取AccessToken以后,是从获取时间开始起,7200秒过期吗?

7200秒之内,获取的 AccessToken 值都是一样的。

还是从他变化值开始周期过期时间?


如果是这样自获取时间起,我就计算好时间即可6800秒更新一次 AccessToken。











获取AccessToken

AccessToken是企业号的全局唯一票据,调用接口时需携带AccessToken。

AccessToken需要用CorpIDSecret来换取,不同的Secret会返回不同的AccessToken。正常情况下AccessToken有效期为7200秒,有效期内重复获取返回相同结果。access_token至少保留512字节的存储空间。企业号可能会出于运营需要,提前使accesstoken失效,企业开发者也应实现accesstoken失效时重试获取的逻辑。

  • 请求说明

Https请求方式: GET

https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=id&corpsecret=secrect

  • 参数说明

参数必须说明corpid是企业Idcorpsecret是管理组的凭证密钥

Excuse me: after obtaining the accesstoken, does it expire in 7200 seconds from the acquisition time? Within 7200 seconds, the accesstoken values obtained are the same. Or does it start from its change value and cycle expiration time? If this is the case, I will calculate the time from the acquisition time, that is, I can update the accesstoken every 6800 seconds. Get accesstoken. Accesstoken is the globally unique bill of the enterprise number. You need to carry the accesstoken when calling the interface. Accesstoken needs to be exchanged with Corpid and secret. Different secrets will return different accesstoken. Under normal circumstances, the validity period of accesstoken is 7200 seconds, and the same result is returned by repeated acquisition within the validity period. access_ The token reserves at least 512 bytes of storage space. The enterprise number may make the accesstoken invalid in advance for operational needs, and the enterprise developers should also implement the logic of retrial when the accesstoken fails. Request description HTTP request method: get https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=id&corpsecret=secrect Parameter description the parameter must specify that Corpid is the enterprise, and idcorpsecret is the certificate key of the management group

回答:

崔直宏:

https://developers.weixin.qq.com/community/develop/article/doc/000e42bdab83c0cbd95b1556656013

可以看一下我总结的access_token使用方法,顺便附带了源码。我的方式是不刻意关心多久过期,而是主要关心调用业务接口失败时更新access_token,并重新调用业务接口。

青寒:

如果是这样自获取时间起,我就计算好时间即可6800秒更新一次 AccessToken。

可以。

天子:

我缓存的 AccessToken 在使用之前,有没有什么办法,能验证一下,它是否已过期呢?


MORNINGSTART:wx.checkSession  检查登录态是否过期

-EOF-