Blogger Information
Blog 1
fans 0
comment 0
visits 4188
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
2020最新防封短链接-新浪短网址API接口分享
btzjvyu
Original
4188 people have browsed it

 在短信,微信,微博,等等各大营销平台中我们都能看到 t.cn/xxxx 样式的新浪短链接,这种超短链接很好的满足了营销中要求链接简洁,美观,专业的特性,而且通过新浪短网址包装后的短链接比原链接在微信、短信、微博等平台存活率更高!那么新浪t.cn短链接如何生成呢?网址缩短API接口如何调用?今天我就给大家分享一下。


新浪t.cn短网址API接口:

http://qingmeidwz.cn/shorten.php?url_long=http://www.baidu.com 

微信url.cn短网址API接口:

http://qingmeidwz.cn/wxshorturl.do?url_long=http://www.baidu.com 


接口来源:

http://qingmeidwz.cn/


使用说明:

将api接口地址中 "http://www.baidu.com"换成需要缩短的网址,然后直接复制前往浏览器中打开即可。

调用方法(以新浪t.cn短链接api接口为例):

PHP调用演示:

$url = 'http://www.baidu.com';
$api_url = 'http://qingmeidwz.cn/shorten.php?url_long=http://www.baidu.com';
$short_url = file_get_contents($api_url);
echo $short_url;

JAVA调用演示:

public static void main(String path[]) throws Exception {
URL u = new URL("http://qingmeidwz.cn/shorten.php?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调用演示:

import urllib, urllib2, sys
host = 'http://qingmeidwz.cn/'
path = 'shorten.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)

注意事项:

① 调用api接口时,只需将 “http://www.baidu.com”换成需要缩短的长网址即可。

② 接口支持url参数,当url中出现 & 符号时,请用 %26 代替,否则参数可能会丢失。

③ 填写url时,必须要以http(s)://开头,否则可能会导致生出的短网址无法访问原网站。

④ 上文的微信url.cn,新浪t.cn短网址api接口,经测试非常稳定,觉得好记得收藏一下,以免丢失。 

常见问题:

① 长链接转换,为什么结尾的参数丢失了?

答:因为url中含有特殊字符,需要使用UTF8编码格式,将url编码

② 接口没有返回结果,是什么情况?

答:有些时候接口返回数据会有延迟,延时未返回则会提示生成失败;或者是因为原链接被封了

③ 生成的短网址有效期是多久?有没有访问次数限制?

答:生成的短网址都是永久有效的,而且没有点击次数限制,可以任意使用

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!