怎么用PHP调用腾讯短网址api接口

发布时间:2021-12-02 13:40:42 作者:iii
来源:亿速云 阅读:217

这篇文章主要介绍“怎么用PHP调用腾讯短网址api接口”,在日常操作中,相信很多人在怎么用PHP调用腾讯短网址api接口问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”怎么用PHP调用腾讯短网址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

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

② 接口支持url参数,当url中出现 & 符号时,请用 %26 代替(或者使用url编码格式),否则参数可能会丢失。

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

PHP调用演示:

$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调用演示:

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调用演示:

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调用腾讯短网址api接口”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

推荐阅读:
  1. 推荐几个最新的腾讯URL短网址以及新浪TCN短连接的API接口
  2. 腾讯(url.cn)短网址链接生成api接口

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php

上一篇:VB.NET怎么实现通信程序

下一篇:tk.Mybatis插入数据获取Id怎么实现

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》