How to decode AS3 object encoded in AMF3 in PHP(如何在PHP中解码以AMF3编码的AS3对象)
问题描述
我正在尝试在 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对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在PHP中解码以AMF3编码的AS3对象
基础教程推荐
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- HTTP 与 FTP 上传 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01