如何用PHP请求api
<?php function curls($url , $data=[]){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); if($data){ curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); } $output = curl_exec($ch); curl_close($ch); return $output; } //get请求 curls('http://www.baidu.com/'); //get带参数请求 curls('http://www.baidu.com?id=1'); //post请求 curls('http://www.baidu.com/',[]); //post带参数请求 curls('http://www.baidu.com/',['id'=>1]);