1. 程式人生 > >CURLOPT_HEADER 控制是否返回請求頭資訊

CURLOPT_HEADER 控制是否返回請求頭資訊

微信請求並儲存access_token的一段程式碼

$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);//設定為0、1控制是否返回請求頭資訊
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);//這個是重點。
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
$wx_access_token = curl_exec($curl);
curl_close($curl);
$wx_json = json_decode($wx_access_token,TRUE);
$count_json = count($wx_json);
$access_token = $wx_json['access_token'];
$expires_in = $wx_json['expires_in'];
$token = array('access_token' => $access_token, 'expires_in'=>$expires_in, 'CreaTime'=>$currentTime); 
$collection->remove();
$result = $collection->insert($token);