Thread: [Solved] Call removeLinks in API
View Single Post
  #3  
Old 16.05.2018, 07:59
contertulio
Guest
 
Posts: n/a
Default

Code:
$links="1526450046583";//UUID for delete
$this->callAction("/downloadsV2/removeLinks",$links);

function callAction( $action, $params = false) {
        if( !is_array( $this -> devices)) {
            $this -> enumerateDevices();
        }
        if( !is_array( $this -> devices) || ( count( $this -> devices) == 0)) {
            return false;
        }
        foreach( $this -> devices as $i => &$ivalue) {
            if( $this -> devices[$i]["name"] == $this->getDeviceName()) {
                $device_id = $this -> devices[$i]["id"];
            }
        }
        if( !isset( $device_id)) {
            return false;
        }
        $query = "/t_".urlencode( $this -> sessiontoken)."_".urlencode( $device_id).$action;
        if( $params != "") {
            if(is_array($params)) {
                $params = str_replace('"', '\"', substr(json_encode($params),1,-1));
            }
            $json_data = '{"url":"'.$action.'","params":["{'.$params.'}"],"rid":'.$this -> getUniqueRid().',"apiVer":'.$this -> apiVer.'}';
        } else {
            $json_data = '{"url":"'.$action.'","rid":'.$this -> getUniqueRid().',"apiVer":'.$this -> apiVer.'}';
        }
        $json_data = $this -> encrypt( $json_data, $this -> deviceEncryptionToken);
        $url = $this -> api_url.$query;
        $res = $this -> postQuery( $url, $json_data, $this -> deviceEncryptionToken);
        if( $res === false) {
            return false;
        }
        $content_json = json_decode( $res, true);
        if( $content_json["rid"] != $this -> rid_counter) {
            return false;
        }
        return $content_json;
    }
function postQuery( $url, $postfields = false, $iv_key = false) {
        $ch = curl_init();
        curl_setopt( $ch, CURLOPT_URL, $url);
        curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
        if( $postfields) {
            $headers[] = "Content-Type: application/aesjson-jd; charset=utf-8";
            curl_setopt( $ch, CURLOPT_POST, true);
            curl_setopt( $ch, CURLOPT_POSTFIELDS, $postfields);
            curl_setopt( $ch, CURLOPT_HEADER, true);
            curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
        }
        $response = array();
        $response["text"] = curl_exec( $ch);
        $response["info"] = curl_getinfo( $ch);
        $response["code"] = $response["info"]["http_code"];
        if( $response["code"] != 200) {
            return false;
        }
        if( $postfields) {
            $response["body"] = substr( $response["text"], $response["info"]["header_size"]);
        } else {
            $response["body"] = $response["text"];
        }
        if( $iv_key) {
            $response["body"] = $this -> decrypt( $response["body"], $iv_key);
        }
        curl_close( $ch);
        return $response["body"];
    }

Last edited by contertulio; 16.05.2018 at 08:01.
Reply With Quote