問題描述
我正在嘗試在 PHP 中解碼通過套接字從 Flash 發送的對象.我嘗試使用 AMFPHP 和 ZEND_AMF,但都沒有奏效.
I am trying to decode an object sent through sockets from Flash in PHP. I tried using AMFPHP and ZEND_AMF but neither did worked.
有人可以指出我在不使用 AMFPHP 的遠程功能的情況下在 php 中解碼 AMF3 編碼對象的方法嗎?數據是通過套接字發送的,所以我不能像通常 amfphp 那樣使用遠程對象.
Can someone point me to the way of decoding the AMF3 encoded objects in php without using remote functionality of the AMFPHP? Data is send thorough sockets, so I cannot use the remote objects as usually amfphp works.
推薦答案
@Ivan Dyachenko 感謝您指出 SabreAMF下面是我在套接字上成功解碼和映射從 Flex/Flash 接收到的 AMF3 編碼對象的方法
@Ivan Dyachenko Thanks for pointing towards SabreAMF Below is the way I successfully decoded and mapped the AMF3 encoded object received from Flex/Flash on sockets
include_once 'SabreAMF/AMF3/Serializer.php';
include_once 'SabreAMF/AMF3/Deserializer.php';
include_once 'SabreAMF/OutputStream.php';
include_once 'SabreAMF/InputStream.php';
include_once 'SabreAMF/TypedObject.php';
include_once 'SabreAMF/ClassMapper.php';
/************DECODER*****************/
SabreAMF_ClassMapper::registerClass('FLASH_CLASS_NAME','PHP_CLASS_NAME'); //CLASSES SHOULD BE SAME
$inputStream = new SabreAMF_InputStream($buffer);
$des = new SabreAMF_AMF3_Deserializer($inputStream);
$obj = $des->readAMFData();
//$obj will contain the instance of PHP_CLASS_NAME with the properties set as the values sent by Flex/Flash
/************END DECODER*****************/
/**************ENCODER******************/
$classObj = new PHP_CLASS(); //PHP_CLASS is your class
$object = new SabreAMF_TypedObject('FLASH_CLASS_NAME',$classObj); //FLASH_CLASS_NAME IS NAME OF CLASS AVAILABLE TO FLASH FOR MAPPING
$outputStream = new SabreAMF_OutputStream();
$serializer = new SabreAMF_AMF3_Serializer($outputStream);
$serializer->writeAMFData($object);
$output = $outputStream->getRawData();
//$output is AMF Encoded string to be sent to FLEX/FLASH.
/***********END ENCODER***************/
這篇關于如何在PHP中解碼以AMF3編碼的AS3對象的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!