msgType = $msgType; return $this; } /** * 设置内容 * * @param array|Message $content 内容 * @return static */ protected function withContent($content): static { $this->content = $content; return $this; } /** * 设置消息 * * @param string $message 消息 * @return static */ protected function withMessage(string $message): static { $this->message = $message; return $this; } /** * 设置状态码 * * @param int $code 状态码 * @return static */ protected function withCode(int $code): static { $this->code = $code; return $this; } /** * 构建protobuf响应 * * @return array */ protected function build(): array { return [ 'MsgType' => $this->msgType, 'Content' => $this->content ]; } /** * 构建正常响应 * * @return array */ protected function response(): array { return [ 'Code' => $this->code, 'Message' => $this->message ?: ResponseCode::getMessage($this->code), 'Data' => [ 'MsgType' => $this->msgType, 'Content' => $this->content ] ]; } }