Home > Article > Backend Development > Development example of obtaining WeChat access_token_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
4 11 12 |
<🎜> <🎜> <🎜>define("APPID", "your appid");<🎜> <🎜>define("APPSECRET", "your 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); //Get the file content or get the content of the network request<🎜> <🎜>//echo $res;<🎜> <🎜>$result = json_decode($res, true); //Accept a JSON format string and convert it into a PHP variable<🎜> <🎜>$access_token = $result['access_token'];<🎜> <🎜>echo $access_token;<🎜> <🎜> <🎜> <🎜>php> |