You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
722 B
37 lines
722 B
<?php
|
|
|
|
namespace app\common\websocket;
|
|
|
|
|
|
class Parser
|
|
{
|
|
/**
|
|
* @notes 数组数据转json
|
|
* @param string $event
|
|
* @param $data
|
|
* @return false|string
|
|
* @author 段誉
|
|
* @date 2021/12/29 18:27
|
|
*/
|
|
public function encode(string $event, $data)
|
|
{
|
|
return json_encode(['event' => $event, 'data' => $data]);
|
|
}
|
|
|
|
/**
|
|
* @notes json转数组数据
|
|
* @param $data
|
|
* @return array
|
|
* @author 段誉
|
|
* @date 2021/12/29 18:28
|
|
*/
|
|
public function decode($data)
|
|
{
|
|
$result = json_decode($data, true);
|
|
return [
|
|
'event' => $result['event'] ?? null,
|
|
'data' => $result['data'] ?? null,
|
|
];
|
|
}
|
|
|
|
}
|
|
|