/** * @desc 接口請求處理 * @date 2017/5/19 11:39 * @param [$url請求的接口地址,$way為false為get請求,true為post請求] * @author 1245049149@qq.com * @return [array $data] */ public function getApiData($url,$way='false'){ $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_POST, $way); //post提交方式 //執行並獲取HTML文檔內容 $output = curl_exec($ch); //釋放curl句柄 curl_close($ch); //轉換json數據 $data = json_decode($output,true); //返回數據 return $data; }
對於url地址是否有效還可以優化,最近被古老的原生框架,搞的不要不要的,我滴天。。。