WeChat public platform to obtain access_token
Get access_token
access_token is the globally unique interface calling credential for the public account. The public account needs to use access_token when calling each interface. Developers need to store it properly. At least 512 characters of space must be reserved for access_token storage. The validity period of access_token is currently 2 hours and needs to be refreshed regularly. Repeated acquisition will cause the last access_token to become invalid.
Instructions on the use and generation of access_token required for API calls on the public platform:
1、为了保密appsecrect,第三方需要一个access_token获取和刷新的中控服务器。而其他业务逻辑服务器所使用的access_token均来自于该中控服务器,不应该各自去刷新,否则会造成access_token覆盖而影响业务; 2、目前access_token的有效期通过返回的expire_in来传达,目前是7200秒之内的值。中控服务器需要根据这个有效时间提前去刷新新access_token。在刷新过程中,中控服务器对外输出的依然是老access_token,此时公众平台后台会保证在刷新短时间内,新老access_token都可用,这保证了第三方业务的平滑过渡; 3、access_token的有效时间可能会在未来有调整,所以中控服务器不仅需要内部定时主动刷新,还需要提供被动刷新access_token的接口,这样便于业务服务器在API调用获知access_token已超时的情况下,可以触发access_token的刷新流程。
The public account can use AppID and AppSecret to call this Interface to obtain access_token. AppID and AppSecret can be obtained from the official website of WeChat public platform - development page (you need to have become a developer and the account has no abnormal status). Note that the https protocol must be used when calling all WeChat interfaces. If the third party does not use the central control server, but chooses each business logic point to refresh the access_token separately, conflicts may occur, leading to service instability.
Interface call request description
http请求方式: GET grant_type=client_credential&appid=APPID&secret=APPSECRET
Parameter description
Return instructions
Under normal circumstances, WeChat will return the following JSON data packet to the public account:
{"access_token":"ACCESS_TOKEN","expires_in":7200} |
When an error occurs, WeChat will return error code and other information. The JSON data packet example is as follows (this example is an invalid AppID error):
{"errcode":40013,"errmsg":"invalid appid"} |
Use web debugging tools to debug this interface