Home >Backend Development >PHP Tutorial >Analysis of steps to obtain WeChat public account access_token using PHP+cURL
This time I will bring you PHP Step analysis of cURL to obtain WeChat public account access_token, PHP cURL to obtain WeChat public account access_tokenNotesWhat are the practical cases, one Get up and take a look.
1. To develop a WeChat public account, you must first obtain the access_token. Before running the code, add the server IP to the whitelist in the developer settings
public function index(){ $appId = 'wxd0e50fe967dccccc'; $appSecret = 'd7f6be12ce41b60ss0f45054';//虚拟的,不要用 $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appId."&secret=".$appSecret; $ch = curl_init();//初始化curl curl_setopt($ch, CURLOPT_URL,$url); //要访问的地址 curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//跳过证书验证 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在 $data = json_decode(curl_exec($ch)); if(curl_errno($ch)){ var_dump(curl_error($ch)); //若错误打印错误信息 } var_dump($data); //打印信息 curl_close($ch);//关闭curl }
2. Obtain 2 access_tokens Valid within hours
# I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!
Recommended reading:
PHP performance testing tool xhprof practical case analysis
Detailed explanation of the steps for PHP to use file_get_contents to send http requests
The above is the detailed content of Analysis of steps to obtain WeChat public account access_token using PHP+cURL. For more information, please follow other related articles on the PHP Chinese website!