build(composer): 添加了错误码和对应的语言包

This commit is contained in:
李东云
2022-04-25 18:54:56 +08:00
parent 0773d7aa41
commit bf6afb70b5
5 changed files with 848 additions and 1 deletions

View File

@@ -6,8 +6,10 @@
"php": "~8.0",
"composer/composer": "*",
"ergebnis/http-method": "^2.2",
"hyperf/constants": "^2.2",
"hyperf/di": "^2.2",
"hyperf/http-server": "^2.2",
"hyperf/translation": "^2.2",
"lmc/http-constants": "^1.2",
"roave/dont": "^1.5",
"teapot/status-code": "^1.1"

122
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "4ff0e69f8e9c2f036a00df61379633c2",
"content-hash": "542ead4c79d684a5c1193d82a3a1c58e",
"packages": [
{
"name": "composer/ca-bundle",
@@ -1070,6 +1070,67 @@
],
"time": "2021-11-21T21:41:47+00:00"
},
{
"name": "hyperf/constants",
"version": "v2.2.15",
"source": {
"type": "git",
"url": "https://github.com/hyperf/constants.git",
"reference": "2cc989808defb6cf59feabdc0ca64a6600ed8b79"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/hyperf/constants/zipball/2cc989808defb6cf59feabdc0ca64a6600ed8b79",
"reference": "2cc989808defb6cf59feabdc0ca64a6600ed8b79",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"hyperf/di": "~2.2.0",
"hyperf/utils": "~2.2.0",
"php": ">=7.2"
},
"suggest": {
"hyperf/translation": "Required to use translation."
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.2-dev"
},
"hyperf": {
"config": "Hyperf\\Constants\\ConfigProvider"
}
},
"autoload": {
"psr-4": {
"Hyperf\\Constants\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "A constants component for hyperf.",
"homepage": "https://hyperf.io",
"keywords": [
"constants",
"hyperf",
"php"
],
"support": {
"docs": "https://hyperf.wiki",
"issues": "https://github.com/hyperf/hyperf/issues",
"pull-request": "https://github.com/hyperf/hyperf/pulls",
"source": "https://github.com/hyperf/hyperf"
},
"time": "2021-11-02T10:40:16+00:00"
},
{
"name": "hyperf/context",
"version": "v2.2.0",
@@ -1742,6 +1803,65 @@
},
"time": "2021-12-13T08:49:35+00:00"
},
{
"name": "hyperf/translation",
"version": "v2.2.13",
"source": {
"type": "git",
"url": "https://github.com/hyperf/translation.git",
"reference": "df8de58751b45626b0eb65d931a1511f0d9618c4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/hyperf/translation/zipball/df8de58751b45626b0eb65d931a1511f0d9618c4",
"reference": "df8de58751b45626b0eb65d931a1511f0d9618c4",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"hyperf/contract": "~2.2.0",
"hyperf/macroable": "~2.2.0",
"hyperf/utils": "~2.2.0",
"php": ">=7.2",
"psr/container": "^1.0|^2.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.2-dev"
},
"hyperf": {
"config": "Hyperf\\Translation\\ConfigProvider"
}
},
"autoload": {
"files": [
"src/Functions.php"
],
"psr-4": {
"Hyperf\\Translation\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "An independent translation component, forked by illuminate/translation.",
"keywords": [
"hyperf",
"translation"
],
"support": {
"issues": "https://github.com/hyperf/translation/issues",
"source": "https://github.com/hyperf/translation/tree/v2.2.13"
},
"time": "2021-10-25T01:29:21+00:00"
},
{
"name": "hyperf/utils",
"version": "v2.2.30",

View File

@@ -0,0 +1,163 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
return [
// 系统错误或未预期的错误
'server_error' => 'An internal error is occurred, try again later',
'program' => [
'default' => 'An internal error is occurred, try again later',
'syntax' => [
'default' => 'An internal error is occurred, try again later',
],
'sql' => [
'default' => 'An internal error is occurred, try again later',
'column_not_found' => 'An internal error is occurred, try again later',
'insert' => 'An internal error is occurred, try again later',
'update' => 'An internal error is occurred, try again later',
'delete' => 'An internal error is occurred, try again later',
],
],
// 参数校验
'params' => [
'method' => [
'default' => 'Reject request',
],
// 参数非法
'format_error' => 'Format error :param',
// 数据错误
'error' => [
'default' => 'Failed verification',
'user' => [
'default' => 'Format error, :reason',
'sec_email' => [
'unique' => 'Oops! This email address is already used',
'required' => '请传入安全邮箱',
'undefined' => '请先绑定',
],
'sec_phone' => [
'unique' => 'Oops! This phone is already used',
'required' => '请传入安全手机号码',
'undefined' => '请先绑定',
],
'username' => [
'unique' => 'Oops! This username is already used',
],
'sign_up' => [
'default' => 'An account with this email or phone already exists.',
],
'action' => [
'error' => 'This type of verification code is unexpected',
],
],
'code' => [
'error' => 'This verification code is incorrect or expired',
'timeout' => 'This verification code is incorrect or expired',
'limit' => [
'default' => 'SMS verification code has reached the upper limit today, please come back tomorrow. Any problem, please contact our customer service.',
'day' => 'SMS verification code has reached the upper limit today, please come back tomorrow. Any problem, please contact our customer service.',
'hour' => 'SMS verification code has reached the upper limit today, please come back tomorrow. Any problem, please contact our customer service.',
'minute' => 'Try again later',
],
],
'target' => [
'format' => 'Invalid Target URL',
'missing' => 'Missing Target URL',
],
],
],
// 鉴权
'auth' => [
'default' => 'Please login',
'jwt' => [
'default' => 'Please login',
'iat' => 'Processing, try again later',
'nbf' => 'Processing, try again later',
'exp' => 'Please login',
'iss' => 'Please login',
'uid' => 'Please login',
],
'session' => [
'default' => 'Please login',
'uid' => 'Please login',
'created_at' => 'Please login',
],
'forbidden' => [
'default' => 'You don\'t have permission to manipulate this content',
'read' => [
'default' => 'You don\'t have permission to manipulate this content',
],
'update' => [
'default' => 'You don\'t have permission to manipulate this content',
'address' => [
'unique' => 'You need at least one default shipping address',
],
],
'create' => [
'default' => 'You don\'t have permission to manipulate this content',
'wechat' => [
'redundant' => 'Oops! This WeChat is already used',
],
],
'delete' => [
'default' => 'You don\'t have permission to manipulate this content',
'wechat' => [
'only' => 'You need to add phone or email before unbind WeChat.',
],
],
],
],
// 服务出错
'server' => [
'cache' => [
'redis' => [
'default' => 'OopsSomething went wrong and it was probably our fault. Please try again, or report the problem to us.',
'refused' => 'OopsSomething went wrong and it was probably our fault. Please try again, or report the problem to us.',
],
],
'dependency' => [
'sms' => [
'default' => 'OopsSomething went wrong and it was probably our fault. Please try again, or report the problem to us.',
],
'wechat' => [
'default' => 'Please refresh the QR code and scan the code again',
'code' => 'An internal error is occurred, try again later',
'timeout' => 'An internal error is occurred, try again later',
],
],
'message' => [
'email' => [
'default' => 'Email send error.',
'not_found' => 'Incorrect Email',
],
],
],
'not_found' => [
'route' => [
'default' => 'The route does not exist',
],
],
// 模型
'model' => [
'not_found' => 'Resource Error',
'user' => [
'default' => 'Invalid User',
'not_valid' => 'The username or password is incorrect',
],
'document' => [
'default' => 'DOC deleted',
],
],
];

View File

@@ -0,0 +1,172 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
return [
// 系统错误或未预期的错误
'server_error' => '服务器开小差了,稍后再来试试吧',
'program' => [
'default' => '服务器开小差了,稍后再来试试吧',
'syntax' => [
'default' => '服务器开小差了,稍后再来试试吧',
],
'sql' => [
'default' => '服务器开小差了,稍后再来试试吧',
'column_not_found' => '服务器开小差了,稍后再来试试吧',
'insert' => '服务器开小差了,稍后再来试试吧',
'update' => '服务器开小差了,稍后再来试试吧',
'delete' => '服务器开小差了,稍后再来试试吧',
],
],
// 参数校验
'params' => [
'method' => [
'default' => '请求方式错误!支持的请求类型为::METHODS',
],
// 参数非法
'format_error' => '参数 :param 格式错误',
// 数据错误
'error' => [
'default' => '校验失败',
'user' => [
'default' => '验证失败,:reason',
'username' => [
'unique' => '用户名已存在',
],
'sec_email' => [
'unique' => '此邮箱已被绑定',
'required' => '请传入安全邮箱',
'undefined' => '请先绑定',
'error_format' => '请传入正确的邮箱地址',
],
'sec_phone' => [
'unique' => '此手机号已被绑定',
'required' => '请传入安全手机号码',
'undefined' => '请先绑定',
'error_format' => '请传入正确的手机号码',
],
'sign_up' => [
'default' => '此账号已注册',
],
'action' => [
'error' => '验证码类型错误',
],
],
'code' => [
'error' => '验证码错误或已过期',
'timeout' => '验证码错误或已过期',
'limit' => [
'default' => '今日短信验证码已达上限,请明日再试。如有紧急情况,请联系人工客服',
'day' => '今日短信验证码已达上限,请明日再试。如有紧急情况,请联系人工客服',
'hour' => '今日短信验证码已达上限,请明日再试。如有紧急情况,请联系人工客服',
'minute' => '你点的太快啦,稍后再试',
],
],
'target' => [
'format' => '跳转目标错误',
'missing' => '要跳转的目标缺失',
],
],
],
// 鉴权
'auth' => [
'default' => '请先登录',
'jwt' => [
'default' => '登录失效,请重新登录',
'iat' => '账户生效中,请稍后再试',
'nbf' => '账户生效中,请稍后再试',
'exp' => '登录失效,请重新登录',
'iss' => '登录失效,请重新登录',
'uid' => '登录失效,请重新登录',
],
'session' => [
'default' => '登录失效,请重新登录',
'uid' => '登录失效,请重新登录',
'created_at' => '登录失效,请重新登录',
],
'saml' => [
'default' => 'SAML 检验失败',
'params' => [
'default' => 'SAML 参数校验失败',
'saml_request' => 'SAMLRequest 参数不能为空',
],
],
'forbidden' => [
'default' => '您无权操作此内容',
'read' => [
'default' => '您无权操作此内容',
],
'update' => [
'default' => '您无权操作此内容',
'address' => [
'unique' => '您至少需要一个默认收货地址',
],
],
'create' => [
'default' => '您无权操作此内容',
'wechat' => [
'redundant' => '此微信已绑定其他账户',
],
],
'delete' => [
'default' => '您无权操作此内容',
'wechat' => [
'only' => '你还未关联安全手机号或安全邮箱,解绑后将无法登录',
],
],
],
],
// 服务出错
'server' => [
'cache' => [
'redis' => [
'default' => '服务出了点问题,请稍后再试',
'refused' => '服务出了点问题,请稍后再试',
],
],
'dependency' => [
'sms' => [
'default' => '服务出了点问题,请稍后再试',
],
'wechat' => [
'default' => '请刷新二维码,重新扫码',
'code' => '服务器开小差了,稍后再来试试吧',
'timeout' => '服务器开小差了,稍后再来试试吧',
],
],
'message' => [
'email' => [
'default' => '邮件发送失败',
'not_found' => '邮箱格式不正确',
],
],
],
'not_found' => [
'route' => [
'default' => '当前路由不存在',
],
],
// 模型
'model' => [
'not_found' => '当前:resource不存在',
'user' => [
'default' => '用户不存在',
'not_valid' => '用户名或密码错误',
],
'document' => [
'default' => '文档已删除',
],
],
];

View File

@@ -0,0 +1,390 @@
<?php
/**
* CommonErrorCode.php@hyperf-development-kit
*
* @author 李东云<dongyun.li@luxcreo.cn>
* Powered by PhpStorm
* Created on 2022/4/25
*/
namespace Singularity\HyperfDevelopmentKit\Constants;
use Hyperf\Constants\AbstractConstants;
use Hyperf\Constants\Annotation\Constants;
/**
* @Constants
* Singularity\HyperfDevelopmentKit\Constants\CommonErrorCode@hyperf-development-kit
*
* @author 李东云<dongyun.li@luxcreo.cn>
* Powered by PhpStorm
* Created on 2022/4/25
*/
class CommonErrorCode extends AbstractConstants
{
// =============== 9 服务器异常 =================
/**
* @Message("common_error.server_common_error")
*/
public const SERVER_ERROR = 9000000;
/**
* @Message("common_error.program.default")
*/
public const PROGRAM_ERROR = 9000000;
// 901 逻辑错误
/**
* @Message("common_error.program.syntax.default")
*/
public const PROGRAM_SYNTAX_ERROR = 9010001;
// 902 SQL 错误
/**
* @Message("common_error.program.sql.default")
*/
public const PROGRAM_SQL_ERROR = 9020001;
/**
* @Message("common_error.program.sql.update")
*/
public const PROGRAM_SQL_UPDATE_ERROR = 9020101;
// 90201 字段不存在
/**
* @Message("common_error.program.sql.column_not_found")
*/
public const PROGRAM_SQL_COLUMN_NOT_FOUND = 9020101;
/**
* @Message("common_error.program.sql.insert")
*/
public const PROGRAM_SQL_INSERT_ERROR = 9020201;
// =============== 1 请求错误 =================
// 101 请求方式有误
/**
* @Message("common_error.params.method.default")
*/
public const REQUEST_METHOD_ERROR = 1010001;
// 102 参数非法
/**
* 参数非法.
* @Message("common_error.params.format_common_error")
*/
public const FORMATTER_ERROR = 1020001;
/**
* 缺少参数.
* @Message("common_error.params.common_error.default")
*/
public const REQUEST_PARAMS_MISS = 1020002;
/**
* 签名非法.
* @Message("common_error.params.common_error.default")
*/
public const REQUEST_SIGN_ERROR = 1020003;
// 103 参数错误
/**
* @Message("common_error.params.common_error.default")
*/
public const REQUEST_PARAMS_ERROR = 1030001;
// 10301 用户信息错误
/**
* @Message("common_error.params.common_error.user.default")
*/
public const REQUEST_PARAMS_ERROR_USER = 1030101;
/**
* @Message("common_error.params.common_error.user.sign_up.default")
*/
public const REQUEST_PARAMS_ERROR_USER_REGISTERED = 1030102;
/**
* @Message("common_error.params.common_error.user.username.unique")
*/
public const REQUEST_PARAMS_ERROR_USER_USERNAME_UNIQUE = 1030111;
/**
* @Message("common_error.params.common_error.user.sec_phone.unique")
*/
public const REQUEST_PARAMS_ERROR_USER_SEC_PHONE_UNIQUE = 1030121;
/**
* @Message("common_error.params.common_error.user.sec_phone.required")
*/
public const REQUEST_PARAMS_ERROR_USER_SEC_PHONE_REQUIRED = 1030122;
/**
* @Message("common_error.params.common_error.user.sec_phone.undefined")
*/
public const REQUEST_PARAMS_ERROR_USER_SEC_PHONE_UNDEFINED = 1030123;
/**
* @Message("common_error.params.common_error.user.sec_email.unique")
*/
public const REQUEST_PARAMS_ERROR_USER_SEC_EMAIL_UNIQUE = 1030131;
/**
* @Message("common_error.params.common_error.user.sec_email.required")
*/
public const REQUEST_PARAMS_ERROR_USER_SEC_EMAIL_REQUIRED = 1030132;
/**
* @Message("common_error.params.common_error.user.sec_email.undefined")
*/
public const REQUEST_PARAMS_ERROR_USER_SEC_EMAIL_UNDEFINED = 1030133;
/**
* @Message("common_error.params.common_error.user.action.common_error")
*/
public const REQUEST_PARAMS_ERROR_USER_ACTION_ERROR = 1030141;
// 10302 验证码错误
/**
* @Message("common_error.params.common_error.code.common_error")
*/
public const REQUEST_PARAMS_ERROR_CODE_ERROR = 1030201;
/**
* @Message("common_error.params.common_error.code.timeout")
*/
public const REQUEST_PARAMS_ERROR_CODE_TIMEOUT = 1030202;
/**
* @Message("common_error.params.common_error.code.limit.minute")
*/
public const REQUEST_PARAMS_ERROR_CODE_MAX_TIMES_MINUTE = 1030301;
/**
* @Message("common_error.params.common_error.code.limit.hour")
*/
public const REQUEST_PARAMS_ERROR_CODE_MAX_TIMES_HOUR = 1030302;
/**
* @Message("common_error.params.common_error.code.limit.day")
*/
public const REQUEST_PARAMS_ERROR_CODE_MAX_TIMES_DAY = 1030303;
/**
* @Message("common_error.params.common_error.target.format")
*/
public const REQUEST_PARAMS_ERROR_TARGET_FORMAT = 1030401;
/**
* @Message("common_error.params.common_error.target.missing")
*/
public const REQUEST_PARAMS_ERROR_TARGET_MISSING = 1030402;
// =============== 2 鉴权问题 =================
// 201 JWT 鉴权失败
/**
* @Message("common_error.auth.default")
*/
public const UNAUTHORIZED = 200000;
/**
* @Message("common_error.auth.jwt.default")
*/
public const AUTH_JWT_ERROR = 201000;
// 20101 验证
/**
* @Message("common_error.auth.jwt.iat")
*/
public const AUTH_JWT_IAT_ERROR = 2010101;
/**
* @Message("common_error.auth.jwt.nbf")
*/
public const AUTH_JWT_NBF_ERROR = 2010102;
/**
* @Message("common_error.auth.jwt.exp")
*/
public const AUTH_JWT_EXP_TIMEOUT = 2010103;
/**
* @Message("common_error.auth.jwt.iss")
*/
public const AUTH_JWT_ISS_ERROR = 2010104;
/**
* @Message("common_error.auth.jwt.uid")
*/
public const AUTH_JWT_UID_ERROR = 2010105;
// 202 Session 鉴权
/**
* @Message("common_error.auth.session.default")
*/
public const AUTH_SESSION_ERROR = 202000;
// 20201 验证
/**
* @Message("common_error.auth.session.uid")
*/
public const AUTH_SESSION_UID_ERROR = 2020101;
/**
* @Message("common_error.auth.session.created_at")
*/
public const AUTH_SESSION_CREATED_AT_ERROR = 2020102;
// 203 SAML 鉴权
/**
* @Message("common_error.auth.saml.default")
*/
public const AUTH_SAML_ERROR = 203000;
// 20301 验证
/**
* @Message("common_error.auth.saml.params.default")
*/
public const AUTH_SAML_REQUEST_PARAMS_ERROR = 2030100;
/**
* @Message("common_error.auth.saml.params.saml_request")
*/
public const AUTH_SAML_REQUEST_PARAMS_SAML_REQUEST = 2030101;
// 204 无权访问
/**
* @Message("common_error.auth.forbidden.default")
*/
public const FORBIDDEN = 204000;
// 20401 无权访问
/**
* @Message("common_error.auth.forbidden.read.default")
*/
public const FORBIDDEN_READ_ERROR = 2040101;
// 20402 无权修改
/**
* @Message("common_error.auth.forbidden.update.default")
*/
public const FORBIDDEN_UPDATE_ERROR = 2040201;
/**
* @Message("common_error.auth.forbidden.update.address.unique")
*/
public const FORBIDDEN_UPDATE_ADDRESS_DEFAULT_UNIQUE_ERROR = 2040211;
// 20403 无权创建
/**
* @Message("common_error.auth.forbidden.create.default")
*/
public const FORBIDDEN_CREATE_ERROR = 2040301;
/**
* @Message("common_error.auth.forbidden.create.wechat.redundant")
*/
public const FORBIDDEN_CREATE_WECHAT_REDUNDANT_ERROR = 2040311;
// 20404 无权删除
/**
* @Message("common_error.auth.forbidden.delete.default")
*/
public const FORBIDDEN_DELETE_ERROR = 2040401;
/**
* @Message("common_error.auth.forbidden.delete.wechat.only")
*/
public const FORBIDDEN_DELETE_ONLY_USERNAME_WITH_WECHAT = 2040411;
// ============== 3 依赖服务出错 ===============
// 303 缓存异常
// 30301 Redis 异常
/**
* @Message("common_error.server.cache.redis.default")
*/
public const SERVER_CACHE_REDIS_ERROR = 3030101;
/**
* @Message("common_error.server.cache.redis.refused")
*/
public const SERVER_CACHE_REDIS_REFUSED_ERROR = 3030110;
// 30302 SMS 异常
/**
* @Message("common_error.server.dependency_sms_common_error")
*/
public const SERVER_DEPENDENCY_SMS_ERROR = 3030201;
// 30303 微信错误
/**
* @Message("common_error.server.dependency.wechat.default")
*/
public const SERVER_DEPENDENCY_WECHAT_ERROR = 3030301;
/**
* @Message("common_error.server.dependency.wechat.code")
*/
public const SERVER_DEPENDENCY_WECHAT_CODE_ERROR = 3030302;
/**
* @Message("common_error.server.dependency.wechat.timeout")
*/
public const SERVER_DEPENDENCY_WECHAT_CODE_TIMEOUT_ERROR = 3030311;
// 306 消息异常
// 30601 自建邮箱发件服务异常
/**
* @Message("common_error.server.message.email.default")
*/
public const SERVER_MESSAGE_EMAIL_ERROR = 3060101;
/**
* @Message("common_error.server.message.email.not_found")
*/
public const SERVER_MESSAGE_EMAIL_NOT_FOUND = 3060102;
// =============== 4 资源不存在 ================
// 401 路由不存在
/**
* @Message("common_error.not_found.route.default")
*/
public const ROUTE_NOT_FOUND = 4010001;
// 402 模型不存在
/**
* @Message("common_error.model.not_found")
*/
public const MODEL_NOT_FOUND = 4020001;
// 40201 用户不存在
/**
* @Message("common_error.model.user.default")
* @note !!!这个码一定不要改,前端根据这个做判断了!!!!
*/
public const USER_NOT_FOUND = 4020101;
/**
* @Message("common_error.model.user.not_valid")
*/
public const USER_NOT_VALID = 4020102;
/**
* @Message("common_error.model.document.default")
*/
public const DOCUMENT_NOT_EXISTS = 4020201;
}