easyswoole 返回给客户端数据格式

引入状态类:   
use EasySwoole\Http\Message\Status;
具体代码
 /**
     * 业务处理成功返回
     * @param null $data
     * @param string $msg
     * @return bool
     * @throws ConnectFail
     * @throws OrderByFail
     * @throws PrepareQueryFail
     * @throws Throwable
     */
    protected function apiSuccess($data = null, $msg = '操作成功!')
    {
        $this->sendJson(Status::CODE_OK, $msg, $data);
        return true;
    }

    /**
     * 返回给客户端
     * @param $code
     * @param $msg
     * @param $date
     * @return bool
     */
    public function sendJson($code,$msg,$date)
    {
        $result = array(
            'code'=>$code,
            'messsage'=>$msg
        );
        if($date){
            $result['date'] = $date;
        }
        $this->response()->write(json_encode($result, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
        $this->response()->withHeader('Content-type', 'application/json;charset=utf-8');
        $this->response()->withStatus(intval($code));
        return true;
    }

你可能感兴趣的:(easyseoole,php)