1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
-
- namespace app\common\websocket;
-
-
- use app\common\enum\ChatMsgEnum;
-
- class Response
- {
-
-
- private function result(string $msg = 'OK', array $data = [], int $code = 10001)
- {
- $result = [
- 'code' => $code,
- 'msg' => $msg,
- 'data' => $data
- ];
- return $result;
- }
-
-
-
-
- public function success(string $msg = 'OK', array $data = [], int $code = 10001)
- {
- return $this->result($msg, $data, $code);
- }
-
-
-
-
- public function error(string $msg = 'Error', array $data = [], int $code = 20001)
- {
- return $this->result($msg, $data, $code);
- }
-
-
-
-
- public function formatSendError(string $msg, int $msg_type = 0)
- {
- if (empty($msg_type)) {
- $msg_type = ChatMsgEnum::TYPE_TEXT;
- }
-
- return [
- 'msg' => $msg,
- 'msg_type' => $msg_type,
- ];
- }
-
- }
|