|
发表于 2023-10-21 00:40:22
|
显示全部楼层
用免费gpt4帮你lu了下代码
- <?php
- // 获取当前Unix时间戳
- $wts = time();
- // 使用给定的参数构造URL
- function generateUrl($bvid, $cid) {
- global $wts;
- $session = rand(100000, 999999); // 生成6位随机数
- $w_rid = rand(100000, 999999); // 生成6位随机数
- return "https://api.bilibili.com/x/player/wbi/playurl?bvid={$bvid}&cid={$cid}&qn=80&fnver=0&fnval=4048&fourk=1&gaia_source=&session={$session}&w_rid={$w_rid}&wts={$wts}";
- }
- // 使用cURL发起HTTP请求并获取响应内容
- function fetchContent($url) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $response = curl_exec($ch);
- curl_close($ch);
- return $response;
- }
- // 从HTTP响应中找到并替换URL
- function findAndReplaceUrl($response) {
- $data = json_decode($response, true);
- if (isset($data['video']['backup_url'])) {
- foreach ($data['video']['backup_url'] as $url) {
- if (strpos($url, "upos-sz-mirrorali.bilivideo.com") !== false) {
- $newUrl = str_replace("upos-sz-mirrorali.bilivideo.com", "upos-sz-mirrorcos.bilivideo.com", $url);
- $newUrl = str_replace("\u00", "&", $newUrl);
- return $newUrl;
- }
- }
- }
- return null;
- }
- // 主函数
- function main($bvid, $cid) {
- $url = generateUrl($bvid, $cid);
- $response = fetchContent($url);
- $resultUrl = findAndReplaceUrl($response);
- if ($resultUrl) {
- echo "Result URL: " . $resultUrl;
- } else {
- echo "No matching URL found.";
- }
- }
- // 示例
- main("BV1H84y127ym", "1299598810");
- ?>
复制代码 |
|