From 2ade8861c96be89c7dbda38b22ef8e972f594a6a Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Thu, 5 Apr 2018 17:07:36 +0800 Subject: [PATCH] =?UTF-8?q?aria2=E4=B8=8B=E8=BD=BD=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E5=AE=8C=E6=88=90=EF=BC=8C=E5=B9=B6=E4=B8=94=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E8=BF=9C=E7=A8=8B=E6=9C=8D=E5=8A=A1=E7=AB=AF?= =?UTF-8?q?path=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index/controller/RemoteDownload.php | 1 + application/index/model/Aria2.php | 42 ++++++++++++++++++- public/downloads/.gitignore | 2 + static/js/qiniu.js | 2 + 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 public/downloads/.gitignore diff --git a/application/index/controller/RemoteDownload.php b/application/index/controller/RemoteDownload.php index 2b3ef331..af749e74 100644 --- a/application/index/controller/RemoteDownload.php +++ b/application/index/controller/RemoteDownload.php @@ -35,6 +35,7 @@ class RemoteDownload extends Controller{ } $aria2Options = Option::getValues(["aria2"]); $aria2 = new Aria2($aria2Options); + $downloadStart = $aria2->addUrl(input("post.url")); } } \ No newline at end of file diff --git a/application/index/model/Aria2.php b/application/index/model/Aria2.php index 68d037e8..d01446e7 100644 --- a/application/index/model/Aria2.php +++ b/application/index/model/Aria2.php @@ -6,9 +6,49 @@ use think\Db; class Aria2 extends Model{ - + private $authToken; + private $apiUrl; + private $savePath; + private $saveOptions; + public $reqStatus; + public $reqMsg; + public function __construct($options){ + $this->authToken = $options["aria2_token"]; + $this->apiUrl = rtrim($options["aria2_rpcurl"],"/")."/"; + $this->saveOptions = json_decode($options["aria2_options"],true); + $this->savePath = $options["aria2_tmppath"]; + } + + public function addUrl($url){ + //{"params": ["token:123123132",["https://www.baidu.com/img/baidu_jgylogo3.gif"],{"dir":"../"}], "jsonrpc": "2.0", "id": "qer", "method": "aria2.addUri"} + $reqFileds = [ + "params" => ["token:".$this->authToken,[ + $url,["dir" => $this->savePath], + ]], + "jsonrpc" => "2.0", + "id" => uniqid(), + "method" => "aria2.addUri" + ]; + $reqFileds["params"][1][1] = array_merge($reqFileds["params"][1][1],$this->saveOptions); + $reqFileds = json_encode($reqFileds,JSON_OBJECT_AS_ARRAY); + $respondData = $this->sendReq($reqFileds); + } + private function sendReq($data){ + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, $this->apiUrl."jsonrpc"); + curl_setopt($curl, CURLOPT_POST, 1); + curl_setopt($curl, CURLOPT_POSTFIELDS, $data); + curl_setopt($curl, CURLOPT_TIMEOUT, 15); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + $tmpInfo = curl_exec($curl); // 执行操作 + if (curl_errno($curl)) { + $this->reqStatus = 0; + $this->reqMsg = "请求失败,".curl_error($curl); + } + curl_close($curl); // 关闭CURL会话 + return json_decode($tmpInfo); // 返回数据,json格式 } } diff --git a/public/downloads/.gitignore b/public/downloads/.gitignore new file mode 100644 index 00000000..c96a04f0 --- /dev/null +++ b/public/downloads/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/static/js/qiniu.js b/static/js/qiniu.js index c6d01ae7..2800307f 100644 --- a/static/js/qiniu.js +++ b/static/js/qiniu.js @@ -1501,6 +1501,8 @@ function QiniuJsSDK() { local_path = '/path/'+that.URLSafeBase64Encode(pathTmp); } if(uploadConfig.saveType == "remote"){ + pathTmp = file.path; + local_path = that.URLSafeBase64Encode(pathTmp); var url = qiniuUploadUrl + 'mkfile.php?size=' + file.size +"&key="+ key+"&fname="+ fname +"&path="+local_path; }else{ var url = qiniuUploadUrl + '/mkfile/' + file.size + key + fname + x_vars_url+local_path;