Blogger Information
Blog 1
fans 0
comment 0
visits 466
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
微信(url.cn),新浪微博(t.cn)短网址生成api接口以及php,python的调用方法
y73mhyuw
Original
466 people have browsed it

微信营销中,原链接太长总是很不方便分享,转化率极低。所以我们一般使用微信短链接即url.cn的短网址或者新浪微博(t.cn)短网址样式来缩短我们的链接,再发布到微信平台进行链接分享,今天给大家分享一个微信短链接生成接口,以及微信url.cn短网址新浪t.cn短网址的生成方式。

微信url.cn短链接生成api接口:

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

新浪t.cn短链接api接口: 

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

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

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

PHP调用演示:

$url = 'http://www.baidu.com';
$api_url = 'http://qingmeidwz.cn/shorten.json?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.json?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.json?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