Пример #1
0
function rpc($reqs, $progress = true)
{
    global $ua, $ch, $swfurl, $cookies, $rpcseq, $rpcmax;
    global $debugout;
    $offset = 0;
    $resps = array();
    while (true) {
        $n = min(count($reqs) - $offset, $rpcmax);
        if ($n == 0) {
            break;
        }
        $req = array(gen_header(), array_slice($reqs, $offset, $n), 0);
        $offset += $n;
        ++$rpcseq;
        $body = new MessageBody();
        $body->setResponseURI("BaseService.dispatchBatch");
        $body->setResponseTarget("/{$rpcseq}");
        $body->setResults($req);
        $amf = new AMFObject();
        $amf->addBody($body);
        $serializer = new AMFSerializer();
        $postdata = $serializer->serialize($amf);
        if ($debugout) {
            file_put_contents("out/{$rpcseq}.req", $postdata);
        }
        curl_setopt_array($ch, array(CURLOPT_POST => true, CURLOPT_BINARYTRANSFER => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_USERAGENT => $ua, CURLOPT_REFERER => $swfurl, CURLOPT_COOKIE => $cookies, CURLOPT_POSTFIELDS => $postdata));
        $out = curl_exec($ch);
        if ($debugout) {
            file_put_contents("out/{$rpcseq}.resp", $out);
        }
        if ($progress) {
            print ".";
        }
        $amf = new AMFObject($out);
        $deserializer = new AMFDeserializer($amf->rawData);
        // deserialize the data
        $deserializer->deserialize($amf);
        // run the deserializer
        $v = $amf->getBodyAt(0)->getValue();
        if ($v['errorType'] != 0) {
            die($v['errorData'] . "\n");
        }
        $resps = array_merge($resps, $v['data']);
    }
    return $resps;
}