/**
* 模拟HTTP发送请求
* @param $URL
* @param $data
* @return mixed
*/
function callInterfaceCommon($URL,$data,$method="POST")
{
$ch = curl_init();
//判断ssl连接方式
if (stripos($URL, 'https://') !== false) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSLVERSION, 1);
}
$connttime = 500; //连接等待时间500毫秒
$timeout = 15000;//超时时间15秒
$querystring = "";
if (is_array($data)) {
// Change data in to postable data
foreach ($data as $key => $val) {
if (is_array($val)) {
foreach ($val as $val2) {
$querystring .= urlencode($key) . '=' . urlencode($val2) . '&';
}
} else {
$querystring .= urlencode($key) . '=' . urlencode($val) . '&';
}
}
$querystring = substr($querystring, 0, -1); // Eliminate unnecessary &
} else {
$querystring = $data;
}
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//反馈信息
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); //http 1.1版本
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, $connttime);//连接等待时间
curl_setopt($ch, CURLOPT_TIMEOUT_MS, $timeout);//超时时间
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $querystring);
$file_contents = curl_exec($ch);//获得返回值
$status = curl_getinfo($ch);
curl_close($ch);
return $file_contents;
}
请求方式是POST 可以自己改下