|
这个接口是采用别人的,因为新浪原生的要申请KEY。
比较麻烦,所以直接采用别人的就可以了,只要功能实现谁的都无所谓。
调用方式是和腾讯短网址一样的,讲究实用..
PS:如果有了接口不会使用怎么办?直接去演示站扒。
完整代码
<?php
header('Access-Control-Allow-Origin:*');
header('Content-type:application/json; charset=utf-8');
error_reporting(0);
function myCurl($params){
$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, $params);
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, $params);
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;
}
!empty($_GET['url']) ? $_GET['url'] : exit(json_encode([
"code"=>201,
"msg"=>"请输入域名"
],JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE));
$json = json_decode(myCurl("https://www.98api.cn/api/sinaDwz.php?url=".$_GET['url']));
if ($json->short_url == "" || $json->long_url==null){
$data = [
"code"=>201,
"msg"=>"生成失败"
];
} else{
$data = [
"code"=>200,
"link"=>$json->short_url
];
}
exit(json_encode($data,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE));
复制代码
|
|