/** * 输出amf格式的内容 * @param $result 需要输出到浏览器的内容 * @param $exit 是否在输出后结束脚本 * @return void */ function print_amf_result($result, $exit = true) { if ($GLOBALS['amfphp']['native'] === true && function_exists('amf_decode')) { $serializer = new AMFBaseSerializer(); // Create a serailizer around the output stream } else { $serializer = new AMFSerializer(); // Create a serailizer around the output stream } $body = new MessageBody('', '/1'); $body->responseURI = $body->responseIndex . "/onResult"; $body->setResults($result); $amfObj = new AMFObject(); $amfObj->addBody($body); $data = $serializer->serialize($amfObj); header('Content-type: application/x-amf'); $dateStr = date('D, j M Y H:i:s', time() - 86400); header("Expires: {$dateStr} GMT"); header('Pragma: no-store'); header('Cache-Control: no-store'); header('Content-length: ' . strlen($data)); echo $data; if ($exit) { exit; } }
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; }
function print_amf_result($result, $exit = true) { $serializer = new AMFBaseSerializer(); $body = new MessageBody('', '/1'); $body->responseURI = $body->responseIndex . "/onResult"; $body->setResults($result); $amfObj = new AMFObject(); $amfObj->addBody($body); $data = $serializer->serialize($amfObj); header("Content-type: application/x-amf"); $dateStr = date("D, j M Y ") . date("H:i:s", strtotime("-2 days")); header("Expires: {$dateStr} GMT"); header("Pragma: no-store"); header("Cache-Control: no-store"); header("Content-length: " . strlen($data)); echo $data; if ($exit) { exit; } }
/** * Adds debugging information to outgoing packet */ function debugFilter(&$amf) { //Add trace headers before outputting if (!$GLOBALS['amfphp']['isFlashComm'] && !$GLOBALS['amfphp']['disableTrace']) { $headerresults = array(); // create a result array $headerresults[0] = array(); // create a sub array in results (CF seems to do this, don't know why) if (count(NetDebug::getTraceStack()) != 0) { $ts = NetDebug::getTraceStack(); $headerresults[0][] = new TraceHeader($ts); } if (Headers::getHeader("serviceBrowser") == true) { global $amfphp; $amfphp['totalTime'] = microtime_float() - $amfphp['startTime']; $headerresults[0][] = new ProfilingHeader(); } //Get the last body in the stack if (count($headerresults[0]) > 0) { $body =& $amf->getBodyAt($amf->numBody() - 1); $headers = new MessageBody(NULL, $body->responseIndex, NULL); // create a new amf body $headers->responseURI = $body->responseIndex . "/onDebugEvents"; // set the response uri of this body $headers->setResults($headerresults); // set the results. $amf->addBodyAt(0, $headers); } } }