全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 1291|回复: 11

[Windows VPS] Json短网址php如何使用

[复制链接]
发表于 2020-3-1 00:17:07 | 显示全部楼层 |阅读模式
本帖最后由 2004tj 于 2020-3-1 01:24 编辑

https://v1.alapi.cn/api/url?url=https://www.hostloc.com
https://vip.video.qq.com/fcgi-bin/comm_cgi?name=short_url&need_short_url=1&url=https://www.hostloc.com
小白请教怎么变成php函数直接使用输出短地址

<?php echo $short_url['长地址']; ?>
发表于 2020-3-1 00:19:03 | 显示全部楼层
小板凳已就绪  坐等楼下解释
发表于 2020-3-1 00:27:46 | 显示全部楼层
bash大砝好,curl https://v1.alapi.cn/api/url?url=https://www.hostloc.com | jq '.data.short_url'
 楼主| 发表于 2020-3-1 00:44:44 | 显示全部楼层
A23187 发表于 2020-3-1 00:27
bash大砝好,curl https://v1.alapi.cn/api/url?url=https://www.hostloc.com | jq '.data.short_url'

大佬 这种PHP怎么调用
发表于 2020-3-1 00:49:56 | 显示全部楼层
  1.         function makeShortUrl($url)
  2.         {
  3.                 $url = urlencode($url);
  4.                 $result = @file_get_contents("https://v1.alapi.cn/api/url?url={$url}");
  5.                 if ($result){
  6.                         $result = json_decode($result, true);
  7.                         if (isset($result['data']['short_url'])){
  8.                                 return $result['data']['short_url'];
  9.                         }
  10.                 }
  11.                 return false;
  12.         }
  13.        
  14.         echo makeShortUrl('http://baidu.com');
复制代码


刚好用到,举手之劳
 楼主| 发表于 2020-3-1 00:53:50 | 显示全部楼层
flofire 发表于 2020-3-1 00:49
刚好用到,举手之劳

谢谢 大佬
 楼主| 发表于 2020-3-1 00:59:28 | 显示全部楼层
flofire 发表于 2020-3-1 00:49
刚好用到,举手之劳

大佬在帮忙看看这个  https://vip.video.qq.com/fcgi-bin/comm_cgi?name=short_url&need_short_url=1&url=https://www.hostloc.com
 楼主| 发表于 2020-3-1 01:23:56 | 显示全部楼层
本帖最后由 2004tj 于 2020-3-1 08:43 编辑
flofire 发表于 2020-3-1 00:49
刚好用到,举手之劳

 楼主| 发表于 2020-3-1 09:51:33 | 显示全部楼层
flofire 发表于 2020-3-1 00:49
刚好用到,举手之劳

代码没错,为啥放在PHP文件直接访问不出结果呢
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2024-5-6 01:54 , Processed in 0.062415 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表