重新设计状态码规范

This commit is contained in:
2026-03-05 13:44:56 +08:00
parent 8d8cee696f
commit 5ab16243bd
6 changed files with 46 additions and 33 deletions

View File

@@ -4,19 +4,32 @@ declare(strict_types=1);
namespace app\api\util;
/**
* API 状态码统一管理
* API 统一状态码
* 与 HTTP 语义对齐,便于前端与网关处理
*/
class ReturnCode
{
/** 200 成功 */
public const SUCCESS = 200;
/** 201 请携带 tokenauth-token / user-token */
public const MISSING_TOKEN = 201;
/** 400 请求参数错误(缺少参数、参数无效、格式错误等 */
public const PARAMS_ERROR = 400;
/** 202 缺少参数 / 参数错误 / 业务校验不通过(如余额不足、购买抽奖券错误等 */
public const EMPTY_PARAMS = 202;
/** 401 未授权(未携带 auth-token 或 user-token */
public const UNAUTHORIZED = 401;
/** 203 token 过期或无效auth-token / user-token 过期、缓存已过期等) */
public const TOKEN_TIMEOUT = 203;
/** 402 token 无效或已过期(格式无效、签名错误、过期、非当前有效 token 等) */
public const TOKEN_INVALID = 402;
/** 403 鉴权失败(密钥错误、签名验证失败等) */
public const FORBIDDEN = 403;
/** 404 资源不存在(用户不存在等) */
public const NOT_FOUND = 404;
/** 422 业务逻辑错误(余额不足、购买失败、业务校验不通过等) */
public const BUSINESS_ERROR = 422;
/** 500 服务器内部错误 */
public const SERVER_ERROR = 500;
}