<?php namespace App\Http\Result; /** * api接口的响应 */ class ApiRst { public static $request_id = ''; protected static $rst = [ 'status' => 200, 'msg' => '', 'data' => [], 'error_type' => '2', 'timestamp' => 0 ]; public static function response($data, $err_msg = '',$error_type = '2') { if (is_array($data)) { self::$rst['data'] = $data; self::$rst['count'] = count($data); } else { $err = new ErrorCode($data); self::$rst['status'] = $err->getCode(); self::$rst['msg'] = $err->getMessage() . (empty($err_msg) ? '' : ( ':' . $err_msg )); self::$rst['data'] = []; // self::$rst['count'] = count($data); } self::$rst['timestamp'] = time(); self::$rst['request_id'] = self::$request_id; self::$rst['error_type'] = $error_type; return self::$rst; } }