我正在尝试解码从PHP中通过套接字发送的对象。 我尝试过使用AMFPHP和ZEND_AMF,但都没有用。
有人能指出我在不使用AMFPHP远程功能的情况下解码php中AMF3编码对象的方法吗? 数据是通过套接字发送的,所以我不能像amfphp那样使用远程对象。
答案 0 :(得分:2)
@Ivan Dyachenko感谢您指向SabreAMF 下面是我成功解码和映射从套接字上的Flex / Flash接收的AMF3编码对象的方式
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***************/
答案 1 :(得分:1)
您可以使用SabreAMF对PHP上的AMF数据进行编码/解码。
答案 2 :(得分:0)
请看一下 - https://github.com/neoxic/php-amf3 - 这是一个非常可靠的PHP扩展,用于编码/解码AMF3流。