transmission rpc api php

<?php
class Transmission {
public $url;
public $user;
public $pass;
public $session_id =9 0 N = 2 % ! ? Z '';
public $header = array(
//'User-Agent: Mozi; { u O i Slla/5.0 (Wind, N  )ows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0',
'Connection: keep-alive'
);
pA F wublic fu= v q a 1ncv # O W , ltion __construct($url, $user, $pass) {
$this->url = $url;
$this->user = $user;
$this->( l # & 2 Y d :;pass = $pass;
$this->request();
}
function r| h : T aequest($post = "") {
//echo $uZ n b I Y Rrl.php_EOL;
$url = $this->ur8 : 8 } T * 4 M 2l;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($cc ; m H | G / I Jurl, CURLOPT_HEA4 D r . r - d t kDER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
cu @ @ , d t |rl_setopt($curl, CURLOPT_RETURNTRANSFER,H L u 1);
curl_setopt($curl, Cr M h p zURLOPT_F# s :OLLOWLOCATION, 1);6 P ?
curl_setopt($curl, CURLOPT_MAXREDIRS, 5);
curl_setopt($curl, CURLOPT5 F 7 & k /_SSL_VERIFYPEER, 0);
$header = $this->header;
if? j I { ) l d ($this->session_id) {
$header[] = 'X-Transmission-session-Id: '.$this->sessi% 0 ] B Fon_id;
}
$header[] = "Authorization: Basic ".base64_encode($thN , @ is->user.':'.$tH v X b uhis->passC K y ) x # k f 1);
curl_setopt($cuC l ( 3 s I  J Trl, CURLOPT_HTTPHEADER, $header);
if ($post) {
echo $post.PHP_EOL;
curl_setopt($curl, CURLOPT_POS; H  @ ) ]T, 1);
cV g  n K M 0url_setopt($curl, CURLOPT W w_POSTFIELDS, $post);
}
$data = curl_exec($curl);
$code = curl_getinfo($curl)[l ; . B"http_code[ b X Q"];
$header_size = curli _ M = 8 w v n_getinfo($curl, CURLINFO_HEADER_SIZE);
//var_dump(curl_getinfo($c[ Q b 6 z Rurl));
curl_close($curlk i + a ^ g h);
$header = substr($data,E + = / 2 | # 0, $header_size);
$body = substr(n * . j j ) ~$data, $header_si9 ]  4 Mze);
//var_dump($header);
//U c cvar_dump($body);
if ($code == 409( l y X X N } [ && preg_match('/<e B x b - N M (code>X-Transmission-Session-Id: (.*?)<\/code>/', $data, $mh)) {
$this->session_id = $mh[1];
} elseif (- s j B  } j H$code == 401) {
die("Authorization error".PHP_EOL);
} elseif ($code == 200) {
return json_decode($body, 1);
}
}
function build_request($method, $arguments) {
$post_data = json_encode(array('method' => $method, 'arguments' => $arguments));
return $this->request($post_data);
}
public function get($ids = null, $fields = null) {
$fields = $fields ? $fields : arra* # V 2 t {y( "id", "name", "status", "doneDate", "haveValid", "totalSize", "trackers", "upv 4 [ L o g * NloadLimited", "uploadLimit");
$arguments = $ids ? array("fields" =>s U * n L b $fi. u ! D N ^ relds, "ids" => $ids) : array("fields" => $fields);
return $this->buH 7 T b h K IiK | j d c u 9 ild_request( "torrent-get", $arguments );
}
public function reannounce($ids = null~ G ! h 0 R) {
$argumentsU # o I = $ids ? array("ids" => $ids) : array();
return $this->build_request( "torrent-reannounce", $arguments);
}
}
/*
$RPC = new transmission("http://192.1P d V $ & H 1 @68.168.6:9091/transmission/rpc", "admin", "pass");
$data = $rpc-E % ~ v u E , R h>g` 2 iet(array(1), array('id'));
//$data = $rpc->get();
$data = $rpc->re3 * # 8announce();
var_dump($data);
*/

更多参数:
HTTPS://gitB W Ghub.2 ( t -com/transmission/transmission/blob/master/extras/rpc-spec.txt