Home > Backend Development > PHP Tutorial > ACCESS TOKEN_PHP Tutorial

ACCESS TOKEN_PHP Tutorial

WBOY
Release: 2016-07-13 17:17:29
Original
904 people have browsed it

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

参数

是否必须

说明

grant_type

获取access_token填写client_credential

appid

第三方用户唯一凭证

secret

第三方用户唯一凭证密钥,既appsecret

Parameters

Is it necessary

Description

grant_type

Yes

参数

说明

access_token

获取到的凭证

expires_in

凭证有效时间,单位:秒

Get access_token and fill in client_credential

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

access_token Obtained voucher
expires_in Voucher validity time, unit: seconds
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"}
Code implementation Special Instructions In OAuth2.0 authentication, we will see another Access Token, please pay attention to the difference. http://www.bkjia.com/PHPjc/626601.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/626601.htmlTechArticleAccess Token In the development of the WeChat public platform interface, Access Token occupies a very important position, which is equivalent to entering various A key to an interface. Only with this key can you call various other special features...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template