前言
最近夸克网盘推广很火,晓杰就研究了下夸克自动转存!
代码
Quark.php
<?php
class Quark
{
private $cookie ="夸克网盘CK";
public function getShareInfo($shareUrl){
preg_match('|\/s\/(\w+)|',$shareUrl,$shareUrlArr);
if (empty($shareUrlArr[1])){
return false;
}
$code = $shareUrlArr[1];
$md5 = md5($code.'Kuakewangpan&^*') ;
$header[]="Content-Type: application/json";
$header[]="Accept: application/json, text/plain, */*";
$header[]="Cache-Control: no-cache";
$header[]="Host: drive-pc.quark.cn";
$header[]="User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36";
$header[]="Referer: ".$shareUrl;
$postUrl="https://drive-pc.quark.cn/1/clouddrive/share/sharepage/token?pr=ucpro&fr=pc&uc_param_str=&__dt=".$this::random_str(3,1)."&__t=".$this::getMillisecond();
$postdata = '{"pwd_id":"'.$code.'","passcode":""}';
$data = $this::getCurl($postUrl,$postdata,$this->cookie,$header);
$dataArr =json_decode($data,true);
if ($dataArr['status']==200){
$stoken = $dataArr['data']['stoken'];
$title = $dataArr['data']['title'];
$selectCount = db('netdisk')->where(array(
'title'=>$title,
'type'=>1
))
->count();
if ($selectCount>=1){
return true;
}
$postUrl ="https://drive-pc.quark.cn/1/clouddrive/file/search?pr=ucpro&fr=pc&uc_param_str=&q=".urlencode($title)."&_page=1&_size=50&_fetch_total=1&_sort=file_type:desc,updated_at:desc&_is_hl=1";
$data = $this::getCurl($postUrl,0,$this->cookie,$header);
$dataArr =json_decode($data,true);
$sscount = sizeof($dataArr['data']['list']);
for ($s=0;$s<$sscount;$s++){
$pdir_fid = $dataArr['data']['list'][$s]['pdir_fid'];
if("d00391b750c84d3fa5f137a826409c42"==$pdir_fid){
$newFileId = $dataArr['data']['list'][$s]['fid'];
break;
}
}
if (!empty($newFileId)){
goto a;
}
$postUrl = "https://drive-pc.quark.cn/1/clouddrive/share/sharepage/detail?pr=ucpro&fr=pc&uc_param_str=&pwd_id={$code}&stoken=".urlencode($stoken)."&pdir_fid=0&force=0&_page=1&_size=50&_fetch_banner=1&_fetch_share=1&_fetch_total=1&_sort=file_type:asc,updated_at:desc&__dt=".$this::random_str(4,1)."&__t=".$this::getMillisecond();
$data1 = $this::getCurl($postUrl,0,$this->cookie,$header);
$dataArr1 =json_decode($data1,true);
if ($dataArr1['status']==200){
if (empty($dataArr1['data']['list'][0]['fid'])){
return false;
}
$fid_list = $dataArr1['data']['list'][0]['fid'];
$fid_token_list = $dataArr1['data']['list'][0]['share_fid_token'];
$postdata ="{\"fid_list\":[\"$fid_list\"],\"fid_token_list\":[\"$fid_token_list\"],\"to_pdir_fid\":\"d00391b750c84d3fa5f137a826409c42\",\"pwd_id\":\"$code\",\"stoken\":\"$stoken\",\"pdir_fid\":\"0\",\"scene\":\"link\"}";
$randomTime=$this::random_str(5,1);
$postUrl="https://drive-pc.quark.cn/1/clouddrive/share/sharepage/save?pr=ucpro&fr=pc&uc_param_str=&__dt=".$randomTime."&__t=".$this::getMillisecond();
$data = $this::getCurl($postUrl,$postdata,$this->cookie,$header);
$dataArr =json_decode($data,true);
if ($dataArr['status']==200){
$ss=0;
do{
sleep(2);
$task_id = $dataArr['data']['task_id'];
$randomTime= $randomTime +$this::random_str(4,1);
$postUrl ="https://drive-pc.quark.cn/1/clouddrive/task?pr=ucpro&fr=pc&uc_param_str=&task_id=$task_id&retry_index=0&__dt=".$randomTime."&__t=".$this::getMillisecond();
$data = $this::getCurl($postUrl,0,$this->cookie,$header);
$dataArr =json_decode($data,true);
if ($dataArr['data']['status']==3){
return false;
}
$ss++;
}while($ss<2 && empty($dataArr['data']['save_as']['save_as_top_fids'][0]));
if ($dataArr['status']==200 && !empty($dataArr['data']['save_as']['save_as_top_fids'][0])){
$newFileId = $dataArr['data']['save_as']['save_as_top_fids'][0];
a :
$postUrl = "https://drive-pc.quark.cn/1/clouddrive/share?pr=ucpro&fr=pc&uc_param_str=";
$postdata = "{\"fid_list\":[\"$newFileId\"],\"title\":\"$title\",\"url_type\":1,\"expired_type\":1}";
$data = $this::getCurl($postUrl,$postdata,$this->cookie,$header);
$dataArr =json_decode($data,true);
if ($dataArr['status']==200 && !empty($dataArr['data']['task_id'])){
sleep(1);
$task_id = $dataArr['data']['task_id'];
$postUrl = "https://drive-pc.quark.cn/1/clouddrive/task?pr=ucpro&fr=pc&uc_param_str=&task_id=$task_id&retry_index=1";
$data = $this::getCurl($postUrl,0,$this->cookie,$header);
$dataArr =json_decode($data,true);
if ($dataArr['status']==200 && !empty($dataArr['data']['share_id'])){
$share_id=$dataArr['data']['share_id'];
$postUrl = "https://drive-pc.quark.cn/1/clouddrive/share/password?pr=ucpro&fr=pc&uc_param_str=";
$postdata = "{\"share_id\":\"$share_id\"}";
$data = $this::getCurl($postUrl,$postdata,$this->cookie,$header);
$dataArr =json_decode($data,true);
if ($dataArr['status']==200 && !empty($dataArr['data']['share_url'])){
$share_url = $dataArr['data']['share_url'];
$newTitle = $dataArr['data']['title'];
$newCode = $dataArr['data']['pwd_id'];
$dbArr = array(
'title'=>$title,
'code'=>$code,
'url'=>$shareUrl,
'md5'=>$md5,
'new_code'=>$newCode,
'new_title'=>$newTitle,
'new_url'=>$share_url,
'file_id'=>$newFileId,
'type'=>1,
);
db('netdisk')->insert($dbArr,true);
return $dbArr;
}else{
return false;
}
}else{
return false;
}
}else{
return false;
}
}else{
return false;
}
}else{
return false;
}
}else{
return false;
}
}else{
return false;
}
}
public static function getCurl($url, $post = 0, $cookie = 0, $isIp=0,$header = 0, $nobaody = 0, $method = 'GET'){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
if (!empty($isIp)){
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
if ($post==1) {
curl_setopt($ch, CURLOPT_POST, 1);
}elseif($post){
if ($method !='PUT'){
$method = 'POST';
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
}
if ($header) {
curl_setopt($ch, CURLOPT_HEADER, true);
}
if ($cookie) {
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
}
if ($nobaody) {
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;
}
}
SQL
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for fxw_netdisk
-- ----------------------------
DROP TABLE IF EXISTS `soujer_netdisk`;
CREATE TABLE `soujer_netdisk` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`url` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
`md5` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
`title` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
`create_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP(0),
`code` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
`pwd` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
`new_title` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
`new_url` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
`type` int(1) NULL DEFAULT NULL COMMENT '1夸克网盘2UC网盘',
`new_code` varchar(25) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
`new_pwd` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
`file_id` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `11`(`md5`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 36604 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
SET FOREIGN_KEY_CHECKS = 1;
Gitee
https://gitee.com/Soujer/quarkService
本文作者
Soujer 晓杰
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。