腾讯微视无水印解析源码分享

文章摘要
腾讯微视无水印解析源码已发布,由赵彤刚编写,基于PHP 8.4环境,采用Apache 2.0协议开源,最后更新时间为2024年8月6日。此脚本支持通过POST请求提交微视视频分享链接,无需Cookie及扩展依赖,通过伪造请求头与重定向获取视频信息并输出JSON格式数据。作者同时提供已搭建的测试接口,但声明仅用于测试,不保证稳定性,且未来将不再提供稳定版接口。作者表示部分内容可能影响部分人群利益,后续将持续开源更多API脚本。
— 文章部分摘要由DeepSeek深度思考而成

微视基本不怎么改算法,也是一个脚本传万代。

源码特点:无需 cookie,原生 php 支持,无需安装任何 php 扩展(包括 cURL)

请求方式为:POST(个人喜欢用 POST,至于为什么,经常做小程序 API 开发的应该都懂)

请求参数为:[url : 微视的分享链接]

输出格式为:JSON

输出示例:

图片[1]|腾讯微视无水印解析源码分享|不死鸟资源网

完整源码如下:(源码已做注释,请自行理解源码思路,我懒得写,源码也可在附件中下载)

<?php
/*
名称:微视无水印解析脚本
源码作者:赵彤刚
测试环境:PHP 8.4
源码版本:v1.2.5
开源协议:Apache 2.0
最后更新:2024年8月6日
*/

// 拦截非POST请求
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
    header('Location: https://blog.heheda.top');
    exit;
}
// 响应头
header("Content-type: application/json; charset=utf-8");
header("Access-Control-Allow-Origin: *");
header("X-Powered-By: PHP/" . PHP_VERSION);
header("Content-language: zh");
preg_match('/^https:\/\/video\.weishi\.qq\.com\/[a-zA-Z0-9]+$/', urldecode($_POST['url']), $video_url);
$video_url = $video_url[0];
// 伪造请求头
$uavalue = "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Mobile Safari/537.36";
$headers = [
    "Content-Type: text/html;charset=utf-8",
    "User-Agent: " . $uavalue,
    "Accept-language: zh-CN,zh;q=0.9,de;q=0.8,ug;q=0.7",
    "Referer: " . $video_url
];
// 重定向方法
function get_redirected_url($url)
{
    // 赋予全局变量
    global $headers, $uavalue;
    // 环境配置
    ini_set("user_agent", $uavalue);
    $context = stream_context_create([
        'http' => [
            'method' => 'GET',
            // 启用重定向
            'follow_location' => true,
            // 最大重定向次数
            'max_redirects' => 5,
            'header' => $headers,
        ],
    ]);
    $response = file_get_contents($url, false, $context);
    foreach ($http_response_header as $header) {
        if (strpos($header, 'Location:') === 0) {
            return trim(substr($header, 9));
        }
    }
    return $url;
}
// 获取最终地址并取得视频ID
preg_match('/id=([a-zA-Z0-9]+)/', get_redirected_url($video_url), $video_id);
// 请求并筛选数据
$context = stream_context_create([
    'http' => [
        'method' => 'GET',
        'header' => $headers,
    ]
]);
$response = file_get_contents('https://m.weishi.qq.com/vise/share/index.html?id=' . $video_id[1], false, $context);
preg_match('/window\.Vise\.initState\s*=\s*(\{.*?\});/', $response, $matches);
$matches = json_decode($matches[1], true)['feedsList'][0];
// 构造输出
$outData = [
    "userName" => $matches['poster']['nick'],
    "avatar" => $matches['poster']['avatar'],
    "title" => $matches['feedDesc'],
    "images" => $matches['images'],
    "videoSpecUrls" => $matches['videoSpecUrls'],
    "videoUrl" => $matches['videoUrl']
];
// 输出
echo json_encode($outData);
exit;

如果自己不想(不会)搭建的,也可以直接用我搭建好的。

地址:https://php-api.heheda.top/jiexi/weishi/

【请求方式和请求参数同上】

PS:稳定版接口已下线,并且后期不在提供稳定接口,此接口仅供测试,看心情维护,不保证稳定性。

如果有更好的实现思路或方法,欢迎大神前来交流!

目前开源的几个 API 脚本,可能砸了一些人的饭碗,为表歉意,我决定以后会开源更多的 API 脚本。

<?php
/*
名称:微视无水印解析脚本
源码作者:赵彤刚
测试环境:PHP 8.4
源码版本:v1.2.5
开源协议:Apache 2.0
最后更新:2024年8月6日
*/

// 拦截非POST请求
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
    header('Location: https://blog.heheda.top');
    exit;
}
// 响应头
header("Content-type: application/json; charset=utf-8");
header("Access-Control-Allow-Origin: *");
header("X-Powered-By: PHP/" . PHP_VERSION);
header("Content-language: zh");
preg_match('/^https:\/\/video\.weishi\.qq\.com\/[a-zA-Z0-9]+$/', urldecode($_POST['url']), $video_url);
$video_url = $video_url[0];
// 伪造请求头
$uavalue = "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Mobile Safari/537.36";
$headers = [
    "Content-Type: text/html;charset=utf-8",
    "User-Agent: " . $uavalue,
    "Accept-language: zh-CN,zh;q=0.9,de;q=0.8,ug;q=0.7",
    "Referer: " . $video_url
];
// 重定向方法
function get_redirected_url($url)
{
    // 赋予全局变量
    global $headers, $uavalue;
    // 环境配置
    ini_set("user_agent", $uavalue);
    $context = stream_context_create([
        'http' => [
            'method' => 'GET',
            // 启用重定向
            'follow_location' => true,
            // 最大重定向次数
            'max_redirects' => 5,
            'header' => $headers,
        ],
    ]);
    $response = file_get_contents($url, false, $context);
    foreach ($http_response_header as $header) {
        if (strpos($header, 'Location:') === 0) {
            return trim(substr($header, 9));
        }
    }
    return $url;
}
// 获取最终地址并取得视频ID
preg_match('/id=([a-zA-Z0-9]+)/', get_redirected_url($video_url), $video_id);
// 请求并筛选数据
$context = stream_context_create([
    'http' => [
        'method' => 'GET',
        'header' => $headers,
    ]
]);
$response = file_get_contents('https://m.weishi.qq.com/vise/share/index.html?id=' . $video_id[1], false, $context);
preg_match('/window\.Vise\.initState\s*=\s*(\{.*?\});/', $response, $matches);
$matches = json_decode($matches[1], true)['feedsList'][0];
// 构造输出
$outData = [
    "userName" => $matches['poster']['nick'],
    "avatar" => $matches['poster']['avatar'],
    "title" => $matches['feedDesc'],
    "images" => $matches['images'],
    "videoSpecUrls" => $matches['videoSpecUrls'],
    "videoUrl" => $matches['videoUrl']
];
// 输出
echo json_encode($outData);
exit;

本站资源均为作者提供和网友推荐收集整理而来,仅供学习和研究使用,请在下载后24小时内删除,谢谢合作!
腾讯微视无水印解析源码分享|不死鸟资源网
腾讯微视无水印解析源码分享
此内容为免费资源,请登录后查看
¥0
限时特惠
¥99
文章采用CC BY-NC-SA 4.0许可协议授权
免费资源
THE END
点赞5 分享