吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1875|回复: 15
收起左侧

[其他原创] 【PHP】心情愉悦(抖音小视频),可自行修改为接口,单文件运行!

[复制链接]
newClass 发表于 2023-5-9 14:16
本帖最后由 newClass 于 2023-5-15 10:56 编辑

  • 新建Joyful.php,复制代码,直接访问即可
  • 自用共享,请勿倒卖


[PHP] 纯文本查看 复制代码
<?php
if ((isset($_SERVER["HTTP_X_REQUESTED_WITH"]) && strtolower($_SERVER["HTTP_X_REQUESTED_WITH"]) == "xmlhttprequest") || isset($_GET['jump'])) {
    $starttime = microtime(1);
    $result['run_time'] = number_format((microtime(1) - $starttime) * 1000, 1);
    $ListApi = 'https://gitee.com/au_2023/codes/nxe5yoirc9l8s70dzvawh50/raw?blob_name=JoyfulList'; // 自己进行收集整理
    $video_id = get_video_id($ListApi);
    $result = array();
    $result['play_addr'] = getRedirect('https://aweme.snssdk.com/aweme/v1/play/?video_id=' . $video_id);
    $result['video_id'] = $video_id;
    $result['run_time'] = number_format((microtime(1) - $starttime) * 1000, 1);
    if (isset($_GET['jump'])) {
        header('Location: ' . $result['play_addr']);
    }
    header("Content-Type: application/json");
    echo json_encode($result);
    exit('');
}

function get_video_id($Api)
{
    $cache = __DIR__ . '/Joyful.txt';
    if (is_file($cache)) {
        $Data = unserialize(file_get_contents($cache));
        if (count($Data) == 0) {
            $Data = json_decode(file_get_contents($cache), true);
        }
    } else {
        $Data = json_decode(file_get_contents($Api), true);
    }
    $key = rand(0, count($Data) - 1);
    $video_id = $Data[$key];
    unset($Data[$key]);
    file_put_contents($cache, serialize(array_values($Data)));
    return $video_id;
}

function getRedirect($Url)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $Url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Accept: */*',
        'Accept-Encoding: gzip',
        'Connection: Keep-Alive',
        'User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)'
    ));
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_NOBODY, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $ret = curl_exec($ch);

    curl_close($ch);
    preg_match("/Location: (.*?)\r\n/iU", $ret, $location);
    if (isset($location[1])) {
        return $location[1];
    }
    return false;
}
?>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>心情愉悦</title>
    <meta name="renderer" content="webkit">
    <meta name="referrer" content="never">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/js-cookie/3.0.1/js.cookie.js"></script>
</head>

<body>
    <div class="container" id="player" style="display: none;">
        <video id="video" controls autoplay style="width: 100%;"></video>
    </div>
    <button id="start">开始运行</button>
</body>
<script>
    load();

    function start() {
        var result = JSON.parse(Cookies.get('next'));
        $('#player').show();
        $('#start').hide();
        $('#video').attr('src', result.play_addr);
        load();
    }

    let video = document.getElementById('video');
    video.onended = function() {
        var result = JSON.parse(Cookies.get('next'));
        $('#video').attr('src', result.new_play_addr);
        load();
    }

    function load() {
        $.ajax({
            type: 'get',
            url: 'Joyful.php',
            async: false,
            success: function(result) {
                data = result;
                downloadBlobFile('GET', result.play_addr).onreadystatechange = res => {
                    if (res.currentTarget.readyState == 4 && res.currentTarget.status == 200) {
                        result.new_play_addr = window.URL.createObjectURL(res.currentTarget.response);
                        result = JSON.stringify(result);
                        Cookies.set('next', result, 60);
                    }
                }
            },
            error: function() {
                //layer.msg('加载失败,等待下一次加载...');
            }
        });
        return data;
    }

    function downloadBlobFile(_method, _url) {
        const request = new XMLHttpRequest();
        request.open(_method, _url);
        request.send();
        request.responseType = 'blob';
        return request;
    }
</script>

</html>

免费评分

参与人数 2吾爱币 +8 热心值 +2 收起 理由
祥哥 + 1 + 1 谢谢@Thanks!
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

TabKey9 发表于 2023-5-12 22:04

来自@TabKey9,的第7个版

  1. 楼主5月8日发帖挨删,我猜原因是gitee链接带Q号,提这件事只是想说,我从8号到12号,已经改了7个版了,后面应该不改了,能改的东西很少了,有个不算BUG的BUG:手速快的网友可以触发到控制台。吐槽一下,第一版复制下来根本用不了。开头没有<?php,变量声明用小写$listApi,使用的时候却用大写$ListApi。楼主第二次发帖时已经改过来了。
  2. 可能编码习惯不同吧,如果开封即用不用改代码的情况下我是一点也不会动楼主代码的,但既然改了,那我不用单文件的形式,拆成index.htmlJoyful.php,下面我分享对这两个文件的 改动部分

Joyful.php

debug:调试代码的过程中抛出 一个报错Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in.....、一个警告Warning: Undefined array key 0 in......

function get_video_id($Api)
{
    $cache = __DIR__ . '/Joyful.txt';
    if (is_file($cache)) {
        $Data = unserialize(file_get_contents($cache));
        if (!is_array($Data)) {
            $Data = json_decode(file_get_contents($cache), true);
            if (!is_array($Data)) {
                $Data = array();
            }
        }
    } else {
        $Data = json_decode(file_get_contents($Api), true);
    }

    if (empty($Data)) {
        unlink($cache); // 删除缓存文件
        $Data = json_decode(file_get_contents($Api), true);
    }

    $key = !empty($Data) ? rand(0, count($Data) - 1) : null;
    $video_id = isset($Data[$key]) ? $Data[$key] : null;

    if ($key !== null && $video_id !== null) {
        unset($Data[$key]);
        file_put_contents($cache, serialize(array_values($Data)));
    }

    return $video_id;
}

index.html

改动太多,代码就不贴了,我留了很多很多的注释,偷个懒让我简单口述一下就好:

  1. 特殊的需求:嵌入第三方论坛,实现跨域名播放。

    难点:跨域问题解决不了,因为跨域不能共享cookie

    解决方案:用浏览器的本地存储替代cookie,于是就有了下面的截图。


   

演示1

演示1


  1. 最想要的需求:上下滑动切换视频。

    难点:首先我不会,但是我会曲线救国呀!我记得有个版本是在<body>加按钮的,丑到自己都嫌弃。

    解决方案:还是按钮,只不过好看 亿点点了,首先引入一个国外的弹窗UIsweetalert.min.js,然后咱得有个DOM事件监听器,监听H5 video的播放\暂停,让这个弹窗菜单在视频被暂停的时候触发。然后就有了下面的效果,完美


演示2

演示2

演示3

演示3


@newClass 抱歉了,我把你的原创改的已经不一样了,不过我给你留了作者名哟!嘻嘻嘻

源码打包在此:
Joyful.zip (45.55 KB, 下载次数: 36)

免费评分

参与人数 2吾爱币 +2 热心值 +2 收起 理由
newClass + 1 + 1 用心讨论,共获提升!
苏紫方璇 + 1 + 1 用心讨论,共获提升!

查看全部评分

skykain 发表于 2023-5-9 23:04
楼主发的代码有点问题啊,稍微修了下。
[PHP] 纯文本查看 复制代码
<?php
if ((isset($_SERVER["HTTP_X_REQUESTED_WITH"]) && strtolower($_SERVER["HTTP_X_REQUESTED_WITH"]) == "xmlhttprequest") || isset($_GET['jump'])) {
    $starttime = microtime(1);
    $result['run_time'] = number_format((microtime(1) - $starttime) * 1000, 1);
    $listApi = 'https://gitee.com/au_2023/codes/nxe5yoirc9l8s70dzvawh50/raw?blob_name=JoyfulList'; // 自己进行收集整理
    $video_id = get_video_id($listApi);
    $result = array();
    $result['play_addr'] = getRedirect('https://aweme.snssdk.com/aweme/v1/play/?video_id=' . $video_id);
    $result['video_id'] = $video_id;
    $result['run_time'] = number_format((microtime(1) - $starttime) * 1000, 1);
    if (isset($_GET['jump'])) {
        header('Location: ' . $result['play_addr']);
    }
    header("Content-Type: application/json");
    echo json_encode($result);
    exit('');
}
 
function get_video_id($Api)
{
    $cache = __DIR__ . '/Joyful.txt';
    if (is_file($cache)) {
        $Data = unserialize(file_get_contents($cache));
        if (count($Data) == 0) {
            $Data = json_decode(file_get_contents($cache), true);
        }
    } else {
        $Data = json_decode(file_get_contents($Api), true);
        // var_dump($Data);exit();
    }
    $key = rand(0, count($Data) - 1);
    $video_id = $Data[$key];
    unset($Data[$key]);
    file_put_contents($cache, serialize(array_values($Data)));
    return $video_id;
}
 
function getRedirect($Url)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $Url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Accept: */*',
        'Accept-Encoding: gzip',
        'Connection: Keep-Alive',
        'User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)'
    ));
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_NOBODY, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $ret = curl_exec($ch);
 
    curl_close($ch);
    preg_match("/Location: (.*?)\r\n/iU", $ret, $location);
    if (isset($location[1])) {
        return $location[1];
    }
    return false;
}
?>
<!DOCTYPE html>
<html>
 
<head>
    <meta charset="utf-8">
    <title>心情愉悦</title>
    <meta name="renderer" content="webkit">
    <meta name="referrer" content="never">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <script src="https://cdn.staticfile.org/jquery/3.6.4/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/js-cookie/3.0.5/js.cookie.min.js"></script>
</head>
 
<body>
    <div class="container" id="player" style="display: none;">
        <video id="video" controls autoplay style="width: 100%;"></video>
    </div>
    <button id="start">开始运行</button>
</body>
<script>
    function start() {
        var result = JSON.parse(Cookies.get('next'));
        $('#player').show();
        $('#start').hide();
        $('#video').attr('src', result.play_addr);
        load();
    }
 
    let video = document.getElementById('video');
    video.onended = function() {
        var result = JSON.parse(Cookies.get('next'));
        $('#video').attr('src', result.new_play_addr);
        load();
    }
 
    function load() {
        $.ajax({
            type: 'get',
            url: 'Joyful.php',
            async: false,
            success: function(result) {
                data = result;
                downloadBlobFile('GET', result.play_addr).onreadystatechange = res => {
                    if (res.currentTarget.readyState == 4 && res.currentTarget.status == 200) {
                        result.new_play_addr = window.URL.createObjectURL(res.currentTarget.response);
                        result = JSON.stringify(result);
                        Cookies.set('next', result, 60);
                    }
                }
            },
            error: function() {
                //layer.msg('加载失败,等待下一次加载...');
            }
        });
        return data;
    }
 
    function downloadBlobFile(_method, _url) {
        const request = new XMLHttpRequest();
        request.open(_method, _url);
        request.send();
        request.responseType = 'blob';
        return request;
    }
    
    $(document).ready(function(){
        load();
        start();
    });
    
</script>
 
</html>
lcg888 发表于 2023-5-9 17:17
htxz2022 发表于 2023-5-9 19:32
没搞懂,新建了Joyful.php,然后打开网页只有一个开始运行按钮,点击没有任何反应,不知道是哪里出错了
bdcpc 发表于 2023-5-9 22:13
<b>Warning</b>:  array_values() expects parameter 1 to be array, boolean given in <b>/www/wwwroot/Joyful.php</b> on line <b>35</b><br />
{"play_addr":false,"video_id":null,"run_time":"746.0"}退出
提示这个错误
onlywey 发表于 2023-5-10 00:30
谢谢分享
 楼主| newClass 发表于 2023-5-10 08:39
htxz2022 发表于 2023-5-9 19:32
没搞懂,新建了Joyful.php,然后打开网页只有一个开始运行按钮,点击没有任何反应,不知道是哪里出错了

看看控制台有什么报错不
 楼主| newClass 发表于 2023-5-10 08:40
bdcpc 发表于 2023-5-9 22:13
Warning:  array_values() expects parameter 1 to be array, boolean given in /www/wwwroot/Joyful.php o ...

我怀疑 你的服务器  打不开  https://gitee.com/au_2023/codes/nxe5yoirc9l8s70dzvawh50/raw?blob_name=JoyfulList  这个链接
 楼主| newClass 发表于 2023-5-10 08:52
skykain 发表于 2023-5-9 23:04
楼主发的代码有点问题啊,稍微修了下。
[mw_shl_code=php,true]

可以 但作用不大
忧郁之子 发表于 2023-5-10 13:35
谢谢分享,支持一下
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-14 22:15

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表