溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

怎么用PHP調(diào)用騰訊短網(wǎng)址api接口

發(fā)布時間:2021-12-02 13:40:42 來源:億速云 閱讀:234 作者:iii 欄目:移動開發(fā)

這篇文章主要介紹“怎么用PHP調(diào)用騰訊短網(wǎng)址api接口”,在日常操作中,相信很多人在怎么用PHP調(diào)用騰訊短網(wǎng)址api接口問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”怎么用PHP調(diào)用騰訊短網(wǎng)址api接口”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!

接口1: http://www.sinadwz.cn/url/dwz.php?url_long=http://www.baidu.com

接口2: http://maiyurl.cn/tengxurl?url_long=http://www.baidu.com

接口3: http://www.sina-url.cn/txdwz.php?url_long=http://www.baidu.com

接口4:http://www.qqdwz.cn/urlcn/api ?url_long=http://www.baidu.com

① 調(diào)用api接口時,只需將 “http://www.baidu.com”換成需要縮短的長網(wǎng)址即可。

② 接口支持url參數(shù),當url中出現(xiàn) & 符號時,請用 %26 代替(或者使用url編碼格式),否則參數(shù)可能會丟失。

③ 填寫url時,必須要以http(s)://開頭,否則可能會導致生出的短網(wǎng)址無法訪問原網(wǎng)站。

PHP調(diào)用演示:

$url = 'http://www.baidu.com';
$api_url = 'http://www.qqdwz.cn/tcn/api?url_long=http://www.baidu.com;
$short_url = file_get_contents($api_url);
echo $short_url;

JAVA調(diào)用演示:

public static void main(String path[]) throws Exception {
URL u = new URL("http://www.qqdwz.cn/tcn/api?url_long=http://www.baidu.com");
InputStream in = u.openStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
byte buf[] = new byte[1024];
int read = 0;
while ((read = in .read(buf)) > 0) {
out.write(buf, 0, read);
}
} finally {
if ( in != null) {
in .close();
}
}
byte b[] = out.toByteArray();
System.out.println(new String(b, "utf-8"));
}

Python調(diào)用演示:

import urllib, urllib2, sys
host = 'http://www.qqdwz.cn '
path = 'sina.php?url_long='
method = 'GET'
querys = 'url=http%3A%2F%2Fwww.baidu.com'
bodys = {}
url = host + path + '?' + querys
request = urllib2.Request(url)
response = urllib2.urlopen(request)
content = response.read()
if (content):
print(content)

到此,關于“怎么用PHP調(diào)用騰訊短網(wǎng)址api接口”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續(xù)學習更多相關知識,請繼續(xù)關注億速云網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

php
AI