Access Token
In the development of WeChat public platform interfaces, Access Token occupies a very important position, which is equivalent to the key to enter various interfaces. Only with this key can you have the authority to call various other special interfaces.
Access_token is the globally unique ticket of the public account. The public account needs to use access_token when calling each interface. Under normal circumstances, the access_token is valid for 7200 seconds. Repeated acquisition will cause the last access_token to become invalid.
Official accounts can use AppID and AppSecret to call this interface to obtain access_token. AppID and AppSecret can be obtained in development mode (you need to be a developer and your account has no abnormal status). Note that the https protocol must be used when calling all WeChat interfaces.
Interface call request description
http request method: GET
https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
Parameter Description
|
Is it necessary
|
Description |
||||||||||||
grant_type |
Yes |
|
||||||||||||
appid
|
Yes
|
Unique credentials for third-party users
|
||||||||||||
secret |
Yes<span $appid</span> = "wxbad0b4x543aa0b5e"<span ; </span><span $appsecret</span> = "ed222a84da15cd24c4bdfa5d9adbabf2"<span ; </span><span $url</span> = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=<span $appid</span>&secret=<span $appsecret</span>"<span ; </span><span $ch</span> =<span curl_init(); curl_setopt(</span><span $ch</span>, CURLOPT_URL, <span $url</span><span ); curl_setopt(</span><span $ch</span>, CURLOPT_SSL_VERIFYPEER, <span FALSE</span><span ); curl_setopt(</span><span $ch</span>, CURLOPT_SSL_VERIFYHOST, <span FALSE</span><span ); curl_setopt(</span><span $ch</span>, CURLOPT_RETURNTRANSFER, 1<span ); </span><span $output</span> = curl_exec(<span $ch</span><span ); curl_close(</span><span $ch</span><span ); </span><span $jsoninfo</span> = json_decode(<span $output</span>, <span true</span><span ); </span><span $access_token</span> = <span $jsoninfo</span>["access_token"]; Copy after login |
Third-party user unique credential key, appsecret |
Return instructions
Under normal circumstances, WeChat will return the following JSON data packet to the official account:
{"access_token":"ACCESS_TOKEN","expires_in":7200}
Parameters |
Description |
access_token | Obtained voucher |
expires_in | Voucher validity time, unit: seconds |