我们做东西的时候常常会调用各种接口,如短信API,快递API等,那们你一定会用到下面这个方法。
function curt_url($url){
$ch = curl_init();$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$contents = curl_exec($ch);
curl_close($ch);
$result = json_decode($contents,true);
return $result;
}