PHP新浪短网址(t.cn)API接口
PHP新浪短网址(t.cn)API接口代码
<?php $token = '';//对接token $url = 'http://www.baidu.com';//需要缩短的网址 $data = curl_get('https://apis.btstu.cn/api/dwz/tcn/index.php?url=' . $url . '&token=' . $token); if ($data['code'] == 200) { echo $data['shorturl']; } else { echo $data['msg']; } 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_ENCODING, "gzip"); curl_setopt($ch, CURLOPT_FAILONERROR, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, false); $data = json_decode(curl_exec($ch), true); curl_close($ch); return $data; }
本文结束