PHP跨越调用接口

// 应用公共文件
/**
 * 创建并并初始化curl
 * GET方式传值
 * @param string $url
 * @return resouce
 */
function getCurl($url = '')
{
$defaults = array(
CURLOPT_HEADER => 0,
CURLOPT_URL => $url,
CURLOPT_FRESH_CONNECT => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FORBID_REUSE => 1,
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false
);
$ch = curl_init();
curl_setopt_array($ch, ($defaults));
if( ! $result = curl_exec($ch))
{
trigger_error(curl_error($ch));
}
curl_close($ch);
return $result;
}
/**
 * 创建并并初始化curl
 * POST方式传值

 * @param string $url

 * @param array $post

 * @return resouce
 */
function postCurl(array $post = NULL, $url = '')
{
$defaults = array(
CURLOPT_POST => 1,
CURLOPT_HEADER => 0,
CURLOPT_URL => $url,
CURLOPT_FRESH_CONNECT => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FORBID_REUSE => 1,
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_POSTFIELDS => http_build_query($post)
);
$ch = curl_init();
curl_setopt_array($ch, ($defaults));
if( ! $result = curl_exec($ch))
{
        trigger_error(curl_error($ch));
}
curl_close($ch);
return $result;
}

你可能感兴趣的:(学习笔记)