本文实例讲述了PHP通过调用新浪API生成t.cn格式短网址链接的方法。分享给大家供大家参考,具体如下:
新浪提供了长链接转为短链接的API,可以把长链接转为 t.cn/xxx 这种格式的短链接。
API:
http://api.t.sina.com.cn/short_url/shorten.json (返回结果是JSON格式)
http://api.t.sina.com.cn/short_url/shorten.xml (返回结果是XML格式)
请求参数:
source 申请应用时分配的AppKey,调用接口时代表应用的唯一身份。
url_long 需要转换的长链接,需要URLencoded,最多不超过20个。
多个url参数需要使用如下方式请求:url_long=aaa&url_long=bbb
创建source方法
1.进入http://open.weibo.com/ ,选择菜单 微连接->网站接入。
2.点击立即接入,创建新应用,随便填写应用名称,点击创建。
3.创建成功后,AppKey就是source参数的值,可以用于请求创建短链接。
测试代码:
<"htmlcode">[ { "url_short": "http:\/\/t.cn\/Rki0twp", "url_long": "http:\/\/www.cnblogs.com\/daxiangxm", "type": 0 } ]返回XML格式
<"1.0" encoding="UTF-8""_blank" href="http://t.cn/RBclsRo" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >http://t.cn/RBclsRo ,访问会跳转到 https://www.jb51.net/完整调用方法如下:
<"http://t.cn/RBclsRo" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >http://t.cn/RBclsRo
[url_long] => https://www.jb51.net/
[type] => 0
)
)Array(
[0] => Array
(
[url_short] => http://t.cn/RBclsRo
[url_long] => https://www.jb51.net/
[type] => 0
)
[1] => Array
(
[url_short] => http://t.cn/RBclsRo
[url_long] => https://www.jb51.net/
[type] => 0
)
[2] => Array
(
[url_short] => http://t.cn/RBclsRo
[url_long] => https://www.jb51.net/
[type] => 0
)
)经测试,这个生成接口还是比较稳定的!
PS:这里为大家推荐一款本站短网址生成工具(也是使用的第三方API接口生成的短网址)
短链(短网址)在线生成工具:
http://tools.jb51.net/password/dwzcreate更多关于PHP相关内容感兴趣的读者可查看本站专题:《php curl用法总结》、《PHP网络编程技巧总结》、《PHP数组(Array)操作技巧大全》、《php字符串(string)用法总结》、《PHP数据结构与算法教程》及《PHP中json格式数据操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。
无为清净楼资源网 Design By www.qnjia.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
更新日志
- 杨千嬅.2002-万紫千红演唱会2CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 郭采洁.2015-Begin.Again爱造飞鸡【华纳】【FLAC分轨】
- 许志安.2011-ON.AND.ON【东亚】【WAV+CUE】
- 潘秀琼.1994-木兰从军【名将】【WAV+CUE】
- 纯音入心系列纯音乐《古筝系列-当流行乐遇到古筝》1CD[MP3][1.9GB]
- 纯音入心系列纯音乐《精选古筝名曲100首》1CD[MP3][388.7MB]
- 纯音入心系列纯音乐《天籁古筝》1CD[MP3][331MB]
- 男女对唱典藏天碟《发烧对唱·那个季节里的歌DSD》10CD[WAV]
- 群星2010-歌林精选辑[歌林][WAV+CUE]
- TrioZimbalist-PianoTriosofWeinberg,Auerbach,Dvorak(2024)[24-44,1]wav
- 群星.1992-滚石第一流台湾歌·12王牌大车拼【滚石】【WAV+CUE】
- 林子祥.1984-创作歌集【华纳】【WAV+CUE】
- 周汤豪.2010-周汤豪【华纳】【FLAC分轨】
- Mozart-TheStringQuintets-AmadeusQuartet,CecilAronowitz(2017)[24-44,1][WAV+CUE]
- JamesWilliamsDennisIrwin-Focus(2024,Red)[24-48]FLAC