Home > Article > Backend Development > WeChat access_token acquisition development example, access_token example_PHP tutorial
Overview
Access_token is the globally unique ticket of 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.
Acquisition of access_token
<?php define("APPID", "您的appid"); define("APPSECRET", "您的appsecret "); $token_access_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . APPID . "&secret=" . APPSECRET; $res = file_get_contents($token_access_url); //获取文件内容或获取网络请求的内容 //echo $res; $result = json_decode($res, true); //接受一个 JSON 格式的字符串并且把它转换为 PHP 变量 $access_token = $result['access_token']; echo $access_token; php>
The above is the entire content of this article, I hope you all like it.