|
|
发表于 2018-12-7 16:02:01
|
显示全部楼层
- <?php
- function restoreSinaShortUrl($shortUrl = '')
- {
- $url = "https://api.weibo.com/2/short_url/expand.json?source=2815391962&url_short={$shortUrl}";
- $urlInfo = file_get_contents($url);
- if ($urlInfo){
- $urlInfo = json_decode($urlInfo, true);
- if (!json_last_error() && isset($urlInfo['urls'])){
- return $urlInfo['urls'][0]['url_long'];
- }
- }
- return false;
- }
- //还原短链接
- //http://t.cn/zWCJpzQ
- function getRealUrl($url)
- {
- while(true){
- if (strstr($url, 'http://t.cn/')){
- $url = restoreSinaShortUrl($url);
- } else {
- break;
- }
- }
- return $url;
- }
复制代码 |
|