封装一个php语言的api提示类
<?php namespace App\Extensions; class ApiNoticeUtils { //通用请求 const RECODE_SUCCESS = 200; const RECODE_REQUESTFAIL = 1; const RECODE_PARAMERR = 506; //.... //订单相关 //系统错误 const RECODE_SYSTEMARR = 500; public static $notice_msg = [ self::RECODE_SUCCESS => '请求成功', self::RECODE_REQUESTFAIL => '请求失败', self::RECODE_PARAMERR => '请求参数缺失或错误', //..... self::RECODE_SYSTEMARR => '系统错误' ]; public static function noticeMsg (int $notice_code, array $data = [] ) { if(!isset(self::$notice_msg[$notice_code])) { $notice_code = self::RECODE_SYSTEMARR; } $result = [ 'code' => $notice_code, 'message' => self::$notice_msg[$notice_code] ]; if ($data) { foreach ($data as $k => $v) { $result['data'][$k] = $v; } } return $result; } }