PHP code example of peixinchen / message

1. Go to this page and download the library: Download peixinchen/message library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

peixinchen / message example snippets




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);