/**
* @param $url
* @param array $param
* @param string $action
* @return mixed|string
* 发起外部请求
*/
function com_sendRequest($url,$param = array(),$action = 'POST'){
// exit;
$paramString = '';
if(!empty($param)){
$endValue = end($param);
foreach ($param as $k=>$v){
$paramString .= $k.'='.urlencode($v);
if($v !== $endValue){
$paramString .= '&';
}
}
}
if($action == 'GET'){
if(function_exists('file_get_contents'))
{
$file_contents = file_get_contents($url.'?'.$paramString);
}
else
{
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, $url.'?'.$paramString);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
}
}else{//POST
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_POST,1);
if(!empty($paramString)){
curl_setopt($ch,CURLOPT_POSTFIELDS,$paramString);
}
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
// dump($file_contents);
curl_close($ch);
}
return json_decode($file_contents,true,512,JSON_BIGINT_AS_STRING);
}