Bing美图抓取API代码

  • 2017-07-20
  • 0
  • 4
 function XCURL($url,$referer){
        $ip = mt_rand(1,255).".".mt_rand(1,255).".".mt_rand(1,255).".".mt_rand(1,255)."";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch,CURLOPT_HTTPHEADER,array("CLIENT-IP".$ip."", "X_FORWARD_FOR:".$ip."")); 
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
        curl_setopt($ch, CURLOPT_TIMEOUT,15);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
        curl_setopt($ch, CURLOPT_REFERER, $referer); 
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Encoding:gzip'));
        curl_setopt($ch, CURLOPT_ENCODING, "gzip");
        $result=curl_exec($ch);
        curl_close($ch);
        return $result;
    }
if(isset($_REQUEST['rand'])&&!empty($_REQUEST['rand'])&&$_REQUEST['rand']=='true'){
	$url='http://cn.bing.com/HPImageArchive.aspx?idx='.rand(0,6).'&n=1';
	}else{
		$url='http://cn.bing.com/HPImageArchive.aspx?idx=0&n=1';
	}
$referer=base64_decode('aHR0cHM6Ly93d3cueHNpY28uY24v');
$str=XCURL($url,$referer);
if(preg_match("/(.+?)<\/url>/ies",$str,$matches)){
	$imgurl='http://cn.bing.com'.$matches[1];
	}
if(isset($_REQUEST['size'])&&!empty($_REQUEST['size'])){
	if($_REQUEST['size']=='1920*1080'){
		$imgurl=str_replace("1366x768","1920x1080",$imgurl);
	}
}
if(isset($_REQUEST['type'])&&!empty($_REQUEST['type'])){
	$type=$_REQUEST['type'];
}else{
	$type='jpeg';
}
if($imgurl){
    header('Content-Type: image/'.$type);
	header(base64_decode('Q29weXJpZ2h0OiB3d3cueHNpY28uY24='));
	@ob_end_clean();
    @readfile($imgurl);
    @flush(); @ob_flush();
	exit();
	    }else{
		exit('error');
	}

评论

    • administrator回复

      可以,但是得加上md5判断或者时间判断。还有个问题就是对文件的读取性能一定会好于curl?特别是在IDC机房下载无限制的条件下。

  • 96CD3oJ8RlE=回复

    DuangDuangDuang

CC共享许可协议:BY-NC-SA 4.0 - 友情链接 - Theme by Qzhai