|
|
@ -12,27 +12,36 @@ class Aria2 extends Model{
|
|
|
|
private $saveOptions;
|
|
|
|
private $saveOptions;
|
|
|
|
public $reqStatus;
|
|
|
|
public $reqStatus;
|
|
|
|
public $reqMsg;
|
|
|
|
public $reqMsg;
|
|
|
|
|
|
|
|
public $pathId;
|
|
|
|
|
|
|
|
public $pid;
|
|
|
|
|
|
|
|
|
|
|
|
public function __construct($options){
|
|
|
|
public function __construct($options){
|
|
|
|
$this->authToken = $options["aria2_token"];
|
|
|
|
$this->authToken = $options["aria2_token"];
|
|
|
|
$this->apiUrl = rtrim($options["aria2_rpcurl"],"/")."/";
|
|
|
|
$this->apiUrl = rtrim($options["aria2_rpcurl"],"/")."/";
|
|
|
|
$this->saveOptions = json_decode($options["aria2_options"],true);
|
|
|
|
$this->saveOptions = json_decode($options["aria2_options"],true);
|
|
|
|
$this->savePath = $options["aria2_tmppath"];
|
|
|
|
$this->savePath = rtrim(rtrim($options["aria2_tmppath"],"/"),"\\").DS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function addUrl($url){
|
|
|
|
public function addUrl($url){
|
|
|
|
//{"params": ["token:123123132",["https://www.baidu.com/img/baidu_jgylogo3.gif"],{"dir":"../"}], "jsonrpc": "2.0", "id": "qer", "method": "aria2.addUri"}
|
|
|
|
$this->pathId = uniqid();
|
|
|
|
$reqFileds = [
|
|
|
|
$reqFileds = [
|
|
|
|
"params" => ["token:".$this->authToken,[
|
|
|
|
"params" => ["token:".$this->authToken,
|
|
|
|
$url,["dir" => $this->savePath],
|
|
|
|
[$url],["dir" => $this->savePath.$this->pathId],
|
|
|
|
]],
|
|
|
|
],
|
|
|
|
"jsonrpc" => "2.0",
|
|
|
|
"jsonrpc" => "2.0",
|
|
|
|
"id" => uniqid(),
|
|
|
|
"id" => $this->pathId,
|
|
|
|
"method" => "aria2.addUri"
|
|
|
|
"method" => "aria2.addUri"
|
|
|
|
];
|
|
|
|
];
|
|
|
|
$reqFileds["params"][1][1] = array_merge($reqFileds["params"][1][1],$this->saveOptions);
|
|
|
|
$reqFileds["params"][2] = array_merge($reqFileds["params"][2],$this->saveOptions);
|
|
|
|
$reqFileds = json_encode($reqFileds,JSON_OBJECT_AS_ARRAY);
|
|
|
|
$reqFileds = json_encode($reqFileds,JSON_OBJECT_AS_ARRAY);
|
|
|
|
$respondData = $this->sendReq($reqFileds);
|
|
|
|
$respondData = $this->sendReq($reqFileds);
|
|
|
|
|
|
|
|
if(isset($respondData["result"])){
|
|
|
|
|
|
|
|
$this->reqStatus = 1;
|
|
|
|
|
|
|
|
$this->pid = $respondData["result"];
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
$this->reqStatus = 0;
|
|
|
|
|
|
|
|
$this->reqMsg = $respondData["error"]["message"];
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private function sendReq($data){
|
|
|
|
private function sendReq($data){
|
|
|
@ -42,13 +51,13 @@ class Aria2 extends Model{
|
|
|
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
|
|
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
|
|
|
curl_setopt($curl, CURLOPT_TIMEOUT, 15);
|
|
|
|
curl_setopt($curl, CURLOPT_TIMEOUT, 15);
|
|
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
$tmpInfo = curl_exec($curl); // 执行操作
|
|
|
|
$tmpInfo = curl_exec($curl);
|
|
|
|
if (curl_errno($curl)) {
|
|
|
|
if (curl_errno($curl)) {
|
|
|
|
$this->reqStatus = 0;
|
|
|
|
$this->reqStatus = 0;
|
|
|
|
$this->reqMsg = "请求失败,".curl_error($curl);
|
|
|
|
$this->reqMsg = "请求失败,".curl_error($curl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
curl_close($curl); // 关闭CURL会话
|
|
|
|
curl_close($curl);
|
|
|
|
return json_decode($tmpInfo); // 返回数据,json格式
|
|
|
|
return json_decode($tmpInfo,true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|