url.cn短网址生成接口是腾讯官方对外公开的腾讯短网址转换接口,可以将一个冗长的网址链接缩短成15个字符以内的短链接,并且都是永久有效的。

实用场景

微信短网址的应用场景很广,譬如微信营销、短信营销、邮件推广、QQ营销、自媒体推广、渠道推广等,都会用到短网址,尤其是微信营销应用频率最高。究其原因是在于短网址可以降低推广成本、用户记忆成本,提高用户点击率等优势,不过最被大家看重的还是在微信内使用能规避关键词,防止原链接被拦截。

请求地址

在线工具

开发文档

1、请求方式

  • POST 

2、返回格式

  • 直接返回 “https://url.cn/xxxx”

3、使用方法

① 在线使用

只需将 “http://www.baidu.com” 换成需要缩短的长网址(要带http(s)://),然后复制整串链接前往浏览器打开即可生成。

url.cn,永久的腾讯url.cn短网址生成接口分享-LMLPHP

② 请求接口

设置服务器请求接口生成,每请求一次返回一个结果,代码请求示例如下。

4、请求示例

① PHP

$url = 'http://www.baidu.com';
$api_url = 'http://lnurl.cn/url-api.json?url=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://lnurl.cn/url-api.json?url=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://lnurl.cn'
path = '/url-api.json'
method = 'GET'
querys = 'url_long=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)

 

原文博客转载自:http://lnurl.cn/sb7nym.html 转载请标明出处!

09-23 03:56