get請求是最簡單的請求,不過要注意自己的請求是http請求還是https的請求,因為https請求時要關閉SSL驗證,不然驗證通不過,沒有辦法請求到數據。
GET請求的參數
get傳遞參數和正常請求url傳遞參數的方式一樣
1 function get_info($card){ 2 $url ="http://www.sdt.com/api/White/CardInfo?cardNo=".$bank_card; 3 $ch = curl_init(); 4 //設置選項,包括URL 5 curl_setopt($ch, CURLOPT_URL, $url); 6 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 7 curl_setopt($ch, CURLOPT_HEADER, 0); 8 //執行並獲取HTML文檔內容 9 $output = curl_exec($ch); 10 //釋放curl句柄 11 curl_close($ch); 12 return $output; 13 }
HTTPS請求時要注意SSL驗證
function get_bankcard_info($bank_card){ $url="https://ccdcapi.alipay.com/validateAndCacheCardInfo.json?_input_charset=utf-8&cardNo=".$bank_card."&cardBinCheck=true"; $ch = curl_init(); //設置選項,包括URL curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//繞過ssl驗證 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //執行並獲取HTML文檔內容 $output = curl_exec($ch); //釋放curl句柄 curl_close($ch); return $output; }