param('code'); if (empty($code)) { $this->error('没有接口编码'); } if (empty(ClientApiConstants::APP_PATH_MAPPING[$code])) { $this->error('没有找到对应的接口,code:' . $code); } $apiPath = ClientApiConstants::APP_PATH_MAPPING[$code]; try { action($apiPath); } catch (Exception $e) { LogService::exception($e); $this->error($e->getMessage()); } } /** * 操作失败返回的数据 * @param string $msg 提示信息 * @param int $code 错误代码 * @param mixed $data 要返回的数据 * @param array $header 发送的 Header 信息 */ protected function error( $msg = '', $code = ClientApiConstants::CLIENT_API_CODE_FAIL, $data = [], array $header = [] ) { if (empty($msg)) { if (isset(ClientApiConstants::$errMsgList[$code])) { $msg = ClientApiConstants::$errMsgList[$code]; } } $result = [ 'code' => $code, 'msg' => $msg, 'time' => Request::instance()->server('REQUEST_TIME'), 'data' => $data, ]; if (empty($result['data'])) { $result['data'] = new \ArrayObject(array()); } $response = Response::create($result, 'json')->header($header); throw new HttpResponseException($response); } }