皮皮虾去水印接口制作全过程
前言当我看皮皮虾想搬运(偷)视频时候,视频里面的水印让我很尴尬,老话说得好自己动手丰衣足食,当然是说干就干,我也是第一次尝试写这个去水印的接口,之前都是用别人的接口,别人一跑路我就得重新寻找,今天就勤快一次,主要是我现在每天很闲开始获取链接https://cdn.jsdelivr.net/gh/xuezheli/Pic/usr/uploads/2020/08/2112417091.jpg得到短链接https://h5.pipix.com/s/JjyWG38/浏览器访问可以看出这个短链接做了302跳转,地址在headers中https://cdn.jsdelivr.net/gh/xuezheli/Pic/usr/uploads/2020/08/631819824.pnghttps://h5.pipix.com/item/6854552706657294607?app_id=1319&app=super×tamp=1596359053&user_id=63284301595&carrier_region=cn®ion=cn&language=zh&utm_source=weixinF12大法找到了,找这个就看与302跳转的链接有什么相同的地方https://h5.pipix.com/bds/webapi/item/detail/?item_id=6854552706657294607https://cdn.jsdelivr.net/gh/xuezheli/Pic/usr/uploads/2020/08/849693573.png分析json代码太长我放到最后,主要是我们做接口获取的信息必须找到,例如作者名称,视频里面的文字,还有视频链接$ppx['name'] = $json->item->author->name; //获取作者名称$ppx['content'] = $json->item->content; //获取文字内容
$ppx['url'] = $json->item->origin_video_download->url_list->url;//获取视频链接PHP操作获取302跳转地址和视频idfunction getrealurl($url)
{
@$header = get_headers($url,1);
if (strpos($header,'301') || strpos($header,'302')) {
if(is_array($header['location'])) {
return $header['location'])-1];
}else{
return $header['location'];
}
}else {
return $url;
}
}
$url = "https://h5.pipix.com/s/JjyWG38/";
$ids= explode('/', parse_url(getrealurl($url))['path']);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
header('Access-Control-Allow-Origin:*');
header('Content-type:application/json; charset=utf-8');
function getrealurl($url)
{
@$header = get_headers($url,1);
if (strpos($header,'301') || strpos($header,'302')) {
if(is_array($header['location'])) {
return $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']);
$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->url;//获取视频链接
exit(stripslashes(json_encode($ppx,JSON_UNESCAPED_UNICODE)));
这么很ncie 大佬牛逼 1
666
1
{:6_174:}{:6_174:}{:6_174:} 6
111
页:
[1]