鍍金池/ 問答/Java  PHP  HTML/ PHP獲取微信公眾號(hào)access_token的問題

PHP獲取微信公眾號(hào)access_token的問題

PHP為什么用curl來獲取access_token,顯示為空,而用file_get_contents來獲取 access_token就能顯示出來

$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);

回答
編輯回答
玄鳥

你的curl代碼發(fā)的是post請(qǐng)求,file_get_contents發(fā)的是get請(qǐng)求。這個(gè)微信接口應(yīng)該是get請(qǐng)求

2018年1月17日 01:16
編輯回答
笑浮塵
curl_setopt($ch, CURLOPT_POST, 1);

你curl用的是post,access_token是get

2017年2月10日 21:54