一.呼叫第三方介面
/*
* $url 介面url string
* $type 請求型別 string
* $res 返回資料 string
* $date 資料 string
*/
function https_request($url,$type="get",$res="json",$data = ``){
//1.初始化curl
$curl = curl_init();
//2.設定curl的引數
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,2);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
if ($type == "post"){
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
//3.採集
$output = curl_exec($curl);
//4.關閉
curl_close($curl);
if ($res == `json`) {
return json_decode($output,true);
}
}