• 请不要在回答技术问题时复制粘贴 AI 生成的内容
w910621
V2EX  ›  程序员

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

  •  
  •   w910621 · Mar 3, 2023 · 1664 views
    This topic created in 1200 days ago, the information mentioned may be changed or developed.
    https://tenapi.cn/v2/video/?url=https://v.douyin.com/6BEYVNs
    比如这个我想获取 data 下的 url 的值并输出结果,不知道用 PHP 代码怎么写。我确实是小白一个,找了好多代码不是输出的是空白的就是输出的是网址。谢谢帮忙
    6 replies    2023-03-03 22:23:31 +08:00
    dolorain
        1
    dolorain  
       Mar 3, 2023
    让我这个 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  
       Mar 3, 2023
    $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
       Mar 3, 2023
    @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  
       Mar 3, 2023
    下载这个文件:
    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  
       Mar 3, 2023 via Android
    百度啊,这个又不是什么偏门的问题,边做边想,然后碰到问题继续搜,总会解决的
    bjzhush
        6
    bjzhush  
       Mar 3, 2023
    @w910621 file_get_contents skip ssl verification 搜一下,加个参数就行
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5826 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 02:46 · PVG 10:46 · LAX 19:46 · JFK 22:46
    ♥ Do have faith in what you're doing.