1.簡要描述
騰訊短網(wǎng)址(url.cn短鏈接)生成api接口是騰訊官方對外公開的短網(wǎng)址生成接口,可以將一個冗長的鏈接縮短成10個字符以內(nèi)的短鏈接。
2.應用場景
騰訊短網(wǎng)址的應用場景很廣,譬如短信營銷、郵件推廣、微信營銷、QQ營銷、自媒體推廣、渠道推廣等都會用到短網(wǎng)址。究其原因是在于短網(wǎng)址可以降低推廣成本、用戶記憶成本,提高用戶點擊率;在特定的場景下推廣還能規(guī)避關(guān)鍵詞,防止域名被攔截,隱藏真實地址等。
3.使用說明
接口地址:http://api.monkeyapi.com
請求方式:http get/post
返回格式:json
4.示例
$url = "http://api.monkeyapi.com"; $params = array( 'appkey' =>'appkey',//您申請的APPKEY 'url' =>'www.monkeyapi.com',//需要查詢的網(wǎng)站 ); $paramstring = http_build_query($params); $content = Curl($url, $paramstring); $result = json_decode($content, true); if($result) { var_dump($result); }else { //請求異常 } /** * 請求接口返回內(nèi)容 * @param string $url [請求的URL地址] * @param string $params [請求的參數(shù)] * @param int $ipost [是否采用POST形式] * @return string */ function Curl($url, $params = false, $ispost = 0) { $httpInfo = array(); $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60); curl_setopt($ch, CURLOPT_TIMEOUT, 60); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); if ($ispost) { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); curl_setopt($ch, CURLOPT_URL, $url); }else { if ($params) { curl_setopt($ch, CURLOPT_URL, $url.'?'.$params); } else { curl_setopt($ch, CURLOPT_URL, $url); } } $response = curl_exec($ch); if ($response === FALSE) { //echo "cURL Error: " . curl_error($ch); return false; } $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $httpInfo = array_merge($httpInfo, curl_getinfo($ch)); curl_close($ch); return $response; }
到此這篇關(guān)于PHP實現(xiàn)騰訊短網(wǎng)址生成api接口實例的文章就介紹到這了,更多相關(guān)騰訊短網(wǎng)址生成api接口內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!