douying/api/tuji.php
2021-07-17 16:03:34 +08:00

161 lines
6.4 KiB
PHP

<?php
header('Access-Control-Allow-Origin:*');
header('Content-type: application/json');
error_reporting(0);
$url = $_POST['url'];
if (!empty($url)) {
if (strpos($url, 'weibo') !== false) {
$data = file_get_contents($url);
preg_match('/\"pic_ids\":([\s\S]*)\]\,([\s\S]*)\"pic_types/', $data, $arr);
$img = json_decode($arr[1].']');
$images = array();
for ($i=0;$i<count($img);$i++) {
$none = 'https://lz.sinaimg.cn/oslarge/'.$img[$i].'.jpg';
array_push($images, $none);
}
if (!empty($arr)) {
$Json = array(
'code' => 200,
'msg' => 'success',
'count' => count($img),
'images' => $images
);
} else {
$Json = array(
'code' => 201,
'msg' => 'error',
);
}
} elseif (strpos($url, 'kuaishou') !== false) {
$loc = get_headers($url, 1)['Location'];
$url = curl($loc[0]);
preg_match('/imageCDN\":\"tx2.a.yximgs.com\",\"images\":(.*?)\],\"width/', $url, $arr);
$img = json_decode($arr[1].']', true);
$images = array();
for ($i=0;$i<count($img);$i++) {
$none = 'http://tx2.a.yximgs.com/'.$img[$i]['path'];
array_push($images, $none);
}
if (!empty($arr)) {
$Json = array(
'code' => 200,
'msg' => 'success',
'count' => count($img),
'images' => $images
);
} else {
$Json = array(
'code' => 201,
'msg' => 'error',
);
}
} elseif (strpos($url, 'douyin') !== false) {
print_r($url);
$loc = get_headers($url, 1)['location'];
print_r($loc);
preg_match('/video\/(.*)\//', $loc, $id);
$arr = json_decode(file_get_contents('https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids='.$id[1]), 1);
$images = $arr['item_list'][0]['video']['cover']['url_list'];
if (!empty($images)) {
$Json = array(
'code' => 200,
'msg' => 'success',
'count' => count($images),
'images' => $images
);
} else {
$Json = array(
'code' => 201,
'msg' => 'error',
);
}
} elseif (strpos($url, 'instagram') !== false) {
preg_match('/p\/(.*)\//', $url, $id);
$arr = json_decode(ins_curl('https://www.instagram.com/p/'.$id[1].'/?__a=1'), true);
$img = $arr['graphql']['shortcode_media']['edge_sidecar_to_children']["edges"];
$images = array();
for ($i=0;$i<count($img);$i++) {
$none = $img[$i]["node"]["display_resources"][0]["src"];
array_push($images, $none);
}
if (empty($images)) {
array_push($images, $arr['graphql']['shortcode_media']['display_url']);
}
if (!empty($images)) {
$Json = array(
'code' => 200,
'msg' => 'success',
'count' => count($img),
'images' => $images
);
} else {
$Json = array(
'code' => 201,
'msg' => 'error',
);
}
}
} else {
$Json = array(
'code' => 201,
'msg' => 'error',
);
}
$Json = json_encode($Json, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE);
echo stripslashes($Json);
return $Json;
function curl($url)
{
$ip = rand(0, 255) . '.' . rand(0, 255) . '.' . rand(0, 255) . '.' . rand(0, 255);
$header[] = "accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9";
$header[] = "accept-encoding: gzip, deflate, br";
$header[] = "accept-language: zh-CN,zh;q=0.9,en;q=0.8";
$header[] = "content-type: application/json";
$header[] = "Referer: ". $url;
$header[] = "Origin: ". $url;
$header[] = "CLIENT-IP:" . $ip;
$header[] = "X-FORWARDED-FOR:" . $ip;
$header[] = "Host: c.kuaishou.com";
$cookie = "cookie";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); //设置传输的 url
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); //发送 http 报头
curl_setopt($ch, CURLOPT_COOKIE, $cookie); //设置Cookie
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.114 Mobile Safari/537.36"); //设置UA
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); // 从证书中检查SSL加密算法是否存在
curl_setopt($ch, CURLOPT_TIMEOUT, 5); // 设置超时限制防止死循环
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
function ins_curl($url)
{
$ip = rand(0, 255) . '.' . rand(0, 255) . '.' . rand(0, 255) . '.' . rand(0, 255);
$header[] = "accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9";
$header[] = "accept-encoding: gzip, deflate, br";
$header[] = "accept-language: zh-CN,zh;q=0.9,en;q=0.8";
$header[] = "content-type: application/json";
$header[] = "Referer: ". $url;
$header[] = "Origin: https://www.instagram.com/";
$header[] = "CLIENT-IP:" . $ip;
$header[] = "X-FORWARDED-FOR:" . $ip;
$cookie = "cookie";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); //设置传输的 url
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); //发送 http 报头
curl_setopt($ch, CURLOPT_COOKIE, $cookie); //设置Cookie
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36"); //设置UA
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); // 从证书中检查SSL加密算法是否存在
curl_setopt($ch, CURLOPT_TIMEOUT, 5); // 设置超时限制防止死循环
$output = curl_exec($ch);
curl_close($ch);
return $output;
}