How to decode AS3 object encoded in AMF3 in PHP

岁酱吖の 提交于 2019-12-02 12:05:17

问题


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.

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.


回答1:


@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***************/



回答2:


You can use SabreAMF to encode/decode AMF data on PHP.




回答3:


Please take a look at this - https://github.com/neoxic/php-amf3 - this is a very reliable PHP extension for encoding/decoding AMF3 streams.



来源:https://stackoverflow.com/questions/12460689/how-to-decode-as3-object-encoded-in-amf3-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!