From 589be671fc64c555948ea1034c2738be3525fc10 Mon Sep 17 00:00:00 2001 From: gzydong <837215079@qq.com> Date: Wed, 4 Nov 2020 11:57:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/Dockerfile | 60 ------ .github/workflows/build.yml | 12 -- .github/workflows/release.yml | 25 --- ...geConsumer.php => ChatMessageConsumer.php} | 14 +- ...moProducer.php => ChatMessageProducer.php} | 15 +- app/Command/TestCommand.php | 44 ----- app/Constants/ResponseCode.php | 33 ++++ app/Controller/AbstractController.php | 23 +++ app/Controller/Api/V1/ArticleController.php | 16 ++ app/Controller/Api/V1/AuthController.php | 16 ++ app/Controller/Api/V1/CController.php | 10 + app/Controller/Api/V1/EmoticonController.php | 16 ++ app/Controller/Api/V1/GroupController.php | 16 ++ app/Controller/Api/V1/TalkController.php | 16 ++ app/Controller/Api/V1/UsersController.php | 16 ++ app/Controller/IndexController.php | 12 +- app/Controller/WebSocketController.php | 5 +- app/Exception/Handler/AppExceptionHandler.php | 7 + .../Handler/ValidateExceptionHandler.php | 46 +++++ app/Exception/ValidateException.php | 16 ++ app/Model/Model.php | 1 + app/Process/FooProcess.php | 45 ----- app/Process/MasterSocketProcess.php | 18 -- app/Process/SalveSocketProcess.php | 20 -- app/Services/ArticleService.php | 9 + app/Services/BaseService.php | 8 + app/Services/EmoticonService.php | 9 + app/Services/FriendService.php | 9 + app/Services/GroupService.php | 9 + app/Services/TalkService.php | 8 + app/Services/UserService.php | 8 + app/Supports/Http/Response.php | 94 ++++++++++ config/autoload/exceptions.php | 1 + config/autoload/middlewares.php | 1 + config/autoload/processes.php | 2 +- config/autoload/server.php | 3 + config/autoload/translation.php | 16 ++ config/routes.php | 4 +- storage/languages/en/validation.php | 177 ++++++++++++++++++ storage/languages/zh_CN/validation.php | 177 ++++++++++++++++++ upload-test.html | 2 +- 41 files changed, 784 insertions(+), 255 deletions(-) delete mode 100644 .github/workflows/Dockerfile delete mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/release.yml rename app/Amqp/Consumer/{ImMessageConsumer.php => ChatMessageConsumer.php} (82%) rename app/Amqp/Producer/{DemoProducer.php => ChatMessageProducer.php} (59%) delete mode 100644 app/Command/TestCommand.php create mode 100644 app/Constants/ResponseCode.php create mode 100644 app/Controller/Api/V1/ArticleController.php create mode 100644 app/Controller/Api/V1/AuthController.php create mode 100644 app/Controller/Api/V1/CController.php create mode 100644 app/Controller/Api/V1/EmoticonController.php create mode 100644 app/Controller/Api/V1/GroupController.php create mode 100644 app/Controller/Api/V1/TalkController.php create mode 100644 app/Controller/Api/V1/UsersController.php create mode 100644 app/Exception/Handler/ValidateExceptionHandler.php create mode 100644 app/Exception/ValidateException.php delete mode 100644 app/Process/FooProcess.php delete mode 100644 app/Process/MasterSocketProcess.php delete mode 100644 app/Process/SalveSocketProcess.php create mode 100644 app/Services/ArticleService.php create mode 100644 app/Services/BaseService.php create mode 100644 app/Services/EmoticonService.php create mode 100644 app/Services/FriendService.php create mode 100644 app/Services/GroupService.php create mode 100644 app/Services/TalkService.php create mode 100644 app/Services/UserService.php create mode 100644 app/Supports/Http/Response.php create mode 100644 config/autoload/translation.php create mode 100644 storage/languages/en/validation.php create mode 100644 storage/languages/zh_CN/validation.php diff --git a/.github/workflows/Dockerfile b/.github/workflows/Dockerfile deleted file mode 100644 index 83e482d..0000000 --- a/.github/workflows/Dockerfile +++ /dev/null @@ -1,60 +0,0 @@ -# Default Dockerfile -# -# @link https://www.hyperf.io -# @document https://hyperf.wiki -# @contact group@hyperf.io -# @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE - -FROM hyperf/hyperf:7.4-alpine-v3.11-cli -LABEL maintainer="Hyperf Developers " version="1.0" license="MIT" app.name="Hyperf" - -## -# ---------- env settings ---------- -## -# --build-arg timezone=Asia/Shanghai -ARG timezone - -ENV TIMEZONE=${timezone:-"Asia/Shanghai"} \ - COMPOSER_VERSION=1.10.10 \ - APP_ENV=prod \ - SCAN_CACHEABLE=(true) - -# update -RUN set -ex \ - # install composer - && cd /tmp \ - && wget https://github.com/composer/composer/releases/download/${COMPOSER_VERSION}/composer.phar \ - && chmod u+x composer.phar \ - && mv composer.phar /usr/local/bin/composer \ - # show php version and extensions - && php -v \ - && php -m \ - && php --ri swoole \ - # ---------- some config ---------- - && cd /etc/php7 \ - # - config PHP - && { \ - echo "upload_max_filesize=128M"; \ - echo "post_max_size=128M"; \ - echo "memory_limit=1G"; \ - echo "date.timezone=${TIMEZONE}"; \ - } | tee conf.d/99_overrides.ini \ - # - config timezone - && ln -sf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime \ - && echo "${TIMEZONE}" > /etc/timezone \ - # ---------- clear works ---------- - && rm -rf /var/cache/apk/* /tmp/* /usr/share/man \ - && echo -e "\033[42;37m Build Completed :).\033[0m\n" - -WORKDIR /opt/www - -# Composer Cache -# COPY ./composer.* /opt/www/ -# RUN composer install --no-dev --no-scripts - -COPY . /opt/www -RUN print "\n" | composer install -o && php bin/hyperf.php - -EXPOSE 9501 - -ENTRYPOINT ["php", "/opt/www/bin/hyperf.php", "start"] diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 0ca82fa..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,12 +0,0 @@ -name: Build Docker - -on: [push, pull_request] - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v2 - - name: Build - run: cp -rf .github/workflows/Dockerfile . && docker build -t hyperf . diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 0f7d23f..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,25 +0,0 @@ -on: - push: - # Sequence of patterns matched against refs/tags - tags: - - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 - -name: Release - -jobs: - release: - name: Release - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v2 - - name: Create Release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ github.ref }} - release_name: Release ${{ github.ref }} - draft: false - prerelease: false diff --git a/app/Amqp/Consumer/ImMessageConsumer.php b/app/Amqp/Consumer/ChatMessageConsumer.php similarity index 82% rename from app/Amqp/Consumer/ImMessageConsumer.php rename to app/Amqp/Consumer/ChatMessageConsumer.php index 54dbefd..d380c14 100644 --- a/app/Amqp/Consumer/ImMessageConsumer.php +++ b/app/Amqp/Consumer/ChatMessageConsumer.php @@ -12,11 +12,10 @@ use Hyperf\Amqp\Message\Type; use Hyperf\Amqp\Builder\QueueBuilder; /** - * @Consumer(name="IM信息消费",enable=true) + * @Consumer(name=" ChatMessage ",enable=true) */ -class ImMessageConsumer extends ConsumerMessage +class ChatMessageConsumer extends ConsumerMessage { - /** * 交换机名称 * @@ -43,7 +42,7 @@ class ImMessageConsumer extends ConsumerMessage */ public function __construct() { - $this->setQueue('im:message:queue:'.config('ip_address')); + $this->setQueue('im:message:queue:' . config('ip_address')); } /** @@ -67,10 +66,10 @@ class ImMessageConsumer extends ConsumerMessage */ public function consumeMessage($data, AMQPMessage $message): string { - echo PHP_EOL.$data; + echo PHP_EOL . $data; $server = server(); - foreach (server()->connections as $fd){ + foreach (server()->connections as $fd) { if ($server->isEstablished($fd)) { $server->push($fd, "Recv: 我是后台进程 [{$data}]"); } @@ -82,7 +81,8 @@ class ImMessageConsumer extends ConsumerMessage /** * @param $data */ - public function getClientFds($data){ + public function getClientFds($data) + { } } diff --git a/app/Amqp/Producer/DemoProducer.php b/app/Amqp/Producer/ChatMessageProducer.php similarity index 59% rename from app/Amqp/Producer/DemoProducer.php rename to app/Amqp/Producer/ChatMessageProducer.php index ad5f53c..1ee3c16 100644 --- a/app/Amqp/Producer/DemoProducer.php +++ b/app/Amqp/Producer/ChatMessageProducer.php @@ -4,28 +4,15 @@ declare(strict_types=1); namespace App\Amqp\Producer; -use Hyperf\Amqp\Builder\ExchangeBuilder; use Hyperf\Amqp\Message\ProducerMessage; use Hyperf\Amqp\Message\Type; - -class DemoProducer extends ProducerMessage +class ChatMessageProducer extends ProducerMessage { public $exchange = 'im.message.fanout'; public $type = Type::FANOUT; - /** - * 重写创建交换机方法 - * 注释 添加 - * - * @return ExchangeBuilder - */ -// public function getExchangeBuilder(): ExchangeBuilder -// { -// return parent::getExchangeBuilder()->setAutoDelete(true); -// } - public function __construct($data) { $message = [ diff --git a/app/Command/TestCommand.php b/app/Command/TestCommand.php deleted file mode 100644 index 599ec40..0000000 --- a/app/Command/TestCommand.php +++ /dev/null @@ -1,44 +0,0 @@ -container = $container; - - parent::__construct('demo:command'); - } - - public function configure() - { - parent::configure(); - $this->setDescription('Hyperf Demo Command'); - } - - public function handle() - { - $producer = ApplicationContext::getContainer()->get(Producer::class); - - $result = $producer->produce(new DemoProducer('test'. date('Y-m-d H:i:s'))); - } -} diff --git a/app/Constants/ResponseCode.php b/app/Constants/ResponseCode.php new file mode 100644 index 0000000..54ca80f --- /dev/null +++ b/app/Constants/ResponseCode.php @@ -0,0 +1,33 @@ +validationFactory->make(...$arg); + + if ($validator->fails()) { + throw new ValidateException($validator->errors()->first(),ResponseCode::VALIDATION_ERROR); + } + } } diff --git a/app/Controller/Api/V1/ArticleController.php b/app/Controller/Api/V1/ArticleController.php new file mode 100644 index 0000000..4de471f --- /dev/null +++ b/app/Controller/Api/V1/ArticleController.php @@ -0,0 +1,16 @@ +request->input('user', 'Hyperf'); $method = $this->request->getMethod(); + $this->validate($this->request->all(), [ + 'username' => 'required', + 'password' => 'required', + ]); + return [ 'method' => $method, - 'message' => "Hello {$user}." + 'message' => "Hello {$user}.", ]; } - public function upload(ResponseInterface $response){ + public function upload(ResponseInterface $response) + { return [ 'method' => 'upload', ]; diff --git a/app/Controller/WebSocketController.php b/app/Controller/WebSocketController.php index 005ebd8..50d5880 100644 --- a/app/Controller/WebSocketController.php +++ b/app/Controller/WebSocketController.php @@ -8,9 +8,8 @@ use Hyperf\Contract\OnMessageInterface; use Hyperf\Contract\OnOpenInterface; use Swoole\Http\Request; use Swoole\Websocket\Frame; - use Hyperf\Amqp\Producer; -use App\Amqp\Producer\DemoProducer; +use App\Amqp\Producer\ChatMessageProducer; class WebSocketController implements OnMessageInterface, OnOpenInterface, OnCloseInterface { @@ -19,7 +18,7 @@ class WebSocketController implements OnMessageInterface, OnOpenInterface, OnClos $producer = container()->get(Producer::class); $ip = config('ip_address'); - $producer->produce(new DemoProducer("我是来自[{$ip} 服务器的消息],{$frame->data}")); + $producer->produce(new ChatMessageProducer("我是来自[{$ip} 服务器的消息],{$frame->data}")); } public function onClose($server, int $fd, int $reactorId): void diff --git a/app/Exception/Handler/AppExceptionHandler.php b/app/Exception/Handler/AppExceptionHandler.php index 188d298..6f1d4a9 100644 --- a/app/Exception/Handler/AppExceptionHandler.php +++ b/app/Exception/Handler/AppExceptionHandler.php @@ -11,6 +11,7 @@ declare(strict_types=1); */ namespace App\Exception\Handler; +use App\Exception\ValidateException; use Hyperf\Contract\StdoutLoggerInterface; use Hyperf\ExceptionHandler\ExceptionHandler; use Hyperf\HttpMessage\Stream\SwooleStream; @@ -31,8 +32,14 @@ class AppExceptionHandler extends ExceptionHandler public function handle(Throwable $throwable, ResponseInterface $response) { + // 判断是否是验证器异常类 + if($throwable instanceof ValidateException){ + return $response; + } + $this->logger->error(sprintf('%s[%s] in %s', $throwable->getMessage(), $throwable->getLine(), $throwable->getFile())); $this->logger->error($throwable->getTraceAsString()); + return $response->withHeader('Server', 'Hyperf')->withStatus(500)->withBody(new SwooleStream('Internal Server Error.')); } diff --git a/app/Exception/Handler/ValidateExceptionHandler.php b/app/Exception/Handler/ValidateExceptionHandler.php new file mode 100644 index 0000000..5352b03 --- /dev/null +++ b/app/Exception/Handler/ValidateExceptionHandler.php @@ -0,0 +1,46 @@ + $throwable->getCode(), + 'message' => $throwable->getMessage(), + 'data'=>[] + ], JSON_UNESCAPED_UNICODE); + + // 阻止异常冒泡 + $this->stopPropagation(); + + return $response->withAddedHeader('content-type', 'application/json; charset=utf-8')->withStatus(200)->withBody(new SwooleStream($data)); + } + + return $response; + } + + /** + * 判断该异常处理器是否要对该异常进行处理 + */ + public function isValid(Throwable $throwable): bool + { + return true; + } +} diff --git a/app/Exception/ValidateException.php b/app/Exception/ValidateException.php new file mode 100644 index 0000000..d4f7bae --- /dev/null +++ b/app/Exception/ValidateException.php @@ -0,0 +1,16 @@ +container->get(ServerFactory::class)->getServer()->getServer(); -// -// $fds = []; -// foreach ($server->connections as $fd) { -// if ($server->isEstablished($fd)) { -// $fds[] = $fd; -// -// $server->push($fd, 'Recv: 我是后台进程 ...'); -// } -// } -// -// echo "当前连接数:".count($fds).' -- fids: '.implode(',',$fds).PHP_EOL; -// -// -// sleep(3); -// echo time().PHP_EOL; -// } - - // 您的代码 ... - } -} diff --git a/app/Process/MasterSocketProcess.php b/app/Process/MasterSocketProcess.php deleted file mode 100644 index c7daf66..0000000 --- a/app/Process/MasterSocketProcess.php +++ /dev/null @@ -1,18 +0,0 @@ -response = container()->get(ResponseInterface::class); + } + + /** + * @param $data + * @return PsrResponseInterface + */ + public function json($data) + { + return $this->response->json($data); + } + + /** + * 处理成功信息返回 + * + * @param array $data 响应数据 + * @param string $message 响应提示 + * @return PsrResponseInterface + */ + public function success(array $data = [], $message = 'success') + { + $code = ResponseCode::SUCCESS; + return $this->response->json(compact('code', 'message', 'data')); + } + + /** + * 处理失败信息返回 + * + * @param array $data 响应数据 + * @param string $message 响应提示 + * @param int $code 错误码 + * + * @return PsrResponseInterface + */ + public function fail($message = 'FAIL', $data = [], $code = ResponseCode::FAIL) + { + return $this->response->json(compact('code', 'message', 'data')); + } + + /** + * @param string $message + * @param int $code + * @return PsrResponseInterface + */ + public function error($message = '', $code = ResponseCode::SERVER_ERROR) + { + return $this->response->withStatus(500)->json([ + 'code' => $code, + 'message' => $message, + ]); + } + + public function redirect($url, $status = 302) + { + return $this->response() + ->withAddedHeader('Location', (string)$url) + ->withStatus($status); + } + + public function cookie(Cookie $cookie) + { + $response = $this->response()->withCookie($cookie); + Context::set(PsrResponseInterface::class, $response); + return $this; + } + + /** + * @return \Hyperf\HttpMessage\Server\Response + */ + public function response() + { + return Context::get(PsrResponseInterface::class); + } +} diff --git a/config/autoload/exceptions.php b/config/autoload/exceptions.php index b848177..b09be03 100644 --- a/config/autoload/exceptions.php +++ b/config/autoload/exceptions.php @@ -14,6 +14,7 @@ return [ 'http' => [ Hyperf\HttpServer\Exception\Handler\HttpExceptionHandler::class, App\Exception\Handler\AppExceptionHandler::class, + App\Exception\Handler\ValidateExceptionHandler::class, ], ], ]; diff --git a/config/autoload/middlewares.php b/config/autoload/middlewares.php index 49bdec2..6ad681d 100644 --- a/config/autoload/middlewares.php +++ b/config/autoload/middlewares.php @@ -11,5 +11,6 @@ declare(strict_types=1); */ return [ 'http' => [ + ], ]; diff --git a/config/autoload/processes.php b/config/autoload/processes.php index 6e69b5e..94a9894 100644 --- a/config/autoload/processes.php +++ b/config/autoload/processes.php @@ -10,5 +10,5 @@ declare(strict_types=1); * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ return [ -// \App\Process\FooProcess::class, + ]; diff --git a/config/autoload/server.php b/config/autoload/server.php index c9c7efd..4127f5a 100644 --- a/config/autoload/server.php +++ b/config/autoload/server.php @@ -51,6 +51,9 @@ return [ 'package_max_length'=> 10 * 1024 * 1024, ], 'callbacks' => [ + //自定义启动前事件 + //SwooleEvent::ON_BEFORE_START => [Hyperf\Framework\Bootstrap\ServerStartCallback::class, 'beforeStart'], + SwooleEvent::ON_WORKER_START => [Hyperf\Framework\Bootstrap\WorkerStartCallback::class, 'onWorkerStart'], SwooleEvent::ON_PIPE_MESSAGE => [Hyperf\Framework\Bootstrap\PipeMessageCallback::class, 'onPipeMessage'], SwooleEvent::ON_WORKER_EXIT => [Hyperf\Framework\Bootstrap\WorkerExitCallback::class, 'onWorkerExit'], diff --git a/config/autoload/translation.php b/config/autoload/translation.php new file mode 100644 index 0000000..35b9f06 --- /dev/null +++ b/config/autoload/translation.php @@ -0,0 +1,16 @@ + 'zh_CN', + 'fallback_locale' => 'en', + 'path' => BASE_PATH . '/storage/languages', +]; diff --git a/config/routes.php b/config/routes.php index 603dd7f..19fd53a 100644 --- a/config/routes.php +++ b/config/routes.php @@ -1,6 +1,7 @@ [CorsMiddleware::class]]); - Router::get('/favicon.ico', function () { return ''; }); - - Router::addServer('ws', function () { Router::get('/', 'App\Controller\WebSocketController'); }); diff --git a/storage/languages/en/validation.php b/storage/languages/en/validation.php new file mode 100644 index 0000000..5e128a6 --- /dev/null +++ b/storage/languages/en/validation.php @@ -0,0 +1,177 @@ + 'The :attribute must be accepted.', + 'active_url' => 'The :attribute is not a valid URL.', + 'after' => 'The :attribute must be a date after :date.', + 'after_or_equal' => 'The :attribute must be a date after or equal to :date.', + 'alpha' => 'The :attribute may only contain letters.', + 'alpha_dash' => 'The :attribute may only contain letters, numbers, and dashes.', + 'alpha_num' => 'The :attribute may only contain letters and numbers.', + 'array' => 'The :attribute must be an array.', + 'before' => 'The :attribute must be a date before :date.', + 'before_or_equal' => 'The :attribute must be a date before or equal to :date.', + 'between' => [ + 'numeric' => 'The :attribute must be between :min and :max.', + 'file' => 'The :attribute must be between :min and :max kilobytes.', + 'string' => 'The :attribute must be between :min and :max characters.', + 'array' => 'The :attribute must have between :min and :max items.', + ], + 'boolean' => 'The :attribute field must be true or false.', + 'confirmed' => 'The :attribute confirmation does not match.', + 'date' => 'The :attribute is not a valid date.', + 'date_format' => 'The :attribute does not match the format :format.', + 'different' => 'The :attribute and :other must be different.', + 'digits' => 'The :attribute must be :digits digits.', + 'digits_between' => 'The :attribute must be between :min and :max digits.', + 'dimensions' => 'The :attribute has invalid image dimensions.', + 'distinct' => 'The :attribute field has a duplicate value.', + 'email' => 'The :attribute must be a valid email address.', + 'exists' => 'The selected :attribute is invalid.', + 'file' => 'The :attribute must be a file.', + 'filled' => 'The :attribute field is required.', + 'gt' => [ + 'numeric' => 'The :attribute must be greater than :value', + 'file' => 'The :attribute must be greater than :value kb', + 'string' => 'The :attribute must be greater than :value characters', + 'array' => 'The :attribute must be greater than :value items', + ], + 'gte' => [ + 'numeric' => 'The :attribute must be great than or equal to :value', + 'file' => 'The :attribute must be great than or equal to :value kb', + 'string' => 'The :attribute must be great than or equal to :value characters', + 'array' => 'The :attribute must be great than or equal to :value items', + ], + 'image' => 'The :attribute must be an image.', + 'in' => 'The selected :attribute is invalid.', + 'in_array' => 'The :attribute field does not exist in :other.', + 'integer' => 'The :attribute must be an integer.', + 'ip' => 'The :attribute must be a valid IP address.', + 'ipv4' => 'The :attribute must be a valid IPv4 address.', + 'ipv6' => 'The :attribute must be a valid IPv6 address.', + 'json' => 'The :attribute must be a valid JSON string.', + 'lt' => [ + 'numeric' => 'The :attribute must be less than :value', + 'file' => 'The :attribute must be less than :value kb', + 'string' => 'The :attribute must be less than :value characters', + 'array' => 'The :attribute must be less than :value items', + ], + 'lte' => [ + 'numeric' => 'The :attribute must be less than or equal to :value', + 'file' => 'The :attribute must be less than or equal to :value kb', + 'string' => 'The :attribute must be less than or equal to :value characters', + 'array' => 'The :attribute must be less than or equal to :value items', + ], + 'max' => [ + 'numeric' => 'The :attribute may not be greater than :max.', + 'file' => 'The :attribute may not be greater than :max kilobytes.', + 'string' => 'The :attribute may not be greater than :max characters.', + 'array' => 'The :attribute may not have more than :max items.', + ], + 'mimes' => 'The :attribute must be a file of type: :values.', + 'mimetypes' => 'The :attribute must be a file of type: :values.', + 'min' => [ + 'numeric' => 'The :attribute must be at least :min.', + 'file' => 'The :attribute must be at least :min kilobytes.', + 'string' => 'The :attribute must be at least :min characters.', + 'array' => 'The :attribute must have at least :min items.', + ], + 'not_in' => 'The selected :attribute is invalid.', + 'not_regex' => 'The :attribute cannot match a given regular rule.', + 'numeric' => 'The :attribute must be a number.', + 'present' => 'The :attribute field must be present.', + 'regex' => 'The :attribute format is invalid.', + 'required' => 'The :attribute field is required.', + 'required_if' => 'The :attribute field is required when :other is :value.', + 'required_unless' => 'The :attribute field is required unless :other is in :values.', + 'required_with' => 'The :attribute field is required when :values is present.', + 'required_with_all' => 'The :attribute field is required when :values is present.', + 'required_without' => 'The :attribute field is required when :values is not present.', + 'required_without_all' => 'The :attribute field is required when none of :values are present.', + 'same' => 'The :attribute and :other must match.', + 'size' => [ + 'numeric' => 'The :attribute must be :size.', + 'file' => 'The :attribute must be :size kilobytes.', + 'string' => 'The :attribute must be :size characters.', + 'array' => 'The :attribute must contain :size items.', + ], + 'starts_with' => 'The :attribute must be start with :values ', + 'string' => 'The :attribute must be a string.', + 'timezone' => 'The :attribute must be a valid zone.', + 'unique' => 'The :attribute has already been taken.', + 'uploaded' => 'The :attribute failed to upload.', + 'url' => 'The :attribute format is invalid.', + 'uuid' => 'The :attribute is invalid UUID.', + 'max_if' => [ + 'numeric' => 'The :attribute may not be greater than :max when :other is :value.', + 'file' => 'The :attribute may not be greater than :max kilobytes when :other is :value.', + 'string' => 'The :attribute may not be greater than :max characters when :other is :value.', + 'array' => 'The :attribute may not have more than :max items when :other is :value.', + ], + 'min_if' => [ + 'numeric' => 'The :attribute must be at least :min when :other is :value.', + 'file' => 'The :attribute must be at least :min kilobytes when :other is :value.', + 'string' => 'The :attribute must be at least :min characters when :other is :value.', + 'array' => 'The :attribute must have at least :min items when :other is :value.', + ], + 'between_if' => [ + 'numeric' => 'The :attribute must be between :min and :max when :other is :value.', + 'file' => 'The :attribute must be between :min and :max kilobytes when :other is :value.', + 'string' => 'The :attribute must be between :min and :max characters when :other is :value.', + 'array' => 'The :attribute must have between :min and :max items when :other is :value.', + ], + /* + |-------------------------------------------------------------------------- + | Custom Validation Language Lines + |-------------------------------------------------------------------------- + | + | Here you may specify custom validation messages for attributes using the + | convention "attribute.rule" to name the lines. This makes it quick to + | specify a specific custom language line for a given attribute rule. + | + */ + + 'custom' => [ + 'attribute-name' => [ + 'rule-name' => 'custom-message', + ], + ], + + /* + |-------------------------------------------------------------------------- + | Custom Validation Attributes + |-------------------------------------------------------------------------- + | + | The following language lines are used to swap attribute place-holders + | with something more reader friendly such as E-Mail Address instead + | of "email". This simply helps us make messages a little cleaner. + | + */ + + 'attributes' => [], + 'phone_number' => 'The :attribute must be a valid phone number', + 'telephone_number' => 'The :attribute must be a valid telephone number', + + 'chinese_word' => 'The :attribute must contain valid characters(chinese/english character, number, underscore)', + 'sequential_array' => 'The :attribute must be sequential array', +]; diff --git a/storage/languages/zh_CN/validation.php b/storage/languages/zh_CN/validation.php new file mode 100644 index 0000000..8093224 --- /dev/null +++ b/storage/languages/zh_CN/validation.php @@ -0,0 +1,177 @@ + ':attribute 必须接受', + 'active_url' => ':attribute 必须是一个合法的 URL', + 'after' => ':attribute 必须是 :date 之后的一个日期', + 'after_or_equal' => ':attribute 必须是 :date 之后或相同的一个日期', + 'alpha' => ':attribute 只能包含字母', + 'alpha_dash' => ':attribute 只能包含字母、数字、中划线或下划线', + 'alpha_num' => ':attribute 只能包含字母和数字', + 'array' => ':attribute 必须是一个数组', + 'before' => ':attribute 必须是 :date 之前的一个日期', + 'before_or_equal' => ':attribute 必须是 :date 之前或相同的一个日期', + 'between' => [ + 'numeric' => ':attribute 必须在 :min 到 :max 之间', + 'file' => ':attribute 必须在 :min 到 :max kb 之间', + 'string' => ':attribute 必须在 :min 到 :max 个字符之间', + 'array' => ':attribute 必须在 :min 到 :max 项之间', + ], + 'boolean' => ':attribute 字符必须是 true 或 false, 1 或 0', + 'confirmed' => ':attribute 二次确认不匹配', + 'date' => ':attribute 必须是一个合法的日期', + 'date_format' => ':attribute 与给定的格式 :format 不符合', + 'different' => ':attribute 必须不同于 :other', + 'digits' => ':attribute 必须是 :digits 位', + 'digits_between' => ':attribute 必须在 :min 和 :max 位之间', + 'dimensions' => ':attribute 具有无效的图片尺寸', + 'distinct' => ':attribute 字段具有重复值', + 'email' => ':attribute 必须是一个合法的电子邮件地址', + 'exists' => '选定的 :attribute 是无效的', + 'file' => ':attribute 必须是一个文件', + 'filled' => ':attribute 的字段是必填的', + 'gt' => [ + 'numeric' => ':attribute 必须大于 :value', + 'file' => ':attribute 必须大于 :value kb', + 'string' => ':attribute 必须大于 :value 个字符', + 'array' => ':attribute 必须大于 :value 项', + ], + 'gte' => [ + 'numeric' => ':attribute 必须大于等于 :value', + 'file' => ':attribute 必须大于等于 :value kb', + 'string' => ':attribute 必须大于等于 :value 个字符', + 'array' => ':attribute 必须大于等于 :value 项', + ], + 'image' => ':attribute 必须是 jpg, jpeg, png, bmp 或者 gif 格式的图片', + 'in' => '选定的 :attribute 是无效的', + 'in_array' => ':attribute 字段不存在于 :other', + 'integer' => ':attribute 必须是个整数', + 'ip' => ':attribute 必须是一个合法的 IP 地址', + 'ipv4' => ':attribute 必须是一个合法的 IPv4 地址', + 'ipv6' => ':attribute 必须是一个合法的 IPv6 地址', + 'json' => ':attribute 必须是一个合法的 JSON 字符串', + 'lt' => [ + 'numeric' => ':attribute 必须小于 :value', + 'file' => ':attribute 必须小于 :value kb', + 'string' => ':attribute 必须小于 :value 个字符', + 'array' => ':attribute 必须小于 :value 项', + ], + 'lte' => [ + 'numeric' => ':attribute 必须小于等于 :value', + 'file' => ':attribute 必须小于等于 :value kb', + 'string' => ':attribute 必须小于等于 :value 个字符', + 'array' => ':attribute 必须小于等于 :value 项', + ], + 'max' => [ + 'numeric' => ':attribute 的最大值为 :max', + 'file' => ':attribute 的最大为 :max kb', + 'string' => ':attribute 的最大长度为 :max 字符', + 'array' => ':attribute 至多有 :max 项', + ], + 'mimes' => ':attribute 的文件类型必须是 :values', + 'mimetypes' => ':attribute 的文件MIME必须是 :values', + 'min' => [ + 'numeric' => ':attribute 的最小值为 :min', + 'file' => ':attribute 大小至少为 :min kb', + 'string' => ':attribute 的最小长度为 :min 字符', + 'array' => ':attribute 至少有 :min 项', + ], + 'not_in' => '选定的 :attribute 是无效的', + 'not_regex' => ':attribute 不能匹配给定的正则', + 'numeric' => ':attribute 必须是数字', + 'present' => ':attribute 字段必须存在', + 'regex' => ':attribute 格式是无效的', + 'required' => ':attribute 字段是必须的', + 'required_if' => ':attribute 字段是必须的当 :other 是 :value', + 'required_unless' => ':attribute 字段是必须的,除非 :other 是在 :values 中', + 'required_with' => ':attribute 字段是必须的当 :values 是存在的', + 'required_with_all' => ':attribute 字段是必须的当 :values 是存在的', + 'required_without' => ':attribute 字段是必须的当 :values 是不存在的', + 'required_without_all' => ':attribute 字段是必须的当 没有一个 :values 是存在的', + 'same' => ':attribute 和 :other 必须匹配', + 'size' => [ + 'numeric' => ':attribute 必须是 :size', + 'file' => ':attribute 必须是 :size kb', + 'string' => ':attribute 必须是 :size 个字符', + 'array' => ':attribute 必须包括 :size 项', + ], + 'starts_with' => ':attribute 必须以 :values 为开头', + 'string' => ':attribute 必须是一个字符串', + 'timezone' => ':attribute 必须是个有效的时区', + 'unique' => ':attribute 已存在', + 'uploaded' => ':attribute 上传失败', + 'url' => ':attribute 无效的格式', + 'uuid' => ':attribute 无效的UUID格式', + 'max_if' => [ + 'numeric' => '当 :other 为 :value 时 :attribute 不能大于 :max', + 'file' => '当 :other 为 :value 时 :attribute 不能大于 :max kb', + 'string' => '当 :other 为 :value 时 :attribute 不能大于 :max 个字符', + 'array' => '当 :other 为 :value 时 :attribute 最多只有 :max 个单元', + ], + 'min_if' => [ + 'numeric' => '当 :other 为 :value 时 :attribute 必须大于等于 :min', + 'file' => '当 :other 为 :value 时 :attribute 大小不能小于 :min kb', + 'string' => '当 :other 为 :value 时 :attribute 至少为 :min 个字符', + 'array' => '当 :other 为 :value 时 :attribute 至少有 :min 个单元', + ], + 'between_if' => [ + 'numeric' => '当 :other 为 :value 时 :attribute 必须介于 :min - :max 之间', + 'file' => '当 :other 为 :value 时 :attribute 必须介于 :min - :max kb 之间', + 'string' => '当 :other 为 :value 时 :attribute 必须介于 :min - :max 个字符之间', + 'array' => '当 :other 为 :value 时 :attribute 必须只有 :min - :max 个单元', + ], + /* + |-------------------------------------------------------------------------- + | Custom Validation Language Lines + |-------------------------------------------------------------------------- + | + | Here you may specify custom validation messages for attributes using the + | convention "attribute.rule" to name the lines. This makes it quick to + | specify a specific custom language line for a given attribute rule. + | + */ + + 'custom' => [ + 'attribute-name' => [ + 'rule-name' => 'custom-message', + ], + ], + + /* + |-------------------------------------------------------------------------- + | Custom Validation Attributes + |-------------------------------------------------------------------------- + | + | The following language lines are used to swap attribute place-holders + | with something more reader friendly such as E-Mail Address instead + | of "email". This simply helps us make messages a little cleaner. + | + */ + + 'attributes' => [], + 'phone_number' => ':attribute 必须为一个有效的电话号码', + 'telephone_number' => ':attribute 必须为一个有效的手机号码', + + 'chinese_word' => ':attribute 必须包含以下有效字符 (中文/英文,数字, 下划线)', + 'sequential_array' => ':attribute 必须是一个有序数组', +]; diff --git a/upload-test.html b/upload-test.html index 4785587..6cb0007 100644 --- a/upload-test.html +++ b/upload-test.html @@ -18,7 +18,7 @@ if (i >= 2000) {return;} $.ajax({ - url: 'http://127.0.0.1:9503/upload', + url: 'http://47.105.180.123:9503/upload', data: fileData, dataType: 'json', //服务器返回json格式数据 type: 'post', //HTTP请求类型