如何搭建一个API接口网站?动漫随机图API?一键加QQ好友/加Q群?

如何搭建一个API接口网站?动漫随机图API?一键加QQ好友/加Q群?
此内容为免费资源,请登录后查看
0
限时特惠
18.88
一经购买概不退款
代码提供技术支持
免费资源
已售 358

杂谈

最近有很多热心网友问有没有API接口的源码,想自己搭建一些API接口,我们今天分享一期专门的教程。

在线体验

界面展示

图片[1]-如何搭建一个API接口网站?动漫随机图API?一键加QQ好友/加Q群?-FancyPig's blog
首页星空效果
图片[2]-如何搭建一个API接口网站?动漫随机图API?一键加QQ好友/加Q群?-FancyPig's blog
API列表

公众号快捷获取

您可以关注FancyPig公众号回复API大全获取相关内容

图片[3]-如何搭建一个API接口网站?动漫随机图API?一键加QQ好友/加Q群?-FancyPig's blog

接口展示

聚合视频接口

详细API,这里我们举个例子聚合短视频解析接口

https://api.iculture.cc/api/video/?url=

用户可以在这里输入比方说抖音的短视频

https://v.douyin.com/Yjn7RYw/

我们则输入

https://api.iculture.cc/api/video/?url=https://v.douyin.com/Yjn7RYw/

便可以获得结果

图片[4]-如何搭建一个API接口网站?动漫随机图API?一键加QQ好友/加Q群?-FancyPig's blog

当然,你还可以将其和其他源码界面结合使用

一键打开QQ聊天

灵感来源于之前的文章

你可以将后面的QQ号改为自己的,然后访问链接就可以直接调起聊天界面了

https://api.iculture.cc/api/qq/?qq=663962

一键加入Q群

还有很多有趣的接口,比方说QQ一键加群,我们想加入265586这个群

则可以直接使用接口

https://api.iculture.cc/api/qun/?qun=265586

点击按钮就可以直接加入Q群

IP地址生成

访问下面的链接可以生成你所在IP地址的图

https://api.iculture.cc/api/ipinfo/
图片[5]-如何搭建一个API接口网站?动漫随机图API?一键加QQ好友/加Q群?-FancyPig's blog

动漫随机图

每次访问都会跳转一个随机的动漫图

https://api.iculture.cc/api/img/acg.php

该接口通常可以用于界面的背景

图文教程

如果你也想拥有一个这样的API接口大全的页面,您可以参考下面的教程。

源码下载

准备工作

你需要准备好一台服务器、一个域名还有宝塔面板,我们下面的演示将依赖于上面三者

  • 服务器购买
  • 域名购买

域名购买完,需要做好解析,通常你可以偷个懒,将@*都用A类型解析到你的服务器IP

图片[6]-如何搭建一个API接口网站?动漫随机图API?一键加QQ好友/加Q群?-FancyPig's blog
图片[7]-如何搭建一个API接口网站?动漫随机图API?一键加QQ好友/加Q群?-FancyPig's blog
图片[8]-如何搭建一个API接口网站?动漫随机图API?一键加QQ好友/加Q群?-FancyPig's blog
  • 建站教程

添加站点

我们这里添加api.iculture.cc站点,php选择PHP-73

图片[9]-如何搭建一个API接口网站?动漫随机图API?一键加QQ好友/加Q群?-FancyPig's blog

创建完成后养成好习惯,开启SSL并强制SSL

图片[10]-如何搭建一个API接口网站?动漫随机图API?一键加QQ好友/加Q群?-FancyPig's blog

上传源码

我们这里上传猪猪API.zip并解压

图片[11]-如何搭建一个API接口网站?动漫随机图API?一键加QQ好友/加Q群?-FancyPig's blog

设置伪静态

设置伪静态,选择thinkphp并保存

图片[12]-如何搭建一个API接口网站?动漫随机图API?一键加QQ好友/加Q群?-FancyPig's blog

添加数据库

我们需要添加一个数据库,可以根据个人习惯进行命名,密码随机生成即可

图片[13]-如何搭建一个API接口网站?动漫随机图API?一键加QQ好友/加Q群?-FancyPig's blog

源码安装

访问/install路径,点击同意

图片[14]-如何搭建一个API接口网站?动漫随机图API?一键加QQ好友/加Q群?-FancyPig's blog

这里看到环境都符合要求,点下一步

图片[15]-如何搭建一个API接口网站?动漫随机图API?一键加QQ好友/加Q群?-FancyPig's blog

我们这里添加好数据库、数据库账户和密码,点击下一步

图片[16]-如何搭建一个API接口网站?动漫随机图API?一键加QQ好友/加Q群?-FancyPig's blog

这里可以看到默认账户和密码

  • 后台账户:admin
  • 密码:123456
图片[17]-如何搭建一个API接口网站?动漫随机图API?一键加QQ好友/加Q群?-FancyPig's blog

后台管理

  • 后台入口/admin

使用刚才账户和密码就可以登录后台了

图片[18]-如何搭建一个API接口网站?动漫随机图API?一键加QQ好友/加Q群?-FancyPig's blog

然后我们在后台可以设置网站的基本信息

图片[19]-如何搭建一个API接口网站?动漫随机图API?一键加QQ好友/加Q群?-FancyPig's blog

当然,还可以管理并添加其他的API接口

图片[20]-如何搭建一个API接口网站?动漫随机图API?一键加QQ好友/加Q群?-FancyPig's blog

修改管理员账户和密码

右上角点击个人设置

图片[21]-如何搭建一个API接口网站?动漫随机图API?一键加QQ好友/加Q群?-FancyPig's blog

然后可以修改我们的用户名、邮箱账户和密码

图片[22]-如何搭建一个API接口网站?动漫随机图API?一键加QQ好友/加Q群?-FancyPig's blog

添加接口

我们这里以短视频去水印源码接口为例,教大家如何添加到本系统中

我们先在api目录下创建一个目录,比如命名为video

图片[23]-如何搭建一个API接口网站?动漫随机图API?一键加QQ好友/加Q群?-FancyPig's blog

然后进入video目录,我们新建一个index.phpvideo_spider.php文件

图片[24]-如何搭建一个API接口网站?动漫随机图API?一键加QQ好友/加Q群?-FancyPig's blog

将下面的代码写好放进去,我们这里聚合视频解析是两个文件

  • video_spider.php
  • index.php

video_spider.php

<?php
namespace Video_spider;

class Video
{
    public function pipixia($url)
    {
        $loc = get_headers($url, true)['Location'];
        preg_match('/item\/(.*)\?/', $loc, $id);
        $arr = json_decode($this->curl('https://is.snssdk.com/bds/cell/detail/?cell_type=1&aid=1319&app_name=super&cell_id=' . $id[1]),true);
        $video_url = $arr['data']['data']['item']['origin_video_download']['url_list'][0]['url'];
        if ($video_url) {
            $arr = [
                'code' => 200,
                'data' => [
                    'author' => $arr['data']['data']['item']['author']['name'],
                    'avatar' => $arr['data']['data']['item']['author']['avatar']['download_list'][0]['url'],
                    'time'   => $arr['data']['data']['display_time'],
                    'title'  => $arr['data']['data']['item']['content'],
                    'cover'  => $arr['data']['data']['item']['cover']['url_list'][0]['url'],
                    'url'    => $video_url
                ]
            ];
            return $arr;
        }
    }

    public function douyin($url)
    {
        $loc = get_headers($url, true)['Location'][1];
        preg_match('/video\/(.*)\?/', $loc, $id);
        $arr = json_decode($this->curl('https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=' . $id[1]),true);
        preg_match('/href="(.*?)">Found/',$this->curl(str_replace('playwm', 'play',$arr['item_list'][0]["video"]["play_addr"]["url_list"][0])),$matches);
        $video_url = str_replace('&', '&', $matches[1]);
        if ($video_url) {
            $arr = [
                'code' => 200,
                'msg'  => '解析成功',
                'data' => [
                    'author' => $arr['item_list'][0]['author']['nickname'],
                    'uid'    => $arr['item_list'][0]['author']['unique_id'],
                    'avatar' => $arr['item_list'][0]['author']['avatar_larger']['url_list'][0],
                    'like'   => $arr['item_list'][0]['statistics']['digg_count'],
                    'time'   => $arr['item_list'][0]["create_time"],
                    'title'  => $arr['item_list'][0]['share_info']['share_title'],
                    'cover'  => $arr['item_list'][0]['video']['origin_cover']['url_list'][0],
                    'url'    => $video_url,
                    'music'  => [
                        'author' => $arr['item_list'][0]['music']['author'],
                        'avatar' => $arr['item_list'][0]['music']['cover_large']['url_list'][0],
                        'url'    => $arr['item_list'][0]['music']['play_url']['url_list'][0],
                    ]
                ]
            ];
            return $arr;
        }
    }

    public function huoshan($url)
    {
        $loc = get_headers($url, true)['location'];
        preg_match('/item_id=(.*)&tag/', $loc, $id);
        $arr = json_decode($this->curl('https://share.huoshan.com/api/item/info?item_id=' . $id[1]), true);
        $url = $arr['data']['item_info']['url'];
        preg_match('/video_id=(.*)&line/', $url, $id);
        if ($id) {
            $arr = [
                'code' => 200,
                'msg'  => '解析成功',
                'data' => [
                    'cover' => $arr["data"]["item_info"]["cover"],
                    'url'   => 'https://api-hl.huoshan.com/hotsoon/item/video/_playback/?video_id=' . $id[1]
                ]
            ];
            return $arr;
        }
    }

    public function weishi($url)
    {
        preg_match('/feed\/(.*)\b/', $url, $id);
        if (strpos($url, 'h5.weishi') != false) {
            $arr = json_decode($this->curl('https://h5.weishi.qq.com/webapp/json/weishi/WSH5GetPlayPage?feedid=' . $id[1]),true);
        } else {
            $arr = json_decode($this->curl('https://h5.weishi.qq.com/webapp/json/weishi/WSH5GetPlayPage?feedid=' . $url),true
            );
        }
        $video_url = $arr['data']['feeds'][0]['video_url'];
        if ($video_url) {
            $arr = [
                'code' => 200,
                'msg'  => '解析成功',
                'data' => [
                    'author' => $arr['data']['feeds'][0]['poster']['nick'],
                    'avatar' => $arr['data']['feeds'][0]['poster']['avatar'],
                    'time'   => $arr['data']['feeds'][0]['poster']['createtime'],
                    'title'  => $arr['data']['feeds'][0]['feed_desc_withat'],
                    'cover'  => $arr['data']['feeds'][0]['images'][0]['url'],
                    'url'    => $video_url
                ]
            ];
            return $arr;
        }
    }

    public function weibo($url)
    {
        if (strpos($url, 'show?fid=') != false) {
            preg_match('/fid=(.*)/', $url, $id);
            $arr = json_decode($this->weibo_curl($id[1]), true);
        } else {
            preg_match('/\d+\:\d+/', $url, $id);
            $arr = json_decode($this->weibo_curl($id[0]), true);
        }
        if ($arr) {
            $one = key($arr['data']['Component_Play_Playinfo']['urls']);
            $video_url = $arr['data']['Component_Play_Playinfo']['urls'][$one];
            $arr = [
                'code' => 200,
                'msg'  => '解析成功',
                'data' => [
                    'author' => $arr['data']['Component_Play_Playinfo']['author'],
                    'avatar' => $arr['data']['Component_Play_Playinfo']['avatar'],
                    'time'   => $arr['data']['Component_Play_Playinfo']['real_date'],
                    'title'  => $arr['data']['Component_Play_Playinfo']['title'],
                    'cover'  => $arr['data']['Component_Play_Playinfo']['cover_image'],
                    'url'    => $video_url
                ]
            ];
            return $arr;
        }
    }

    public function lvzhou($url)
    {
        $text = $this->curl($url);
        preg_match('/<div class=\"text\">(.*)<\/div>/', $text, $video_title);
        preg_match('/<div style=\"background-image:url\((.*)\)/', $text, $video_cover);
        preg_match('/<video src=\"([^\"]*)\"/', $text, $video_url);
        preg_match('/<div class=\"nickname\">(.*)<\/div>/', $text, $video_author);
        preg_match('/<a class=\"avatar\"><img src=\"(.*)\?/', $text, $video_author_img);
        preg_match('/<div class=\"like-count\">(.*)次点赞<\/div>/', $text, $video_like);
        if ($video_url[1]) {
            $arr = [
                'code' => 200,
                'msg'  => '解析成功',
                'data' => [
                    'author' => $video_author[1],
                    'avatar' => str_replace('1080.180', '1080.680', $video_author_img)[1],
                    'like'   => $video_like[1],
                    'title'  => $video_title[1],
                    'cover'  => $video_cover[1],
                    'url'    => $video_url[1],
                ]
            ];
            return $arr;
        }
    }

    public function zuiyou($url)
    {
        $text = $this->curl($url);
        preg_match('/fullscreen=\"false\" src=\"(.*?)\"/', $text, $video);
        preg_match('/:<\/span><h1>(.*?)<\/h1><\/div><\/div><div class=\"ImageBoxII\">/', $text, $video_title);
        preg_match('/poster=\"(.*?)\">/', $text, $video_cover);
        $video_url = str_replace('\\', '/', str_replace('u002F', '', $video[1]));
        preg_match('/<span class=\"SharePostCard__name\">(.*?)<\/span>/', $text, $video_author);
        if ($video_url) {
            $arr = [
                'code' => 200,
                'msg'  => '解析成功',
                'data' => [
                    'author' => $video_author[1],
                    'title'  => $video_title[1],
                    'cover' => $video_cover[1],
                    'url'    => $video_url,
                ]
            ];
            return $arr;
        }
    }

    public function bbq($url)
    {
        preg_match('/id=(.*)\b/', $url, $id);
        $arr = json_decode($this->curl('https://bbq.bilibili.com/bbq/app-bbq/sv/detail?svid=' . $id[1]), true);
        $video_url = $arr['data']['play']['file_info'][0]['url'];
        if ($video_url) {
            $arr = [
                'code' => 200,
                'msg'  => '解析成功',
                'data' => [
                    'author' => $arr['data']['user_info']['uname'],
                    'avatar' => $arr['data']['user_info']['face'],
                    'time'   => $arr['data']['pubtime'],
                    'like'   => $arr['data']['like'],
                    'title'  => $arr['data']['title'],
                    'cover'  => $arr['data']['cover_url'],
                    'url'    => $video_url,
                ]
            ];
            return $arr;
        }
    }

    public function kuaishou($url)
    {
        $loc = get_headers($url, true)["Location"][0];
        $text = $this->curl($loc);
        preg_match('/{\"title\":\"(.*?)\",\"desc/', $text, $video_title);
        preg_match('/poster=\"(.*?)\"/', $text, $video_cover);
        preg_match('/srcNoMark\":\"(.*?)\"/', $text, $video_url);
        preg_match('/<div class=\"auth-name\">(.*?)<\/div>/', $text, $video_author);
        preg_match('/<div class=\"auth-avatar\" style=\"background-image:url\((.*?)\)/', $text, $video_avatar);
        preg_match('/timestamp\":(.*?),\"/', $text, $video_time);
        if ($video_url[1]) {
            $arr = [
                'code' => 200,
                'msg'  => '解析成功',
                'data' => [
                    'author' => $video_author[1],
                    'avatar' => $video_avatar[1],
                    'time'   => $video_time[1],
                    "title"  => $video_title[1],
                    "cover"  => $video_cover[1],
                    "url"    => $video_url[1],
                ]
            ];
            return $arr;
        }
    }

    public function quanmin($id)
    {
        if (strpos($id, 'quanmin.baidu.com/v/')) {
            preg_match('/v\/(.*?)\?/', $id, $vid);
            $id = $vid[1];
        }
        $arr = json_decode($this->curl('https://quanmin.hao222.com/wise/growth/api/sv/immerse?source=share-h5&pd=qm_share_mvideo&vid=' . $id . '&_format=json'),true);
        if ($arr) {
            $arr = [
                'code' => 200,
                'msg'  => '解析成功',
                'data' => [
                    'author' => $arr["data"]["author"]['name'],
                    'avatar' => $arr["data"]["author"]["icon"],
                    "title"  => $arr["data"]["meta"]["title"],
                    "cover"  => $arr["data"]["meta"]["image"],
                    "url"    => $arr["data"]["meta"]["video_info"]["clarityUrl"][0]['url']
                ]
            ];
            return $arr;
        }
    }

    public function basai($id)
    {
        $arr = json_decode($this->curl('http://www.moviebase.cn/uread/api/m/video/' . $id . '?actionkey=300303'),true);
        $video_url = $arr[0]['data']['videoUrl'];
        if ($video_url) {
            $arr = [
                'code' => 200,
                'msg'  => '解析成功',
                'data' => [
                    'time'  => $arr[0]['data']['createDate'],
                    'title' => $arr[0]['data']['title'],
                    "cover" => $arr[0]['data']['coverUrl'],
                    "url"   => $video_url
                ]
            ];
            return $arr;
        }
    }

    public function before($url)
    {
        preg_match('/detail\/(.*)\?/', $url, $id);
        $arr = json_decode($this->curl('https://hlg.xiatou.com/h5/feed/detail?id=' . $id[1]), true);
        $video_url = $arr['data'][0]['mediaInfoList'][0]['videoInfo']['url'];
        if ($video_url) {
            $arr = [
                'code' => 200,
                'msg'  => '解析成功',
                'data' => [
                    'author' => $arr['data'][0]['author']['nickName'],
                    'avatar' => $arr['data'][0]['author']['avatar']['url'],
                    'like'   => $arr['data'][0]['diggCount'],
                    'time'   => $arr['recTimeStamp'],
                    'title'  => $arr['data'][0]['title'],
                    "cover"  => $arr['data'][0]['staticCover'][0]['url'],
                    "url"    => $video_url
                ]
            ];
            return $arr;
        }
    }

    public function kaiyan($url)
    {
        preg_match('/\?vid=(.*)\b/', $url, $id);
        $arr = json_decode($this->curl('https://baobab.kaiyanapp.com/api/v1/video/' . $id[1] . '?f=web'), true);
        $video = 'https://baobab.kaiyanapp.com/api/v1/playUrl?vid=' . $id[1] . '&resourceType=video&editionType=default&source=aliyun&playUrlType=url_oss&ptl=true';
        $video_url = get_headers($video, true)["Location"];
        if ($video_url) {
            $arr = [
                'code' => 200,
                'msg'  => '解析成功',
                'data' => [
                    'title' => $arr['title'],
                    "cover" => $arr['coverForFeed'],
                    "url"   => $video_url
                ]
            ];
            return $arr;
        }
    }

    public function momo($url)
    {
        preg_match('/new-share-v2\/(.*)\.html/', $url, $id);
        if (count($id) < 1) {
            preg_match('/momentids=(\w+)/', $url, $id);
        }
        $post_data = ["feedids" => $id[1],];
        $arr = json_decode($this->post_curl('https://m.immomo.com/inc/microvideo/share/profiles', $post_data),true);
        $video_url = $arr['data']['list'][0]['video']['video_url'];
        if ($video_url) {
            $arr = [
                'code' => 200,
                'msg'  => '解析成功',
                'data' => [
                    'author' => $arr['data']['list'][0]['user']['name'],
                    'avatar' => $arr['data']['list'][0]['user']['img'],
                    'uid'    => $arr['data']['list'][0]['user']['momoid'],
                    'sex'    => $arr['data']['list'][0]['user']['sex'],
                    'age'    => $arr['data']['list'][0]['user']['age'],
                    'city'   => $arr['data']['list'][0]['video']['city'],
                    'like'   => $arr['data']['list'][0]['video']['like_cnt'],
                    'title'  => $arr['data']['list'][0]['content'],
                    "cover"  => $arr['data']['list'][0]['video']['cover']['l'],
                    "url"    => $video_url
                ]
            ];
            return $arr;
        }
    }

    public function vuevlog($url)
    {
        $text = $this->curl($url);
        preg_match('/<title>(.*?)<\/title>/', $text, $video_title);
        preg_match('/<meta name=\"twitter:image\" content=\"(.*?)\">/', $text, $video_cover);
        preg_match('/<meta property=\"og:video:url\" content=\"(.*?)\">/', $text, $video_url);
        preg_match('/<div class=\"infoItem name\">(.*?)<\/div>/', $text, $video_author);
        preg_match('/<div class="avatarContainer"><img src="(.*?)\"/', $text, $video_avatar);
        preg_match('/<div class=\"likeTitle\">(.*) friends/', $text, $video_like);
        $video_url = $video_url[1];
        if ($video_url) {
            $arr = [
                'code' => 200,
                'msg'  => '解析成功',
                'data' => [
                    'author' => $video_author[1],
                    'avatar' => $video_avatar[1],
                    'like'   => $video_like[1],
                    'title'  => $video_title[1],
                    "cover"  => $video_cover[1],
                    "url"    => $video_url,
                ]
            ];
            return $arr;
        }
    }

    public function xiaokaxiu($url)
    {
        preg_match('/id=(.*)\b/', $url, $id);
        $sign = md5('S14OnTD#Qvdv3L=3vm&time=' . time());
        $arr = json_decode($this->curl('https://appapi.xiaokaxiu.com/api/v1/web/share/video/' . $id[1] . '?time=' . time(),["x-sign : $sign"]),true);
        if ($arr['code'] != -2002) {
            $arr = [
                'code' => 200,
                'msg'  => '解析成功',
                'data' => [
                    'author' => $arr['data']['video']['user']['nickname'],
                    'avatar' => $arr['data']['video']['user']['avatar'],
                    'like'   => $arr['data']['video']['likedCount'],
                    'time'   => $arr['data']['video']['createdAt'],
                    'title'  => $arr['data']['video']['title'],
                    'cover'  => $arr['data']['video']['cover'],
                    'url'    => $arr['data']['video']['url'][0]
                ]
            ];
            return $arr;
        }
    }

    public function pipigaoxiao($url)
    {
        preg_match('/post\/(.*)/', $url, $id);
        $arr = json_decode($this->pipigaoxiao_curl($id[1]), true);
        $id = $arr["data"]["post"]["imgs"][0]["id"];
        if ($id) {
            $arr = [
                'code' => 200,
                'msg'  => '解析成功',
                'data' => [
                    'title' => $arr["data"]["post"]["content"],
                    'cover' => 'https://file.ippzone.com/img/view/id/' . $arr["data"]["post"]["imgs"][0]["id"],
                    'url'   => $arr["data"]["post"]["videos"]["$id"]["url"]
                ]
            ];
            return $arr;
        }
    }

    public function quanminkge($url)
    {
        preg_match('/\?s=(.*)/', $url, $id);
        $text = $this->curl('https://kg.qq.com/node/play?s=' . $id[1]);
        preg_match('/<title>(.*?)-(.*?)-/', $text, $video_title);
        preg_match('/cover\":\"(.*?)\"/', $text, $video_cover);
        preg_match('/playurl_video\":\"(.*?)\"/', $text, $video_url);
        preg_match('/{\"activity_id\":0\,\"avatar\":\"(.*?)\"/', $text, $video_avatar);
        preg_match('/<p class=\"singer_more__time\">(.*?)<\/p>/', $text, $video_time);
        if ($video_url[1]) {
            $arr = [
                'code'   => 200,
                'msg'    => '解析成功',
                'data'   => [
                    'title' => $video_title[2],
                    'cover' => $video_cover[1],
                    'url'   => $video_url[1],
                    'author' => $video_title[1],
                    'avatar' => $video_avatar[1],
                    'time'   => $video_time[1],
                ]
            ];
            return $arr;
        }
    }

    public function xigua($url)
    {
        if (strpos($url, 'v.ixigua.com') != false) {
            $loc = get_headers($url, true)['Location'];
            preg_match('/video\/(.*)\//', $loc, $id);
            $url = 'https://www.ixigua.com/' . $id[1];
        }
        $headers = [
            "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36 ",
            "cookie:MONITOR_WEB_ID=7892c49b-296e-4499-8704-e47c1b150c18; ixigua-a-s=1; ttcid=af99669b6304453480454f150701d5c226; BD_REF=1; __ac_nonce=060d88ff000a75e8d17eb; __ac_signature=_02B4Z6wo00f01kX9ZpgAAIDAKIBBQUIPYT5F2WIAAPG2ad; ttwid=1%7CcIsVF_3vqSIk4XErhPB0H2VaTxT0tdsTMRbMjrJOPN8%7C1624806049%7C08ce7dd6f7d20506a41ba0a331ef96a6505d96731e6ad9f6c8c709f53f227ab1"
        ];
        $text = $this->curl($url, $headers);
        preg_match('/<script id=\"SSR_HYDRATED_DATA\">window._SSR_HYDRATED_DATA=(.*?)<\/script>/', $text, $jsondata);
        $data = json_decode(str_replace('undefined', 'null', $jsondata[1]), 1);
        $result = $data["anyVideo"]["gidInformation"]["packerData"]["video"];
        $video = $result["videoResource"]["dash"]["dynamic_video"]["dynamic_video_list"][2]["main_url"];
        preg_match('/(.*?)=&vr=/', base64_decode($video), $video_url);
        $music = $result["videoResource"]["dash"]["dynamic_video"]["dynamic_audio_list"][0]["main_url"];
        preg_match('/(.*?)=&vr=/', base64_decode($music), $music_url);
        $video_author = $result['user_info']['name'];
        $video_avatar = str_replace('300x300.image', '300x300.jpg', $result['user_info']['avatar_url']);
        $video_cover = $data["anyVideo"]["gidInformation"]["packerData"]["pSeries"]["firstVideo"]["middle_image"]["url"];
        $video_title = $result["title"];
        if ($url) {
            $arr = [
                'code' => 200,
                'msg'  => '解析成功',
                'data' => [
                    'author' => $video_author,
                    'avatar' => $video_avatar,
                    'like'   => $result['video_like_count'],
                    'time'   => $result['video_publish_time'],
                    'title'  => $video_title,
                    'cover'  => $video_cover,
                    'url'    => $video_url[0],
                    'music'  => [
                        'url' => $music_url[0]
                    ]
                ]
            ];
            return $arr;
        }
    }

    public function doupai($url)
    {
        preg_match("/topic\/(.*?).html/", $url, $d_url);
        $vid = $d_url[1];
        $base_url = "https://v2.doupai.cc/topic/" . $vid . ".json";
        $data = json_decode($this->curl($base_url), true);
        $url = $data["data"]["videoUrl"];
        $title = $data["data"]["name"];
        $cover = $data["data"]["imageUrl"];
        $time = $data['data']['createdAt'];
        $author = $data['data']['userId'];
        if ($url) {
            $arr = [
                'code' => 200,
                'msg'  => '解析成功',
                'data' => [
                    "title"  => $title,
                    "cover"  => $cover,
                    'time'   => $time,
                    'author' => $author['name'],
                    'avatar' => $author['avatar'],
                    "url"    => $url
                ]
            ];
            return $arr;
        }
    }

    public function sixroom($url)
    {
        preg_match("/http[s]?:\/\/(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+/",$url,$deal_url);
        $headers = [
            'user-agent'       => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36',
            'x-requested-with' => 'XMLHttpRequest'
        ];
        $rows = $this->curl($deal_url[0], $headers);
        preg_match('/tid: \'(\w+)\',/', $rows, $tid);
        $base_url = 'https://v.6.cn/message/message_home_get_one.php';
        $content = $this->curl($base_url . '?tid=' . $tid[1], $headers);
        $content = json_decode($content, 1);
        if($content){
            $arr = [
                'code' => 200,
                'msg'  => '解析成功',
                'data' => [
                    'title'  => $content["content"]["content"][0]["content"]['title'],
                    'cover'  => $content["content"]["content"][0]["content"]['url'],
                    'url'  => $content["content"]["content"][0]["content"]['playurl'],
                    'author' => $content["content"]["content"][0]['alias'],
                    'avatar' => $content["content"]["content"][0]['userpic'],
                ]
            ];
            return $arr;
        }
    }

    public function huya($url)
    {
        preg_match('/\/(\d+).html/', $url, $vid);
        $api = 'https://liveapi.huya.com/moment/getMomentContent';
        $response = $this->curl($api . '?videoId=' . $vid[1],
            [
                'user-agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36',
                'referer'    => 'https://v.huya.com/',
            ]
        );
        $content  = json_decode($response, 1);
        if ($content['status'] === 200) {
            $url = $content["data"]["moment"]["videoInfo"]["definitions"][0]["url"];
            $cover = $content["data"]["moment"]["videoInfo"]["videoCover"];
            $title = $content["data"]["moment"]["videoInfo"]["videoTitle"];
            $avatarUrl = $content["data"]["moment"]["videoInfo"]["avatarUrl"];
            $author = $content["data"]["moment"]["videoInfo"]["nickName"];
            $time = $content["data"]["moment"]["cTime"];
            $like = $content["data"]["moment"]["favorCount"];
            $arr = [
                'code' => 200,
                'msg'  => '解析成功',
                'data' => [
                    'title'  => $title,
                    'cover'  => $cover,
                    'url'    => $url,
                    'time'   => $time,
                    'like'   => $like,
                    'author' => $author,
                    'avatar' => $avatarUrl
                ]
            ];
            return $arr;
        }
    }

    public function pear($url)
    {
        $html = $this->curl($url);
        preg_match('/<h1 class=\"video-tt\">(.*?)<\/h1>/', $html, $title);
        preg_match('/_(\d+)/', $url, $feed_id);
        $base_url = sprintf("https://www.pearvideo.com/videoStatus.jsp?contId=%s&mrd=%s", $feed_id[1], time());
        $response = $this->pear_curl($base_url, $url);
        $content = json_decode($response, 1);
        if ($content['resultCode'] == 1) {
            $video = $content["videoInfo"]["videos"]["srcUrl"];
            $cover = $content["videoInfo"]["video_image"];
            $timer = $content["systemTime"];
            $video_url = str_replace($timer, "cont-" . $feed_id[1], $video);
            $arr = [
                'code' => 200,
                'msg'  => '解析成功',
                'data' => [
                    'title' => $title[1],
                    'cover' => $cover,
                    'url'   => $video_url,
                    'time'  => $timer,
                ]
            ];
            return $arr;
        }
    }

    public function xinpianchang($url)
    {
        $api_headers  = [
            "User-Agent" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36",
            "referer" => $url,
            "origin" => "https://www.xinpianchang.com",
            "content-type" => "application/json"
        ];
        $home_headers = [
            "User-Agent" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36",
            "upgrade-insecure-requests" => "1"
        ];
        $html         = $this->curl($url, $home_headers);
        preg_match('/var modeServerAppKey = "(.*?)";/', $html, $key);
        preg_match('/var vid = "(.*?)";/', $html, $vid);
        $base_url = sprintf("https://mod-api.xinpianchang.com/mod/api/v2/media/%s?appKey=%s&extend=%s", $vid[1], $key[1], "userInfo,userStatus");
        $response = $this->xinpianchang_curl($base_url, $api_headers, $url);
        $content  = json_decode($response, 1);
        if ($content['status'] == 0) {
            $cover = $content['data']["cover"];
            $title = $content['data']["title"];
            $videos = $content['data']["resource"]["progressive"];
            $author = $content['data']['owner']['username'];
            $avatar = $content['data']['owner']['avatar'];
            $video = [];
            foreach ($videos as $v) {
                $video[] = ['profile' => $v['profile'], 'url' => $v['url']];
            }
            $arr = [
                'code' => 200,
                'msg'  => '解析成功',
                'data' => [
                    'author' => $author,
                    'avatar' => $avatar,
                    'cover'  => $cover,
                    'title'  => $title,
                    'url'   => $video
                ]
            ];
            return $arr;
        }
    }

    public function acfan($url)
    {
        $headers = [
            'User-Agent:Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1'
        ];
        $html = $this->acfun_curl($url, $headers);
        preg_match('/var videoInfo =\s(.*?);/', $html, $info);
        $videoInfo = json_decode(trim($info[1]), 1);
        preg_match('/var playInfo =\s(.*?);/', $html, $play);
        $playInfo = json_decode(trim($play[1]), 1);
        if ($html) {
            $arr = [
                'code' => 200,
                'title' => $videoInfo['title'],
                'cover' => $videoInfo['cover'],
                'url'   => $playInfo['streams'][0]['playUrls'][0],
            ];
            return $arr;
        }
    }

    public function meipai($url)
    {
        $headers = [
            "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36 ",
        ];
        $html = $this->curl($url, $headers);
        preg_match('/data-video="(.*?)"/', $html, $content);
        preg_match('/<meta name=\"description\" content="(.*?)"/', $html, $title);
        $video_bs64 = $content[1];
        $hex = $this->getHex($video_bs64);
        $dec = $this->getDec($hex['hex_1']);
        $d = $this->sub_str($hex['str_1'], $dec['pre']);
        $p = $this->getPos($d, $dec['tail']);
        $kk = $this->sub_str($d, $p);
        $video = 'https:' . base64_decode($kk);
        if ($video_bs64) {
            $arr = [
                'code'  => 200,
                "title" => $title[1],
                "url"   => $video
            ];
            return $arr;
        }
    }


    private function acfun_curl($url, $headers = [])
    {
        $header = ['User-Agent:Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1'];
        $con = curl_init((string)$url);
        curl_setopt($con, CURLOPT_HEADER, false);
        curl_setopt($con, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($con, CURLOPT_RETURNTRANSFER, true);
        if (!empty($headers)) {
            curl_setopt($con, CURLOPT_HTTPHEADER, $headers);
        } else {
            curl_setopt($con, CURLOPT_HTTPHEADER, $header);
        }
        curl_setopt($con, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($con, CURLOPT_TIMEOUT, 5000);
        return curl_exec($con);
    }

    private function curl($url, $headers = [])
    {
        $header = ['User-Agent:Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1'];
        $con = curl_init((string)$url);
        curl_setopt($con, CURLOPT_HEADER, false);
        curl_setopt($con, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($con, CURLOPT_RETURNTRANSFER, true);
        if (!empty($headers)) {
            curl_setopt($con, CURLOPT_HTTPHEADER, $headers);
        } else {
            curl_setopt($con, CURLOPT_HTTPHEADER, $header);
        }
        curl_setopt($con, CURLOPT_TIMEOUT, 5000);
        $result = curl_exec($con);
        return $result;
    }

    private function post_curl($url, $post_data)
    {
        $postdata = http_build_query($post_data);
        $options = [
            'http' => [
                'method'  => 'POST',
                'content' => $postdata,
            ]
        ];
        $context  = stream_context_create($options);
        $result   = @file_get_contents($url, false, $context);
        return $result;
    }

    private function pipigaoxiao_curl($id)
    {
        $post_data = "{\"pid\":" . $id . ",\"type\":\"post\",\"mid\":null}";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "http://share.ippzone.com/ppapi/share/fetch_content");
        curl_setopt($ch, CURLOPT_REFERER, "http://share.ippzone.com/ppapi/share/fetch_content");
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_TIMEOUT, 5);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        $output = curl_exec($ch);
        curl_close($ch);
        return $output;
    }

    private function weibo_curl($id)
    {
        $cookie = "login_sid_t=6b652c77c1a4bc50cb9d06b24923210d; cross_origin_proto=SSL; WBStorage=2ceabba76d81138d|undefined; _s_tentry=passport.weibo.com; Apache=7330066378690.048.1625663522444; SINAGLOBAL=7330066378690.048.1625663522444; ULV=1625663522450:1:1:1:7330066378690.048.1625663522444:; TC-V-WEIBO-G0=35846f552801987f8c1e8f7cec0e2230; SUB=_2AkMXuScYf8NxqwJRmf8RzmnhaoxwzwDEieKh5dbDJRMxHRl-yT9jqhALtRB6PDkJ9w8OaqJAbsgjdEWtIcilcZxHG7rw; SUBP=0033WrSXqPxfM72-Ws9jqgMF55529P9D9W5Qx3Mf.RCfFAKC3smW0px0; XSRF-TOKEN=JQSK02Ijtm4Fri-YIRu0-vNj";
        $post_data = "data={\"Component_Play_Playinfo\":{\"oid\":\"$id\"}}";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://weibo.com/tv/api/component?page=/tv/show/" . $id);
        curl_setopt($ch, CURLOPT_COOKIE, $cookie);
        curl_setopt($ch, CURLOPT_REFERER, "https://weibo.com/tv/show/" . $id);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_TIMEOUT, 5);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        $output = curl_exec($ch);
        curl_close($ch);
        return $output;
    }

    private function pear_curl($url, $referer)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_REFERER, $referer);
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_TIMEOUT, 5);
        $output = curl_exec($ch);
        curl_close($ch);
        return $output;
    }
    private function xinpianchang_curl($url, $headers, $referer)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_REFERER, $referer);
        if (!empty($headers)) {
            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        }
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_TIMEOUT, 5);
        $output = curl_exec($ch);
        curl_close($ch);
        return $output;
    }

    protected function getHex($url)
    {
        $length = strlen($url);
        $hex_1 = substr($url, 0, 4);
        $str_1 = substr($url, 4, $length);
        return [
            'hex_1' => strrev($hex_1),
            'str_1' => $str_1
        ];
    }

    protected function getDec($hex)
    {
        $b = hexdec($hex);
        $length = strlen($b);
        $c = str_split(substr($b, 0, 2));
        $d = str_split(substr($b, 2, $length));
        return [
            'pre' => $c,
            'tail' => $d,
        ];
    }

    protected function sub_str($a, $b)
    {
        $length = strlen($a);
        $k = $b[0];
        $c = substr($a, 0, $k);
        $d = substr($a, $k, $b[1]);
        $temp = str_replace($d, '', substr($a, $k, $length));
        return $c . $temp;
    }

    protected function getPos($a, $b)
    {
        $b[0] = strlen($a) - (int)$b[0] - (int)$b[1];
        return $b;
    }
}

index.php

<?php
include '../black.php';

header('Access-Control-Allow-Origin:*');
header('Content-type: application/json');
ini_set('display_errors','off');
error_reporting(E_ALL || ~E_NOTICE);
require 'video_spider.php';
$url = $_REQUEST['url'];
$id = $_GET['id'];
$vid = $_GET['vid'];
$basai_id = $_GET['data'];
use Video_spider\Video;
$api = new Video;
if (strpos($url,'pipix')){
    $arr = $api->pipixia($url);
} elseif (strpos($url, 'douyin')){
    $arr = $api->douyin($url);
} elseif (strpos($url, 'huoshan')){
    $arr = $api->huoshan($url);
} elseif (strpos($url, 'h5.weishi')){
    $arr = $api->weishi($url);
} elseif (strpos($url, 'isee.weishi')){
    $arr = $api->weishi($id);
} elseif (strpos($url, 'weibo.com')){
    $arr = $api->weibo($url);
} elseif (strpos($url, 'oasis.weibo')){
    $arr = $api->lvzhou($url);
} elseif (strpos($url, 'zuiyou')){
    $arr = $api->zuiyou($url);
} elseif (strpos($url, 'xiaochuankeji')){
    $arr = $api->zuiyou($url);
    
} elseif (strpos($url, 'bbq.bilibili')){
    $arr = $api->bbq($url);
} elseif (strpos($url, 'kuaishou')){
    $arr = $api->kuaishou($url);
} elseif (strpos($url, 'quanmin')){
    if(empty($vid)){
        $arr = $api->quanmin($url);
    }else{
        $arr = $api->quanmin($vid);
    }
} elseif (strpos($url, 'moviebase')){
    $arr = $api->basai($basai_id);
} elseif (strpos($url, 'hanyuhl')){
    $arr = $api->before($url);
} elseif (strpos($url, 'eyepetizer')){
    $arr = $api->kaiyan($url);
} elseif (strpos($url, 'immomo')){
    $arr = $api->momo($url);
} elseif (strpos($url, 'vuevideo')){
    $arr = $api->vuevlog($url);
} elseif (strpos($url, 'xiaokaxiu')){
    $arr = $api->xiaokaxiu($url);
} elseif (strpos($url, 'ippzone') || strpos($url,'pipigx') ){
    $arr = $api->pipigaoxiao($url);
} elseif (strpos($url, 'qq.com')){
    $arr = $api->quanminkge($url);
} elseif (strpos($url, 'ixigua.com')){
    $arr = $api->xigua($url);
} elseif (strpos($url, 'doupai')){
    $arr = $api->doupai($url);
} elseif(strpos($url,'6.cn')){
    $arr = $api->sixroom($url);
} elseif(strpos($url,'huya.com/play/')){
    $arr = $api->huya($url);
} elseif(strpos($url,'pearvideo.com')){
    $arr = $api->pear($url);
} elseif(strpos($url,'xinpianchang.com')){
    $arr = $api->xinpianchang($url);
} elseif(strpos($url,'acfun.cn')){
    $arr = $api->acfan($url);
} elseif(strpos($url,'meipai.com')){
    $arr = $api->meipai($url);
} else {
    $arr = array(
        'code'  => 201,
        'msg' => '不支持您输入的链接'
    );
}
if (!empty($arr)){
    echo json_encode($arr, JSON_NUMERIC_CHECK | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
else{
    $arr = array(
        'code' => 201,
        'msg' => '解析失败',
    );
    echo json_encode($arr, JSON_NUMERIC_CHECK | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
?>

这里温馨提示,第三方代码拿过来要在第二行添加黑名单文件引用

include '../black.php';

其实到此为止接口就可以用了,但是为了在前端展示我们的接口以及告诉用户如何使用,才有了下面的教程

后台添加接口,因为我们刚才新建的目录为video,因此这里接口地址填api/video/?url=

最后点击提交

图片[25]-如何搭建一个API接口网站?动漫随机图API?一键加QQ好友/加Q群?-FancyPig's blog

© 版权声明
THE END
喜欢就支持一下吧
点赞26赞赏 分享
评论 共8条

请登录后发表评论