千家信息网

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

发表于:2025-02-23 作者:千家信息网编辑
千家信息网最后更新 2025年02月23日,这篇文章主要介绍"怎么用PHP调用腾讯短网址api接口",在日常操作中,相信很多人在怎么用PHP调用腾讯短网址api接口问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"怎
千家信息网最后更新 2025年02月23日怎么用PHP调用腾讯短网址api接口

这篇文章主要介绍"怎么用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, syshost = 'http://www.qqdwz.cn 'path = 'sina.php?url_long='method = 'GET'querys = 'url=http%3A%2F%2Fwww.baidu.com'bodys = {}url = host + path + '?' + querysrequest = urllib2.Request(url)response = urllib2.urlopen(request)content = response.read()if (content):print(content)

到此,关于"怎么用PHP调用腾讯短网址api接口"的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!

0