腾讯短网址接口API源码

Xin 189 次浏览 0

代码

<?php
header("Access-Control-Allow-Origin:*");
header('Content-type: application/json');
!empty($_GET['url']) ? $url = $_GET['url'] : exit(json_encode([
    'code'=>202,
    "msg"=>"请输入网址"
],JSON_UNESCAPED_UNICODE));
$link = myCurl('https://sa.sogou.com/gettiny?url='.$url);
function myCurl($data){
    $ch = curl_init();     // Curl 初始化
    $timeout = 30;     // 超时时间:30s
    $ip = rand(1, 254) . '.' . rand(1, 254) . '.' . rand(1, 254) . '.' . rand(1, 254);
    $UserAgent='Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36';
    curl_setopt($ch, CURLOPT_URL, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_ENCODING, "");
    curl_setopt($ch, CURLOPT_REFERER, $data);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:'.$ip, 'CLIENT-IP:'.$ip));  //构造IP 
    curl_setopt($ch, CURLOPT_USERAGENT, $UserAgent);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    $content = curl_exec($ch);
    curl_close($ch);
    return $content;
}

exit (json_encode(array('code'=>'200','link'=>$link),JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE));
?>
发表评论 取消回复
表情 图片 链接 代码

分享