V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
w910621
V2EX  ›  程序员

请问一下 PHP 如何获取 API 字段的值并输出结果

  •  
  •   w910621 · 2023-03-03 12:32:39 +08:00 · 780 次点击
    这是一个创建于 420 天前的主题,其中的信息可能已经有所发展或是发生改变。
    https://tenapi.cn/v2/video/?url=https://v.douyin.com/6BEYVNs
    比如这个我想获取 data 下的 url 的值并输出结果,不知道用 PHP 代码怎么写。我确实是小白一个,找了好多代码不是输出的是空白的就是输出的是网址。谢谢帮忙
    6 条回复    2023-03-03 22:23:31 +08:00
    dolorain
        1
    dolorain  
       2023-03-03 13:36:25 +08:00
    让我这个 php 菜鸟试试:

    <?php
    $data = file_get_contents('https://tenapi.cn/v2/video/?url=https://v.douyin.com/6BEYVNs');
    $toJson = json_decode($data);
    echo $toJson->data->music->url;
    mht
        2
    mht  
       2023-03-03 13:38:12 +08:00
    $result = file_get_content("https://tenapi.cn/v2/video/?url=https://v.douyin.com/6BEYVNs");
    $json = json_decode($result,true);
    if($json){
    echo $json['data']['url'];
    }else{
    echo '数据解析失败';
    }
    w910621
        3
    w910621  
    OP
       2023-03-03 14:20:59 +08:00
    @mht Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
    报这个错
    vibbow
        4
    vibbow  
       2023-03-03 16:23:01 +08:00
    下载这个文件:
    https://curl.se/ca/cacert.pem

    然后把他放到服务器上,php.ini 里添加下面两句 (路径设置到你放到的位置)

    curl.cainfo = "D:\PHP\Shared\cert\cacert.pem"
    openssl.cafile = "D:\PHP\Shared\cert\cacert.pem"
    zddwj
        5
    zddwj  
       2023-03-03 17:48:38 +08:00 via Android
    百度啊,这个又不是什么偏门的问题,边做边想,然后碰到问题继续搜,总会解决的
    bjzhush
        6
    bjzhush  
       2023-03-03 22:23:31 +08:00
    @w910621 file_get_contents skip ssl verification 搜一下,加个参数就行
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5338 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 09:05 · PVG 17:05 · LAX 02:05 · JFK 05:05
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.