皮皮虾去水印接口制作全过程(值得学习) - 七彩资源网

皮皮虾去水印接口制作全过程(值得学习)

作者: 七彩网络

全网最全的网络资源分享网站

手机扫码查看

标签:

皮皮虾

特别声明:文章多为网络转载,资源使用一般不提供任何帮助,特殊资源除外,如有侵权请联系!

前言:

当我看皮皮虾想搬运(偷)视频时候,视频里面的水印让我很尴尬,老话说得好自己动手丰衣足食,当然是说干就干,我也是第一次尝试写这个去水印的接口,之前都是用别人的接口,别人一跑路我就得重新寻找,今天就勤快一次,主要是我现在每天很闲

由此得到短链接:

https://h5.pipix.com/s/JjyWG38/
浏览器访问
可以看出这个短链接做了302跳转,地址在headers中
https://h5.pipix.com/item/6854552706657294607?app_id=1319&app=super&timestamp=1596359053&user_id=63284301595&carrier_region=cn&region=cn&language=zh&utm_source=weixin

F12大法

找到了,找这个就看与302跳转的链接有什么相同的地方
https://h5.pipix.com/bds/webapi/item/detail/?item_id=6854552706657294607​

分析json

代码太长我放到最后,主要是我们做接口获取的信息必须找到,例如作者名称,视频里面的文字,还有视频链接
$ppx['name'] = $json->item->author->name;   //获取作者名称
$ppx['content'] = $json->item->content;    //获取文字内容
$ppx['url'] = $json->item->origin_video_download->url_list[0]->url;  //获取视频链接

PHP操作获取302跳转地址和视频id

function getrealurl($url)
{
    @$header = get_headers($url,1);
    if (strpos($header[0],'301') || strpos($header[0],'302')) {
        if(is_array($header['location'])) {
            return $header['location'][count($header['location'])-1];
        }else{
            return $header['location'];
        }
    }else {
        return $url;
    }
}
$url = "https://h5.pipix.com/s/JjyWG38/";
$ids  = explode('/', parse_url(getrealurl($url))['path'])[2];

curl模拟访问

function get_curl($url, $paras = array())
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    if ($paras['httpheader']) { // 请求头
        $httpheader=$paras['httpheader'];
    }else{
        $httpheader[] = "Accept:*/*";
        $httpheader[] = "Accept-Encoding:gzip,deflate,sdch";
        $httpheader[] = "Accept-Language:zh-CN,zh;q=0.8";
        $httpheader[] = "Connection:close";
    }
    curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
    if ($paras['ctime']) { // 连接超时
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, $paras['ctime']);
    }
    if ($paras['rtime']) { // 读取超时
        curl_setopt($ch, CURLOPT_TIMEOUT_MS, $paras['rtime']);
    }
    if ($paras['post']) {
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $paras['post']);
    }
    if ($paras['header']) {
        curl_setopt($ch, CURLOPT_HEADER, true);
    }
    if ($paras['cookie']) {
        curl_setopt($ch, CURLOPT_COOKIE, $paras['cookie']);
    }
    if ($paras['refer']) {
        if ($paras['refer'] == 1) {
            curl_setopt($ch, CURLOPT_REFERER, 'http://m.qzone.com/infocenter?g_f=');
        } else {
            curl_setopt($ch, CURLOPT_REFERER, $paras['refer']);
        }
    }
    if ($paras['ua']) {
        curl_setopt($ch, CURLOPT_USERAGENT, $paras['ua']);
    } else {
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36");
    }
    if ($paras['nobody']) {
        curl_setopt($ch, CURLOPT_NOBODY, 1);
    }
    curl_setopt($ch, CURLOPT_ENCODING, "gzip");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $ret = curl_exec($ch);
    curl_close($ch);
    return $ret;
}
$json = json_decode(get_curl('https://h5.pipix.com/bds/webapi/item/detail/?item_id='.$ids))->data;

看看效果

{
    "code": 200, 
    "msg": "获取成功!", 
    "name": "止于言情", 
    "content": "有对象了搞互删真没必要 你单身的时候我都看不上你 你有对象了我还能拆散你?", 
    "url": "http://v3-ppx.ixigua.com/bd9bc81bd72fe920f6997888d954fc8f/5f26b58a/video/m/2204f179597aab34bcdae3bfd30458edcf611668c6c8000055ca67c1f631/?a=1319&br=3375&bt=1125&cr=0&cs=0&dr=3&ds=3&er=&l=202008021945530100140431501209D910&lr=&mime_type=video_mp4&qs=0&rc=am1zbzhtdW83djMzNWYzM0ApNDU1aWZMvMF4vNjIyLjM6Yw%3D%3D&vl=&vr="
}

终极代码

<?php
/**
* 学者李
* https://handsl.cn
*/
header('Access-Control-Allow-Origin:*');
header('Content-type:application/json; charset=utf-8');
function getrealurl($url)
{
    @$header = get_headers($url,1);
    if (strpos($header[0],'301') || strpos($header[0],'302')) {
        if(is_array($header['location'])) {
            return $header['location'][count($header['location'])-1];
        }else{
            return $header['location'];
        }
    }else {
        return $url;
    }
}
function get_curl($url, $paras = array())
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    if ($paras['httpheader']) { // 请求头
        $httpheader=$paras['httpheader'];
    }else{
        $httpheader[] = "Accept:*/*";
        $httpheader[] = "Accept-Encoding:gzip,deflate,sdch";
        $httpheader[] = "Accept-Language:zh-CN,zh;q=0.8";
        $httpheader[] = "Connection:close";
    }
    curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
    if ($paras['ctime']) { // 连接超时
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, $paras['ctime']);
    }
    if ($paras['rtime']) { // 读取超时
        curl_setopt($ch, CURLOPT_TIMEOUT_MS, $paras['rtime']);
    }
    if ($paras['post']) {
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $paras['post']);
    }
    if ($paras['header']) {
        curl_setopt($ch, CURLOPT_HEADER, true);
    }
    if ($paras['cookie']) {
        curl_setopt($ch, CURLOPT_COOKIE, $paras['cookie']);
    }
    if ($paras['refer']) {
        if ($paras['refer'] == 1) {
            curl_setopt($ch, CURLOPT_REFERER, 'http://m.qzone.com/infocenter?g_f=');
        } else {
            curl_setopt($ch, CURLOPT_REFERER, $paras['refer']);
        }
    }
    if ($paras['ua']) {
        curl_setopt($ch, CURLOPT_USERAGENT, $paras['ua']);
    } else {
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36");
    }
    if ($paras['nobody']) {
        curl_setopt($ch, CURLOPT_NOBODY, 1);
    }
    curl_setopt($ch, CURLOPT_ENCODING, "gzip");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $ret = curl_exec($ch);
    curl_close($ch);
    return $ret;
}
$url = "https://h5.pipix.com/s/JjyWG38/";
$ids  = explode('/', parse_url(getrealurl($url))['path'])[2];
$json = json_decode(get_curl('https://h5.pipix.com/bds/webapi/item/detail/?item_id='.$ids))->data;
$ppx['code'] = 200;
$ppx['msg'] = "获取成功!";
$ppx['name'] = $json->item->author->name;   //获取作者名称
$ppx['content'] = $json->item->content;    //获取文字内容
$ppx['url'] = $json->item->origin_video_download->url_list[0]->url;  //获取视频链接
exit(stripslashes(json_encode($ppx,JSON_UNESCAPED_UNICODE)));
分享到:
打赏
未经允许不得转载:

作者: 七彩网络, 转载或复制请以 超链接形式 并注明出处 七彩资源网
原文地址: 《皮皮虾去水印接口制作全过程(值得学习)》 发布于2020-8-28

评论

切换注册

登录

您也可以使用第三方帐号快捷登录

切换登录

注册

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏