/**
* CURL模拟HTTP请求
* @param string $url
* @param string $type
* @param array $data
* @return array|boolean
*/
function curlData($url, $type = 'GET', $data = array()){
$ch = curl_init();
if(empty($url) || ! $ch) return false;
if(strtoupper($type) == 'POST'){
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
}else{
$url .= '?' . http_build_query($data);
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($ch);
//$err_no = curl_errno($ch);
//$err_info = curl_getinfo($ch);
curl_close($ch);
return $result;
}
- function curlrequest($url,$data,$method='post'){
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
-
- curl_setopt($ch,CURLOPT_HTTPHEADER,array("X-HTTP-Method-Override: $method"));
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- $document = curl_exec($ch);
-
- curl_close($ch);
-
- return $document;
- }
-
- $url = 'www.wxh.com/3.php';
- $data = "m=1&c=2&jaingxi=67";
- $return = curlrequest($url, $data, 'put');
- var_dump($return);
/**
* Func 生成短URL
* @param string $url 源路径地址
* @param int $type 1-7 生成短url的域名 2是t.cn
*/
function GetShortUrl ($url,$type = 2){
$path = 'http://www.ft12.com/create.php?m=index&a=urlCreate';//生成短连接网站
$data['url'] = $url;
$data['type'] = $type;
$content = curlData($path,'post' , $data);
if($content){
$result = json_decode($content, true);
if($result['status'] == 1){
return $result['list'];
}else{
return false;
}
}
}