<?php
$url = "要生成的长链接";
print_r(sinaurl($url));
function sinaurl($longurl) {
$result = tcn($longurl);
$result = substr($result,strripos($result,"/")+1);
$result = 'http://sinaurl.cn/'.$result;
if (!$result) {
return '生成失败,请重试';
} else {
return ($result);
}
}
function tcn($site){
$url = 'http://service.weibo.com/share/share.php?url='.urlencode($site).'&title=ířÖˇťńČĄ&pic=&appkey=';
set_time_limit(0);
sleep(0.5);
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3314.0 Safari/537.36 SE 2.X MetaSr 1.0');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt ($ch, CURLOPT_REFERER, "http://news.cctv.com/2019/04/02/ARTIFR5qnxs1fj0v7j3CqXPI190402.shtml");
curl_setopt($ch, CURLOPT_MAXREDIRS,3);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
curl_close($ch);
preg_match('#<em class="tag_text">(.*?)<\/em>#' , $result ,$wburl);
return $wburl[1];
}
function curl_get($url){
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Linux; U; Android 4.4.1; zh-cn; R815T Build/JOP40D) AppleWebKit/533.1 (KHTML, like Gecko)Version/4.0 MQQBrowser/4.5 Mobile Safari/533.1');
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$content=curl_exec($ch);
curl_close($ch);
return($content);
}
?>
原文地址:
https://www.52pojie.cn/thread-1106651-1-1.html
版权属于:soarli
本文链接:https://blog.soarli.top/archives/82.html
转载时须注明出处及本声明。