騰訊短網(wǎng)址(url.cn短鏈接)生成api接口是騰訊官方對(duì)外公開的短網(wǎng)址生成接口,可以將一個(gè)冗長(zhǎng)的鏈接縮短成10個(gè)字符以內(nèi)的短鏈接。
騰訊短網(wǎng)址的應(yīng)用場(chǎng)景很廣,譬如短信營(yíng)銷、郵件推廣、微信營(yíng)銷、QQ營(yíng)銷、自媒體推廣、渠道推廣等都會(huì)用到短網(wǎng)址。究其原因是在于短網(wǎng)址可以降低推廣成本、用戶記憶成本,提高用戶點(diǎn)擊率;在特定的場(chǎng)景下推廣還能規(guī)避關(guān)鍵詞,防止域名被攔截,隱藏真實(shí)地址等。
$url = "http://api.monkeyapi.com";
$params = array(
'appkey' =>'appkey',//您申請(qǐng)的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 {
//請(qǐng)求異常
}
/**
* 請(qǐng)求接口返回內(nèi)容
* @param string $url [請(qǐng)求的URL地址]
* @param string $params [請(qǐng)求的參數(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實(shí)現(xiàn)騰訊短網(wǎng)址生成api接口實(shí)例的文章就介紹到這了,更多相關(guān)騰訊短網(wǎng)址生成api接口內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!