经常来我博客的朋友都知道上次我发过了,这次为啥还要发一次,其实是这样的上次的失效了。。。所以又重新写一份新的HHH,下面贴代码

<?php

/**
 * 获取抖音无水印视频地址
 * @param string $url 抖音分享地址
 * @return json
 * @example 调用方法 例: echo douying('http://v.douyin.com/UyxaDa/');
 * @author Reaper <a@0oo.ren>
 * @request https://www.52bz.la
 */
function douying($url)
{
    $content = curl($url)['content'];
    preg_match('/itemId: "(.*?)"/', $content, $itemId);
    preg_match('/dytk: "(.*?)"/', $content, $dytk);
    $url_data['itemId'] = $itemId[1];
    $url_data['dytk'] = $dytk[1];
    $content = curl('https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=' . $url_data['itemId'] . '&dytk=' . $url_data['dytk']);
    $json_data = json_decode($content['content'], 1)['item_list'][0]['video']['download_addr']['url_list'][rand(0, 1)];
    $file_url = curl($json_data)['url'];
    $data = ['code' => 200, 'msg' => '获取成功!', 'download' => $file_url];
    return json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}

function curl($url, $ref = 'https://www.iesdouyin.com/')
{
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_REFERER, $ref);
    curl_setopt($ch, CURLOPT_USERAGENT, 'User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4 (compatible; Baiduspider/2.0; +https://www.52bz.la)');
    $content = curl_exec($ch);
    $newurl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
    curl_close($ch);
    return ['content' => $content, 'url' => $newurl];
}

老版解析接口代码:

原创文章(代码),来之不易,转载请注明原著!

最后修改:2023 年 07 月 25 日
您的赞赏是对我最大的支持。