The problem of obtaining the official account access_token of Wechat by PHP

Why does PHP use curl to get access_token, display is empty, while file_get_contents to get access_token can show

$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx3225919883125899&secret=5913d164a3660264868de68ca02884f2";
/*$ch = curl_init ();
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($ch);
curl_close ($ch) * /

)

$res = file_get_contents ($url);

Feb.27,2021

curl_setopt($ch, CURLOPT_POST, 1);

your curl uses post,access_token and get


your curl code sends a post request, and file_get_contents sends a get request. This Wechat interface should be a get request

Menu