peixinchen / message
The message encoder/decoder for message queue, it would be encrypted/decrypted between the transmission.
1.0.0
2017-01-17 16:49 UTC
Requires (Dev)
- phpunit/phpunit: ^5.7
This package is not auto-updated.
Last update: 2024-10-21 16:07:52 UTC
README
编解码用于MessageQueue的消息体,同时进行加密
Installation 安装
- 使用 composer
$ composer require peixinchen/message
Tutorial 使用指导
- 初始化编码器
<?php use Peixinchen\Message\MessageCoder; // 加/解密算法 $cipher = 'blowfish'; // 密钥 $secretKey = 'some random key'; $coder = new MessageCoder($cipher, $secretKey);
- 编码
// 消息体版本,用于格式升级时做不同处理 $version = '1.0.0'; // 实际要传递的消息内容 $payload = [ 'id' => 1, 'text' => 'Some important message!', ]; $messageText = $coder->encode($version, $payload);
- 解码
list($version, $payload) = $coder->decode($messageText); // 1.0.0 var_dump($version); // [ // 'id' => 1, // 'text' => 'Some important message!', // ] var_dump($payload);