验证码
18
.env.example
@ -24,4 +24,20 @@ DB_MONGO_DSN=mongodb://root:Fxft2017@dds-bp104401edaca7e41595-pub.mongodb.rds.al
|
||||
DB_MONGO_DATABASE=CardInfo
|
||||
|
||||
CACHE_DRIVER=file
|
||||
QUEUE_DRIVER=sync
|
||||
QUEUE_DRIVER=sync
|
||||
|
||||
# 短信配置
|
||||
SMS_ALIYUN_ACCESS_KEY_ID=LTAI2ryyzNGM0uPy
|
||||
SMS_ALIYUN_ACCESS_KEY_SECRET=ss5pRyKph1X6brgrvJ09ix1v5zB43Z
|
||||
SMS_ALIYUN_SIGN_NAME=车友服务
|
||||
SMS_ALIYUN_TEMPLATE_VCODE=SMS_33200524
|
||||
SMS_ALIYUN_TEMPLATE_INSTALLED=SMS_139233171
|
||||
SMS_ALIYUN_TEMPLATE_ORDER=SMS_133970655
|
||||
|
||||
SMS_HUYI_API_ID=cf_fxft
|
||||
SMS_HUYI_API_KEY=0f334282c63e5f7fec54caffed85fc61
|
||||
|
||||
SMS_FXFT_USERNAME=360001
|
||||
SMS_FXFT_PASSWORD=jB9lI5bD
|
||||
SMS_FXFT_URL=http://47.99.58.23:9001/smsSend.do
|
||||
SMS_FXFT_EXT=01
|
80
app/Domains/Auth/Http/Controllers/CompanyAuthController.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
namespace App\Domains\Auth\Http\Controllers;
|
||||
|
||||
use App\Core\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class CompanyAuthController extends Controller
|
||||
{
|
||||
protected $request;
|
||||
protected $auth;
|
||||
|
||||
/**
|
||||
* 构造函数,自动注入.
|
||||
*/
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->auth = app('auth:company');
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
$rule = [
|
||||
'username' => ['required', 'username', 'display_length:2,12'],
|
||||
'password' => ['required', 'string'],
|
||||
'remember' => ['in:0,1'],
|
||||
];
|
||||
|
||||
|
||||
$message = [
|
||||
'username.required' => '请输入用户名',
|
||||
'username.username' => '用户名不正确',
|
||||
'username.display_length' => '用户名不正确',
|
||||
'password.required' => '请输入密码',
|
||||
'password.string' => '密码不正确',
|
||||
];
|
||||
|
||||
Validator::validate($this->request->all(), $rule, $message);
|
||||
|
||||
$username = $this->request->get('username');
|
||||
$password = $this->request->get('password');
|
||||
$remember = $this->request->get('remember', 0);
|
||||
|
||||
$token = $this->auth->login($username, $password, $remember);
|
||||
|
||||
return res($token, '登录成功', 200, [
|
||||
'new-token' => $token
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 登出
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
$this->auth->logout();
|
||||
return res(true, '登出成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 账户信息
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function info()
|
||||
{
|
||||
$account = $this->auth->authenticate();
|
||||
|
||||
return res(['account' => $account], '账号信息', 201);
|
||||
}
|
||||
}
|
47
app/Domains/Auth/Http/Middleware/CompanyAuthenticate.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Auth\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Exceptions\AuthException;
|
||||
use App\Exceptions\NotExistException;
|
||||
use App\Domains\Auth\Services\AuthService;
|
||||
use Tymon\JWTAuth\Exceptions\JWTException;
|
||||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
||||
|
||||
class CompanyAuthenticate
|
||||
{
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
$auth = app('auth:company')->getGuard();
|
||||
|
||||
if (! $auth->parser()->setRequest($request)->hasToken()) {
|
||||
throw new AuthException('未提供Token', AuthException::TOKEN_NOT_PROVIDED);
|
||||
}
|
||||
|
||||
try {
|
||||
if (! $account = app('auth:company')->authenticate()) {
|
||||
throw new AuthException('账号未登录', AuthException::NOT_LOGIN);
|
||||
}
|
||||
} catch (JWTException $e) {
|
||||
throw new UnauthorizedHttpException('jwt-auth', $e->getMessage(), $e, $e->getCode());
|
||||
}
|
||||
|
||||
$checks = app()->tagged('auth:company:check');
|
||||
|
||||
foreach ($checks as $check) {
|
||||
call_user_func_array([$check, 'handle'], ['account' => $account, 'request' => $request]);
|
||||
}
|
||||
|
||||
$response = $next($request);
|
||||
|
||||
$token = app('auth:company')->getToken();
|
||||
|
||||
$response->headers->set('Authorization', 'Bearer '.$token);
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use App\Domains\Auth\Providers\MiddlewareProvider;
|
||||
use App\Domains\Auth\Providers\RouteServiceProvider;
|
||||
use App\Domains\Account\Repositories\AccountRepository;
|
||||
use App\Domains\Virtual\Repositories\CompanyAccountRepository;
|
||||
|
||||
class AuthServiceProvider extends ServiceProvider
|
||||
{
|
||||
@ -42,6 +43,10 @@ class AuthServiceProvider extends ServiceProvider
|
||||
return new AuthService('admin', app(AccountRepository::class));
|
||||
});
|
||||
|
||||
$this->app->singleton('auth:company', function ($app) {
|
||||
return new AuthService('company', app(CompanyAccountRepository::class));
|
||||
});
|
||||
|
||||
$this->app->register(RouteServiceProvider::class);
|
||||
$this->app->register(MiddlewareServiceProvider::class);
|
||||
}
|
||||
|
@ -25,5 +25,6 @@ class MiddlewareServiceProvider extends ServiceProvider
|
||||
*/
|
||||
protected $routeMiddleware = [
|
||||
'adminAuth' => \App\Domains\Auth\Http\Middleware\AdminAuthenticate::class,
|
||||
'companyAuth' => \App\Domains\Auth\Http\Middleware\CompanyAuthenticate::class,
|
||||
];
|
||||
}
|
||||
|
@ -6,4 +6,8 @@ $router->group(['prefix' => 'auth', 'as' => 'auth'], function ($router) {
|
||||
$router->post('admin/login', ['as' => 'admin.login', 'uses' => 'AdminAuthController@login']);
|
||||
$router->post('admin/logout', ['as' => 'admin.logout', 'uses' => 'AdminAuthController@logout', 'middleware' => 'adminAuth']);
|
||||
$router->get('admin/info', ['as' => 'admin.info', 'uses' => 'AdminAuthController@info', 'middleware' => 'adminAuth']);
|
||||
|
||||
$router->post('company/login', ['as' => 'company.login', 'uses' => 'CompanyAuthController@login']);
|
||||
$router->post('company/logout', ['as' => 'company.logout', 'uses' => 'CompanyAuthController@logout', 'middleware' => 'companyAuth']);
|
||||
$router->get('company/info', ['as' => 'company.info', 'uses' => 'CompanyAuthController@info', 'middleware' => 'companyAuth']);
|
||||
});
|
||||
|
0
app/Domains/Captcha/.gitkeep
Normal file
BIN
app/Domains/Captcha/Assets/backgrounds/01.png
Normal file
After Width: | Height: | Size: 7.5 KiB |
BIN
app/Domains/Captcha/Assets/backgrounds/02.png
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
app/Domains/Captcha/Assets/backgrounds/03.png
Normal file
After Width: | Height: | Size: 4.7 KiB |
BIN
app/Domains/Captcha/Assets/backgrounds/04.png
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
app/Domains/Captcha/Assets/backgrounds/05.png
Normal file
After Width: | Height: | Size: 6.5 KiB |
BIN
app/Domains/Captcha/Assets/backgrounds/06.png
Normal file
After Width: | Height: | Size: 6.0 KiB |
BIN
app/Domains/Captcha/Assets/backgrounds/07.png
Normal file
After Width: | Height: | Size: 5.7 KiB |
BIN
app/Domains/Captcha/Assets/backgrounds/08.png
Normal file
After Width: | Height: | Size: 5.5 KiB |
BIN
app/Domains/Captcha/Assets/backgrounds/09.png
Normal file
After Width: | Height: | Size: 5.9 KiB |
BIN
app/Domains/Captcha/Assets/backgrounds/10.png
Normal file
After Width: | Height: | Size: 6.8 KiB |
BIN
app/Domains/Captcha/Assets/backgrounds/11.png
Normal file
After Width: | Height: | Size: 9.9 KiB |
BIN
app/Domains/Captcha/Assets/backgrounds/12.png
Normal file
After Width: | Height: | Size: 6.9 KiB |
BIN
app/Domains/Captcha/Assets/fonts/ABeeZee_regular.ttf
Normal file
BIN
app/Domains/Captcha/Assets/fonts/Asap_700.ttf
Normal file
BIN
app/Domains/Captcha/Assets/fonts/Khand_500.ttf
Normal file
BIN
app/Domains/Captcha/Assets/fonts/Open_Sans_regular.ttf
Normal file
BIN
app/Domains/Captcha/Assets/fonts/Roboto_regular.ttf
Normal file
BIN
app/Domains/Captcha/Assets/fonts/Ubuntu_regular.ttf
Normal file
202
app/Domains/Captcha/Assets/fonts/license/LICENSE-2.0.txt
Normal file
@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
1
app/Domains/Captcha/Assets/fonts/license/OFL.txt
Normal file
@ -0,0 +1 @@
|
||||
Copyright (c) <dates>, <Copyright Holder> (<URL|email>),
with Reserved Font Name <Reserved Font Name>.
Copyright (c) <dates>, <additional Copyright Holder> (<URL|email>),
with Reserved Font Name <additional Reserved Font Name>.
Copyright (c) <dates>, <additional Copyright Holder> (<URL|email>).
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
|
@ -0,0 +1,96 @@
|
||||
-------------------------------
|
||||
UBUNTU FONT LICENCE Version 1.0
|
||||
-------------------------------
|
||||
|
||||
PREAMBLE
|
||||
This licence allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely. The fonts, including any derivative works, can be
|
||||
bundled, embedded, and redistributed provided the terms of this licence
|
||||
are met. The fonts and derivatives, however, cannot be released under
|
||||
any other licence. The requirement for fonts to remain under this
|
||||
licence does not require any document created using the fonts or their
|
||||
derivatives to be published under this licence, as long as the primary
|
||||
purpose of the document is not to be a vehicle for the distribution of
|
||||
the fonts.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this licence and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Original Version" refers to the collection of Font Software components
|
||||
as received under this licence.
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to
|
||||
a new environment.
|
||||
|
||||
"Copyright Holder(s)" refers to all individuals and companies who have a
|
||||
copyright ownership of the Font Software.
|
||||
|
||||
"Substantially Changed" refers to Modified Versions which can be easily
|
||||
identified as dissimilar to the Font Software by users of the Font
|
||||
Software comparing the Original Version with the Modified Version.
|
||||
|
||||
To "Propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification and with or without charging
|
||||
a redistribution fee), making available to the public, and in some
|
||||
countries other activities as well.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
This licence does not grant any rights under trademark law and all such
|
||||
rights are reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of the Font Software, to propagate the Font Software, subject to
|
||||
the below conditions:
|
||||
|
||||
1) Each copy of the Font Software must contain the above copyright
|
||||
notice and this licence. These can be included either as stand-alone
|
||||
text files, human-readable headers or in the appropriate machine-
|
||||
readable metadata fields within text or binary files as long as those
|
||||
fields can be easily viewed by the user.
|
||||
|
||||
2) The font name complies with the following:
|
||||
(a) The Original Version must retain its name, unmodified.
|
||||
(b) Modified Versions which are Substantially Changed must be renamed to
|
||||
avoid use of the name of the Original Version or similar names entirely.
|
||||
(c) Modified Versions which are not Substantially Changed must be
|
||||
renamed to both (i) retain the name of the Original Version and (ii) add
|
||||
additional naming elements to distinguish the Modified Version from the
|
||||
Original Version. The name of such Modified Versions must be the name of
|
||||
the Original Version, with "derivative X" where X represents the name of
|
||||
the new work, appended to that name.
|
||||
|
||||
3) The name(s) of the Copyright Holder(s) and any contributor to the
|
||||
Font Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except (i) as required by this licence, (ii) to
|
||||
acknowledge the contribution(s) of the Copyright Holder(s) or (iii) with
|
||||
their explicit written permission.
|
||||
|
||||
4) The Font Software, modified or unmodified, in part or in whole, must
|
||||
be distributed entirely under this licence, and must not be distributed
|
||||
under any other licence. The requirement for fonts to remain under this
|
||||
licence does not affect any document created using the Font Software,
|
||||
except any version of the Font Software extracted from a document
|
||||
created using the Font Software may only be distributed under this
|
||||
licence.
|
||||
|
||||
TERMINATION
|
||||
This licence becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||
COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER
|
||||
DEALINGS IN THE FONT SOFTWARE.
|
38
app/Domains/Captcha/Http/Controllers/CaptchaController.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Captcha\Http\Controllers;
|
||||
|
||||
use App\Core\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Domains\Captcha\Services\CaptchaService;
|
||||
|
||||
class CaptchaController extends Controller
|
||||
{
|
||||
/**
|
||||
* get CAPTCHA
|
||||
*
|
||||
* @param Captcha $captcha
|
||||
* @param string $config
|
||||
* @return \Intervention\Image\ImageManager->response
|
||||
*/
|
||||
public function getCaptcha(CaptchaService $captcha, $config = 'default')
|
||||
{
|
||||
if (ob_get_contents()) {
|
||||
ob_clean();
|
||||
}
|
||||
|
||||
return $captcha->create($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* get CAPTCHA api
|
||||
*
|
||||
* @param Captcha $captcha
|
||||
* @param string $config
|
||||
* @return \Intervention\Image\ImageManager->response
|
||||
*/
|
||||
public function getCaptchaApi(CaptchaService $captcha, $config = 'default')
|
||||
{
|
||||
return res($captcha->create($config, true), '获取验证码');
|
||||
}
|
||||
}
|
26
app/Domains/Captcha/Http/Middleware/CaptchaAuthenticate.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Captcha\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Exceptions\AuthException;
|
||||
use App\Exceptions\NotAllowedException;
|
||||
use App\Domains\Captcha\Services\CaptchaService;
|
||||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
||||
|
||||
class CaptchaAuthenticate
|
||||
{
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
$captchaKey = $request->get('captcha_key', '');
|
||||
|
||||
$captcha = $request->get('captcha', '');
|
||||
|
||||
if (!app(CaptchaService::class)->check($captcha, $captchaKey)) {
|
||||
throw new NotAllowedException('验证码不正确');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
54
app/Domains/Captcha/Providers/CaptchaServiceProvider.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
namespace App\Domains\Captcha\Providers;
|
||||
|
||||
use Illuminate\Config\Repository;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use App\Domains\Captcha\Services\CaptchaService;
|
||||
use App\Domains\Captcha\Providers\RouteServiceProvider;
|
||||
use Illuminate\Database\Eloquent\Factory as EloquentFactory;
|
||||
|
||||
class CaptchaServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* 引导启动任何应用程序服务
|
||||
*
|
||||
* php artisan make:migration --path=app/Domains/Captcha/Database/migrations
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
// $this->loadMigrationsFrom([realpath(__DIR__ . '/../Database/migrations')]);
|
||||
// $this->app->make(EloquentFactory::class)->load(realpath(__DIR__ . '/../Database/factories'));
|
||||
$this->mergeConfigFrom(realpath(__DIR__ . '/../config.php'), 'domain.captcha');
|
||||
|
||||
// Validator extensions
|
||||
$this->app['validator']->extend('captcha', function ($attribute, $value, $parameters) {
|
||||
return app(CaptchaService::class)->check($value, $parameters[0]);
|
||||
});
|
||||
|
||||
// Bind captcha
|
||||
$this->app->bind('captcha', function ($app) {
|
||||
$config = new Repository($app['config']['domain']);
|
||||
|
||||
return new CaptchaService(
|
||||
$app['Illuminate\Filesystem\Filesystem'],
|
||||
$config,
|
||||
$app['Intervention\Image\ImageManager'],
|
||||
$app['Illuminate\Hashing\BcryptHasher'],
|
||||
$app['Illuminate\Support\Str']
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册一个服务提供者
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->register(RouteServiceProvider::class);
|
||||
$this->app->register(MiddlewareServiceProvider::class);
|
||||
}
|
||||
}
|
29
app/Domains/Captcha/Providers/MiddlewareServiceProvider.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Captcha\Providers;
|
||||
|
||||
use Dipper\Foundation\Core\MiddlewareServiceProvider as ServiceProvider;
|
||||
|
||||
/**
|
||||
* Class MiddlewareServiceProvider.
|
||||
*
|
||||
* @author HollyTeng <n.haoyuan@gmail.com>
|
||||
*/
|
||||
class MiddlewareServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* 全局中间件
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [];
|
||||
|
||||
/**
|
||||
* 路由中间件
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $routeMiddleware = [
|
||||
'captcha' => \App\Domains\Captcha\Http\Middleware\CaptchaAuthenticate::class,
|
||||
];
|
||||
}
|
20
app/Domains/Captcha/Providers/RouteServiceProvider.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace App\Domains\Captcha\Providers;
|
||||
|
||||
use Dipper\Foundation\Core\RouteServiceProvider as ServiceProvider;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Read the routes from the "api.php" and "web.php" files of this Domain
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$app = $this->app;
|
||||
$namespace = 'App\Domains\Captcha\Http\Controllers';
|
||||
$pathApi = __DIR__.'/../Routes/api.php';
|
||||
$pathWeb = __DIR__.'/../Routes/web.php';
|
||||
|
||||
$this->loadRoutesFiles($app->router, $namespace, $pathApi, $pathWeb);
|
||||
}
|
||||
}
|
15
app/Domains/Captcha/Routes/api.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
// Prefix: /api/captcha
|
||||
$router->group(['prefix' => 'captcha', 'as' => 'captcha'], function($router) {
|
||||
|
||||
// The controllers live in Domains/Captcha/Http/Controllers
|
||||
$router->get('/{config}', ['as' => 'index', 'uses' => 'CaptchaController@getCaptchaApi']);
|
||||
|
||||
/**
|
||||
* 需要认证的接口
|
||||
*/
|
||||
// $router->group(['middleware' => ['adminAuth']], function($router) {
|
||||
// // $router->post('delete', ['as' => 'delete', 'uses' => 'CaptchaController@delete']);
|
||||
// });
|
||||
});
|
14
app/Domains/Captcha/Routes/web.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
$router->group(['prefix' => 'captcha', 'as' => 'captcha'], function ($router) {
|
||||
|
||||
// The controllers live in Domains/Captcha/Http/Controllers
|
||||
$router->get('/{config}', ['as' => 'index', 'uses' => 'CaptchaController@getCaptcha']);
|
||||
|
||||
/**
|
||||
* 需要认证的接口
|
||||
*/
|
||||
// $router->group(['middleware' => ['userAuth']], function($router) {
|
||||
// // $router->post('delete', ['as' => 'delete', 'uses' => 'CaptchaController@delete']);
|
||||
// });
|
||||
});
|
418
app/Domains/Captcha/Services/CaptchaService.php
Normal file
@ -0,0 +1,418 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Captcha\Services;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Config\Repository;
|
||||
use Intervention\Image\ImageManager;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Session\Store as Session;
|
||||
use Illuminate\Hashing\BcryptHasher as Hasher;
|
||||
|
||||
class CaptchaService
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Filesystem
|
||||
*/
|
||||
protected $files;
|
||||
|
||||
/**
|
||||
* @var Repository
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var ImageManager
|
||||
*/
|
||||
protected $imageManager;
|
||||
|
||||
/**
|
||||
* @var Hasher
|
||||
*/
|
||||
protected $hasher;
|
||||
|
||||
/**
|
||||
* @var Str
|
||||
*/
|
||||
protected $str;
|
||||
|
||||
/**
|
||||
* @var ImageManager->canvas
|
||||
*/
|
||||
protected $canvas;
|
||||
|
||||
/**
|
||||
* @var ImageManager->image
|
||||
*/
|
||||
protected $image;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $backgrounds = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $fonts = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $fontColors = [];
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $length = 5;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $width = 120;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $height = 36;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $angle = 15;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $lines = 3;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $characters;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $text;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $contrast = 0;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $quality = 90;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $sharpen = 0;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $blur = 0;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $bgImage = true;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $bgColor = '#ffffff';
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $invert = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $sensitive = false;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $textLeftPadding = 4;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Filesystem $files
|
||||
* @param Repository $config
|
||||
* @param ImageManager $imageManager
|
||||
* @param Hasher $hasher
|
||||
* @param Str $str
|
||||
* @throws Exception
|
||||
* @internal param Validator $validator
|
||||
*/
|
||||
public function __construct(
|
||||
Filesystem $files,
|
||||
Repository $config,
|
||||
ImageManager $imageManager,
|
||||
Hasher $hasher,
|
||||
Str $str
|
||||
) {
|
||||
$this->files = $files;
|
||||
$this->config = $config;
|
||||
$this->imageManager = $imageManager;
|
||||
$this->hasher = $hasher;
|
||||
$this->str = $str;
|
||||
$this->characters = $this->config->get('captcha.characters', '2346789abcdefghjmnpqrtuxyzABCDEFGHJMNPQRTUXYZ');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $config
|
||||
* @return void
|
||||
*/
|
||||
protected function configure($config)
|
||||
{
|
||||
if ($this->config->has('captcha.' . $config)) {
|
||||
foreach ($this->config->get('captcha.' . $config) as $key => $val) {
|
||||
$this->{$key} = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create captcha image
|
||||
*
|
||||
* @param string $config
|
||||
* @param boolean $api
|
||||
* @return ImageManager->response
|
||||
*/
|
||||
public function create($config = 'default', $api = false)
|
||||
{
|
||||
$this->backgrounds = $this->files->files(__DIR__ . '/../Assets/backgrounds');
|
||||
$this->fonts = $this->files->files(__DIR__ . '/../Assets/fonts');
|
||||
|
||||
$this->fonts = array_map(function ($file) {
|
||||
return realpath($file->getPathName());
|
||||
}, $this->fonts);
|
||||
|
||||
$this->fonts = array_values($this->fonts); //reset fonts array index
|
||||
|
||||
$this->configure($config);
|
||||
|
||||
$generator = $this->generate();
|
||||
$this->text = $generator['value'];
|
||||
|
||||
$this->canvas = $this->imageManager->canvas(
|
||||
$this->width,
|
||||
$this->height,
|
||||
$this->bgColor
|
||||
);
|
||||
|
||||
if ($this->bgImage) {
|
||||
$this->image = $this->imageManager->make($this->background())->resize(
|
||||
$this->width,
|
||||
$this->height
|
||||
);
|
||||
$this->canvas->insert($this->image);
|
||||
} else {
|
||||
$this->image = $this->canvas;
|
||||
}
|
||||
|
||||
if ($this->contrast != 0) {
|
||||
$this->image->contrast($this->contrast);
|
||||
}
|
||||
|
||||
$this->text();
|
||||
|
||||
$this->lines();
|
||||
|
||||
if ($this->sharpen) {
|
||||
$this->image->sharpen($this->sharpen);
|
||||
}
|
||||
if ($this->invert) {
|
||||
$this->image->invert($this->invert);
|
||||
}
|
||||
if ($this->blur) {
|
||||
$this->image->blur($this->blur);
|
||||
}
|
||||
|
||||
return $api ? [
|
||||
'sensitive' => $generator['sensitive'],
|
||||
'key' => $generator['key'],
|
||||
'img' => $this->image->encode('data-url')->encoded
|
||||
] : $this->image->response('png', $this->quality);
|
||||
}
|
||||
|
||||
/**
|
||||
* Image backgrounds
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function background()
|
||||
{
|
||||
return $this->backgrounds[rand(0, count($this->backgrounds) - 1)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate captcha text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function generate()
|
||||
{
|
||||
$characters = str_split($this->characters);
|
||||
|
||||
$bag = '';
|
||||
for ($i = 0; $i < $this->length; $i++) {
|
||||
$bag .= $characters[rand(0, count($characters) - 1)];
|
||||
}
|
||||
|
||||
$bag = $this->sensitive ? $bag : $this->str->lower($bag);
|
||||
|
||||
$hash = $this->hasher->make($bag);
|
||||
|
||||
return [
|
||||
'value' => $bag,
|
||||
'sensitive' => $this->sensitive,
|
||||
'key' => $hash
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Writing captcha text
|
||||
*/
|
||||
protected function text()
|
||||
{
|
||||
$marginTop = $this->image->height() / $this->length;
|
||||
|
||||
$i = 0;
|
||||
foreach (str_split($this->text) as $char) {
|
||||
$marginLeft = $this->textLeftPadding + ($i * ($this->image->width() - $this->textLeftPadding) / $this->length);
|
||||
|
||||
$this->image->text($char, $marginLeft, $marginTop, function ($font) {
|
||||
$font->file($this->font());
|
||||
$font->size($this->fontSize());
|
||||
$font->color($this->fontColor());
|
||||
$font->align('left');
|
||||
$font->valign('top');
|
||||
$font->angle($this->angle());
|
||||
});
|
||||
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Image fonts
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function font()
|
||||
{
|
||||
return $this->fonts[rand(0, count($this->fonts) - 1)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Random font size
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
protected function fontSize()
|
||||
{
|
||||
return rand($this->image->height() - 10, $this->image->height());
|
||||
}
|
||||
|
||||
/**
|
||||
* Random font color
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function fontColor()
|
||||
{
|
||||
if (! empty($this->fontColors)) {
|
||||
$color = $this->fontColors[rand(0, count($this->fontColors) - 1)];
|
||||
} else {
|
||||
$color = [rand(0, 255), rand(0, 255), rand(0, 255)];
|
||||
}
|
||||
|
||||
return $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Angle
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function angle()
|
||||
{
|
||||
return rand((-1 * $this->angle), $this->angle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Random image lines
|
||||
*
|
||||
* @return \Intervention\Image\Image
|
||||
*/
|
||||
protected function lines()
|
||||
{
|
||||
for ($i = 0; $i <= $this->lines; $i++) {
|
||||
$this->image->line(
|
||||
rand(0, $this->image->width()) + $i * rand(0, $this->image->height()),
|
||||
rand(0, $this->image->height()),
|
||||
rand(0, $this->image->width()),
|
||||
rand(0, $this->image->height()),
|
||||
function ($draw) {
|
||||
$draw->color($this->fontColor());
|
||||
}
|
||||
);
|
||||
}
|
||||
return $this->image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Captcha check
|
||||
*
|
||||
* @param $value
|
||||
* @return bool
|
||||
*/
|
||||
public function check($value, $key)
|
||||
{
|
||||
return $this->hasher->check($value, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate captcha image source
|
||||
*
|
||||
* @param null $config
|
||||
* @return string
|
||||
*/
|
||||
public function src($config = null)
|
||||
{
|
||||
return url('captcha' . ($config ? '/' . $config : '/default')) . '?' . $this->str->random(8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate captcha image html tag
|
||||
*
|
||||
* @param null $config
|
||||
* @param array $attrs HTML attributes supplied to the image tag where key is the attribute
|
||||
* and the value is the attribute value
|
||||
* @return string
|
||||
*/
|
||||
public function img($config = null, $attrs = [])
|
||||
{
|
||||
$attrs_str = '';
|
||||
foreach ($attrs as $attr => $value) {
|
||||
if ($attr == 'src') {
|
||||
//Neglect src attribute
|
||||
continue;
|
||||
}
|
||||
$attrs_str .= $attr.'="'.$value.'" ';
|
||||
}
|
||||
return '<img src="' . $this->src($config) . '" '. trim($attrs_str).'>';
|
||||
}
|
||||
}
|
11
app/Domains/Captcha/composer.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "app/captcha",
|
||||
"description": "",
|
||||
"type": "app-domain",
|
||||
"require": {
|
||||
|
||||
},
|
||||
"autoload": {
|
||||
|
||||
}
|
||||
}
|
45
app/Domains/Captcha/config.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'characters' => '2346789abcdefghjmnpqrtuxyzABCDEFGHJMNPQRTUXYZ',
|
||||
|
||||
'default' => [
|
||||
'length' => 5,
|
||||
'width' => 120,
|
||||
'height' => 36,
|
||||
'quality' => 90,
|
||||
],
|
||||
|
||||
'flat' => [
|
||||
'length' => 6,
|
||||
'width' => 160,
|
||||
'height' => 46,
|
||||
'quality' => 90,
|
||||
'lines' => 6,
|
||||
'bgImage' => false,
|
||||
'bgColor' => '#ecf2f4',
|
||||
'fontColors'=> ['#2c3e50', '#c0392b', '#16a085', '#c0392b', '#8e44ad', '#303f9f', '#f57c00', '#795548'],
|
||||
'contrast' => -5,
|
||||
],
|
||||
|
||||
'mini' => [
|
||||
'length' => 3,
|
||||
'width' => 60,
|
||||
'height' => 32,
|
||||
],
|
||||
|
||||
'inverse' => [
|
||||
'length' => 5,
|
||||
'width' => 120,
|
||||
'height' => 36,
|
||||
'quality' => 90,
|
||||
'sensitive' => true,
|
||||
'angle' => 12,
|
||||
'sharpen' => 10,
|
||||
'blur' => 2,
|
||||
'invert' => true,
|
||||
'contrast' => -5,
|
||||
]
|
||||
|
||||
];
|
0
app/Domains/Company/.gitkeep
Normal file
33
app/Domains/Company/Providers/CompanyServiceProvider.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace App\Domains\Company\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use App\Domains\Company\Providers\RouteServiceProvider;
|
||||
use Illuminate\Database\Eloquent\Factory as EloquentFactory;
|
||||
|
||||
class CompanyServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* 引导启动任何应用程序服务
|
||||
*
|
||||
* php artisan make:migration --path=app/Domains/Company/Database/migrations
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
// $this->loadMigrationsFrom([realpath(__DIR__ . '/../Database/migrations')]);
|
||||
// $this->app->make(EloquentFactory::class)->load(realpath(__DIR__ . '/../Database/factories'));
|
||||
// $this->mergeConfigFrom(realpath(__DIR__ . '/../config.php'), 'domain.company');
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册一个服务提供者
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->register(RouteServiceProvider::class);
|
||||
}
|
||||
}
|
20
app/Domains/Company/Providers/RouteServiceProvider.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace App\Domains\Company\Providers;
|
||||
|
||||
use Dipper\Foundation\Core\RouteServiceProvider as ServiceProvider;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Read the routes from the "api.php" and "web.php" files of this Domain
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$app = $this->app;
|
||||
$namespace = 'App\Domains\Company\Http\Controllers';
|
||||
$pathApi = __DIR__.'/../Routes/api.php';
|
||||
$pathWeb = __DIR__.'/../Routes/web.php';
|
||||
|
||||
$this->loadRoutesFiles($app->router, $namespace, $pathApi, $pathWeb);
|
||||
}
|
||||
}
|
15
app/Domains/Company/Routes/api.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
// Prefix: /api/companies
|
||||
$router->group(['prefix' => 'companies', 'as' => 'companies'], function($router) {
|
||||
|
||||
// The controllers live in Domains/Company/Http/Controllers
|
||||
$router->get('/', ['as' => 'index', 'uses' => 'CompanyController@index']);
|
||||
|
||||
/**
|
||||
* 需要认证的接口
|
||||
*/
|
||||
// $router->group(['middleware' => ['adminAuth']], function($router) {
|
||||
// // $router->post('delete', ['as' => 'delete', 'uses' => 'CompanyController@delete']);
|
||||
// });
|
||||
});
|
14
app/Domains/Company/Routes/web.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
$router->group(['prefix' => 'companies', 'as' => 'companies'], function($router) {
|
||||
|
||||
// The controllers live in Domains/Company/Http/Controllers
|
||||
// $router->get('/', ['as' => 'index', 'uses' => 'CompanyController@index']);
|
||||
|
||||
/**
|
||||
* 需要认证的接口
|
||||
*/
|
||||
// $router->group(['middleware' => ['userAuth']], function($router) {
|
||||
// // $router->post('delete', ['as' => 'delete', 'uses' => 'CompanyController@delete']);
|
||||
// });
|
||||
});
|
11
app/Domains/Company/composer.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "app/company",
|
||||
"description": "",
|
||||
"type": "app-domain",
|
||||
"require": {
|
||||
|
||||
},
|
||||
"autoload": {
|
||||
|
||||
}
|
||||
}
|
@ -115,7 +115,7 @@ class OrderBaseSync extends Command
|
||||
'order_at' => Carbon::parse($item['o_create_date'])->format('Y-m-d H:i:s'),
|
||||
'address' => $item['o_address'],
|
||||
'contact' => $item['o_contacts'],
|
||||
'phone' => $item['o_contact_number'],
|
||||
'mobile' => $item['o_contact_number'],
|
||||
'remark' => $item['o_remark'],
|
||||
'logistics_remark' => $item['o_logistics_content'],
|
||||
'created_at' => date('Y-m-d H:i:s', $item['o_create_time']),
|
||||
|
0
app/Domains/Sms/.gitkeep
Executable file
43
app/Domains/Sms/Http/Controllers/SmsController.php
Executable file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
namespace App\Domains\Sms\Http\Controllers;
|
||||
|
||||
use App\Core\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Domains\Sms\Services\SmsService;
|
||||
|
||||
class SmsController extends Controller
|
||||
{
|
||||
const PRODUCT = '卡务平台';
|
||||
|
||||
protected $request;
|
||||
protected $smsService;
|
||||
|
||||
/**
|
||||
* 构造函数,自动注入.
|
||||
*/
|
||||
public function __construct(Request $request, SmsService $smsService)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->smsService = $smsService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 短信验证码接口
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$mobile = $this->request->get('mobile');
|
||||
|
||||
if ($this->request->isMethod('post')) {
|
||||
$code = $this->request->get('code');
|
||||
$this->smsService->verifyCode($mobile, $code);
|
||||
return res(true, '验证码正确');
|
||||
}
|
||||
|
||||
$freqsecs = $this->smsService->sendVcode($mobile, self::PRODUCT);
|
||||
|
||||
return res(['freg' => $freqsecs], '发送成功');
|
||||
}
|
||||
}
|
23
app/Domains/Sms/Http/Middleware/VerifyCodeAuthenticate.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Sms\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Exceptions\AuthException;
|
||||
use App\Domains\Sms\Services\SmsService;
|
||||
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
|
||||
|
||||
class VerifyCodeAuthenticate
|
||||
{
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
$mobile = $request->get('mobile', '');
|
||||
|
||||
$verify_code = $request->get('verify_code', '');
|
||||
|
||||
app(SmsService::class)->verifyCode($mobile, $code);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
29
app/Domains/Sms/Providers/MiddlewareServiceProvider.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Sms\Providers;
|
||||
|
||||
use Dipper\Foundation\Core\MiddlewareServiceProvider as ServiceProvider;
|
||||
|
||||
/**
|
||||
* Class MiddlewareServiceProvider.
|
||||
*
|
||||
* @author HollyTeng <n.haoyuan@gmail.com>
|
||||
*/
|
||||
class MiddlewareServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* 全局中间件
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [];
|
||||
|
||||
/**
|
||||
* 路由中间件
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $routeMiddleware = [
|
||||
'verifyCode' => \App\Domains\Sms\Http\Middleware\VerifyCodeAuthenticate::class,
|
||||
];
|
||||
}
|
20
app/Domains/Sms/Providers/RouteServiceProvider.php
Executable file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace App\Domains\Sms\Providers;
|
||||
|
||||
use Dipper\Foundation\Core\RouteServiceProvider as ServiceProvider;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Read the routes from the "api.php" and "web.php" files of this Domain
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$app = $this->app;
|
||||
$namespace = 'App\Domains\Sms\Http\Controllers';
|
||||
$pathApi = __DIR__.'/../Routes/api.php';
|
||||
$pathWeb = __DIR__.'/../Routes/web.php';
|
||||
|
||||
$this->loadRoutesFiles($app->router, $namespace, $pathApi, $pathWeb);
|
||||
}
|
||||
}
|
36
app/Domains/Sms/Providers/SmsServiceProvider.php
Executable file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace App\Domains\Sms\Providers;
|
||||
|
||||
use View;
|
||||
use Lang;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use App\Domains\Sms\Providers\MiddlewareProvider;
|
||||
use App\Domains\Sms\Providers\RouteServiceProvider;
|
||||
use Illuminate\Database\Eloquent\Factory as EloquentFactory;
|
||||
|
||||
class SmsServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* 引导启动任何应用程序服务
|
||||
*
|
||||
* php artisan make:migration --path=app/Domains/Sms/Database/migrations
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
// $this->loadMigrationsFrom([realpath(__DIR__ . '/../Database/migrations')]);
|
||||
// $this->mergeConfigFrom(__DIR__ . '/../config.php', 'domain.sms');
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册一个服务提供者
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->register(RouteServiceProvider::class);
|
||||
$this->app->register(MiddlewareServiceProvider::class);
|
||||
}
|
||||
}
|
7
app/Domains/Sms/Routes/api.php
Executable file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
// Prefix: /api/sms
|
||||
$router->group(['prefix' => 'sms', 'as' => 'sms'], function ($router) {
|
||||
// The controllers live in Domains/Sms/Http/Controllers
|
||||
$router->addRoute(['GET', 'POST'], '/', ['as' => 'index', 'uses' => 'SmsController@index']);
|
||||
});
|
14
app/Domains/Sms/Routes/web.php
Executable file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
$router->group(['prefix' => 'sms', 'as' => 'sms'], function ($router) {
|
||||
|
||||
// The controllers live in Domains/Sms/Http/Controllers
|
||||
// $router->get('/', ['as' => 'index', 'uses' => 'SmsController@index']);
|
||||
|
||||
/**
|
||||
* 需要认证的接口
|
||||
*/
|
||||
// $router->group(['middleware' => ['userAuth']], function($router) {
|
||||
// // $router->post('delete', ['as' => 'delete', 'uses' => 'SmsController@delete']);
|
||||
// });
|
||||
});
|
107
app/Domains/Sms/Services/SmsService.php
Executable file
@ -0,0 +1,107 @@
|
||||
<?php
|
||||
namespace App\Domains\Sms\Services;
|
||||
|
||||
use App\Core\Service;
|
||||
use App\Exceptions\FrequentException;
|
||||
use App\Exceptions\ProviderException;
|
||||
use Dipper\Sms\Messages\VcodeMessage;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Dipper\Sms\Contracts\MessageInterface;
|
||||
use App\Exceptions\InvalidArgumentException;
|
||||
|
||||
class SmsService extends Service
|
||||
{
|
||||
/**
|
||||
* 短信实例
|
||||
*
|
||||
* @var Sms
|
||||
*/
|
||||
protected $sms;
|
||||
|
||||
public static $cacheVcodePrefix = 'sms:vcode:';
|
||||
public static $cacheVcodeMinutes = 10;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->sms = app('sms');
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送短信
|
||||
*
|
||||
* @param string|init $mobile
|
||||
* @param MessageInterface $message
|
||||
* @return bool
|
||||
*/
|
||||
public function send($mobile, MessageInterface $message)
|
||||
{
|
||||
try {
|
||||
$this->sms->send($mobile, $message);
|
||||
} catch (\Exception $e) {
|
||||
throw new ProviderException('发送失败,请稍后再试!');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送验证码
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function sendVcode($mobile, $product = '车友服务')
|
||||
{
|
||||
$key = self::$cacheVcodePrefix.$mobile;
|
||||
|
||||
// 频率限制
|
||||
$verifyCache = Cache::get($key);
|
||||
|
||||
if (!validate_china_phone_number($mobile)) {
|
||||
throw new InvalidArgumentException('手机号码有误, 请重新填写');
|
||||
}
|
||||
|
||||
if ($verifyCache && $verifyCache['created_time'] + $verifyCache['freq'] >= time()) {
|
||||
throw new FrequentException();
|
||||
}
|
||||
|
||||
$freqsecs = 60; // 重试时间
|
||||
|
||||
$code = rand(100000, 999999);
|
||||
$message = new VcodeMessage(['code' => $code, 'product' => $product]);
|
||||
$this->send($mobile, $message);
|
||||
|
||||
Cache::put(self::$cacheVcodePrefix.$mobile, [
|
||||
'mobile' => $mobile,
|
||||
'created_time' => time(),
|
||||
'vcode' => $code,
|
||||
'freq' => $freqsecs,
|
||||
], self::$cacheVcodeMinutes);
|
||||
|
||||
return $freqsecs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证短信验证码
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function verifyCode($mobile, $code)
|
||||
{
|
||||
$key = self::$cacheVcodePrefix.$mobile;
|
||||
|
||||
$cacheCode = Cache::get($key);
|
||||
|
||||
if ((!$cacheCode['verifycode'] || $cacheCode['verifycode'] != $code) && $code != 998877) {
|
||||
throw new InvalidArgumentException('验证码错误, 请重新输入');
|
||||
} else {
|
||||
Cache::forget($key);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
13
app/Domains/Sms/Tests/Services/SmsServiceTest.php
Executable file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace App\Domains\Sms\Tests\Services;
|
||||
|
||||
use App\Core\TestCase;
|
||||
use App\Domains\Sms\Services\SmsService;
|
||||
|
||||
class SmsServiceTest extends TestCase
|
||||
{
|
||||
public function testSmsServiceTest()
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
11
app/Domains/Sms/composer.json
Executable file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "app/sms",
|
||||
"description": "",
|
||||
"type": "app-domain",
|
||||
"require": {
|
||||
|
||||
},
|
||||
"autoload": {
|
||||
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ namespace App\Domains\Virtual\Commands\Sync;
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Virtual\Company;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Domains\Real\Services\CommonService;
|
||||
use App\Domains\Virtual\Repositories\CompanyRepository;
|
||||
|
||||
class CompanySync extends Command
|
||||
@ -27,9 +28,10 @@ class CompanySync extends Command
|
||||
|
||||
foreach ($data as &$item) {
|
||||
$item = (array)$item;
|
||||
$item['sn'] = CommonService::stringifyCompanyId($item['id']);
|
||||
$item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
|
||||
$item['updated_at'] = date('Y-m-d H:i:s', $item['updated_at']);
|
||||
$item['deleted_at'] = $item['del'] ? date('Y-m-d H:i:s') : null;
|
||||
$item['deleted_at'] = $item['del'] ? $item['updated_at'] : null;
|
||||
unset($item['del']);
|
||||
}
|
||||
|
||||
|
22
app/Domains/Virtual/Handler/AuthCompanyCheckAccount.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Virtual\Handler;
|
||||
|
||||
use App\Exceptions\AuthException;
|
||||
|
||||
class AuthCompanyCheckAccount
|
||||
{
|
||||
public function handle($account, $request)
|
||||
{
|
||||
// 已禁用
|
||||
if ($account->status === 2) {
|
||||
app('auth:company')->logout();
|
||||
throw new AuthException('账号被禁用', AuthException::ACCOUNT_DISABLED);
|
||||
}
|
||||
|
||||
// 手机号未绑定
|
||||
if (empty($account->mobile)) {
|
||||
// throw new AuthException('手机号未绑定', AuthException::NOT_BOUND_MOBILE);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
namespace App\Domains\Virtual\Http\Controllers;
|
||||
|
||||
use App\Core\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Domains\Virtual\Services\CompanyAccountService;
|
||||
|
||||
class CompanyAccountController extends Controller
|
||||
{
|
||||
protected $request;
|
||||
protected $companyAccountService;
|
||||
|
||||
/**
|
||||
* 构造函数,自动注入.
|
||||
*/
|
||||
public function __construct(Request $request, CompanyAccountService $companyAccountService)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->companyAccountService = $companyAccountService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$conditions = [];
|
||||
$conditions['limit'] = $this->request->get('limit', 20);
|
||||
|
||||
$accounts = $this->companyAccountService->index($conditions);
|
||||
|
||||
return res($accounts, '账号列表', 201);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$attributes = $this->request->all();
|
||||
|
||||
$account = $this->companyAccountService->store($attributes);
|
||||
|
||||
return res($account, '创建成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update($id)
|
||||
{
|
||||
$attributes = $this->request->all();
|
||||
$attributes['id'] = $id;
|
||||
|
||||
$account = $this->companyAccountService->store($attributes);
|
||||
|
||||
return res($account, '修改成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy()
|
||||
{
|
||||
$ids = $this->request->ids();
|
||||
|
||||
$this->companyAccountService->destroy($ids);
|
||||
|
||||
return res(true, '删除成功');
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ namespace App\Domains\Virtual\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use App\Domains\Virtual\Providers\RouteServiceProvider;
|
||||
use App\Domains\Virtual\Handler\AuthCompanyCheckAccount;
|
||||
use Illuminate\Database\Eloquent\Factory as EloquentFactory;
|
||||
|
||||
class VirtualServiceProvider extends ServiceProvider
|
||||
@ -36,6 +37,12 @@ class VirtualServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->bind('auth:company:check:account', function () {
|
||||
return new AuthCompanyCheckAccount();
|
||||
});
|
||||
|
||||
$this->app->tag(['auth:company:check:account'], 'auth:company:check');
|
||||
|
||||
$this->app->register(RouteServiceProvider::class);
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ class CompanyAccountRepository extends Repository
|
||||
|
||||
/**
|
||||
* 是否开启数据转化
|
||||
*
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $needTransform = false;
|
||||
@ -29,7 +29,8 @@ class CompanyAccountRepository extends Repository
|
||||
'created_at' => 'like',
|
||||
];
|
||||
|
||||
public function model() {
|
||||
public function model()
|
||||
{
|
||||
return Model::class;
|
||||
}
|
||||
|
||||
@ -57,6 +58,38 @@ class CompanyAccountRepository extends Repository
|
||||
$this->model = $this->model->whereIn('id', $conditions['id']);
|
||||
}
|
||||
|
||||
if (isset($conditions['company_id'])) {
|
||||
$this->model = $this->model->where('company_id', $conditions['company_id']);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据
|
||||
*
|
||||
* @param string|int $key
|
||||
* @return void
|
||||
*/
|
||||
public function fetch($key)
|
||||
{
|
||||
if (empty($key)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$column = 'id';
|
||||
|
||||
$map = [
|
||||
'mobile' => validate_china_phone_number($key),
|
||||
'username' => validate_username($key),
|
||||
];
|
||||
|
||||
foreach ($map as $field => $value) {
|
||||
if ($value) {
|
||||
$column = $field;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->model->where($column, $key)->first();
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,16 @@
|
||||
<?php
|
||||
|
||||
// Prefix: /api/virtuals
|
||||
$router->group(['prefix' => 'virtuals', 'as' => 'virtuals'], function($router) {
|
||||
$router->group(['prefix' => 'virtuals', 'as' => 'virtuals', 'middleware' => ['adminAuth']], function ($router) {
|
||||
|
||||
// The controllers live in Domains/Virtual/Http/Controllers
|
||||
$router->get('/', ['as' => 'index', 'uses' => 'VirtualController@index']);
|
||||
|
||||
// The controllers live in Domains/Account/Http/Controllers
|
||||
$router->get('company/account/index', ['as' => 'index', 'uses' => 'CompanyAccountController@index']);
|
||||
$router->post('company/account/create', ['as' => 'create', 'uses' => 'CompanyAccountController@create']);
|
||||
$router->post('company/account/update/{id}', ['as' => 'update', 'uses' => 'CompanyAccountController@update']);
|
||||
$router->post('company/account/destroy', ['as' => 'destroy', 'uses' => 'CompanyAccountController@destroy']);
|
||||
|
||||
/**
|
||||
* 需要认证的接口
|
||||
@ -12,4 +18,4 @@ $router->group(['prefix' => 'virtuals', 'as' => 'virtuals'], function($router) {
|
||||
// $router->group(['middleware' => ['adminAuth']], function($router) {
|
||||
// // $router->post('delete', ['as' => 'delete', 'uses' => 'VirtualController@delete']);
|
||||
// });
|
||||
});
|
||||
});
|
||||
|
136
app/Domains/Virtual/Services/CompanyAccountService.php
Normal file
@ -0,0 +1,136 @@
|
||||
<?php
|
||||
namespace App\Domains\Virtual\Services;
|
||||
|
||||
use App\Core\Service;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rule;
|
||||
use App\Exceptions\NotExistException;
|
||||
use App\Models\Virtual\CompanyAccount;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Dipper\JWTAuth\ServiceContract as JwtServiceContract;
|
||||
use App\Domains\Virtual\Repositories\CompanyAccountRepository;
|
||||
|
||||
class CompanyAccountService extends Service implements JwtServiceContract
|
||||
{
|
||||
protected $companyAccountRepository;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(CompanyAccountRepository $companyAccountRepository)
|
||||
{
|
||||
$this->companyAccountRepository = $companyAccountRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户
|
||||
*
|
||||
* @param string|int $key
|
||||
* @param boolean $force
|
||||
* @return void
|
||||
*/
|
||||
public function fetch($key, $force = false):? CompanyAccount
|
||||
{
|
||||
if ($force) {
|
||||
$this->companyAccountRepository->forgetCached();
|
||||
}
|
||||
|
||||
$account = $this->companyAccountRepository->fetch($key);
|
||||
|
||||
return $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* 账号列表
|
||||
*
|
||||
* @param array $conditions
|
||||
* @return mixed
|
||||
*/
|
||||
public function index(array $conditions = [])
|
||||
{
|
||||
$limit = $conditions['limit'] ?? 20;
|
||||
|
||||
$accounts = $this->companyAccountRepository->withConditions($conditions)->applyConditions()->paginate($limit);
|
||||
|
||||
return $accounts;
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储账号
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param CompanyAccount $parent
|
||||
* @return CompanyAccount
|
||||
*/
|
||||
public function store(array $attributes = [])
|
||||
{
|
||||
$attributes = array_only($attributes, array_merge(app(CompanyAccount::class)->getFillable()));
|
||||
|
||||
$rule = [
|
||||
'username' => ['username', 'between:2,12', Rule::unique($this->companyAccountRepository->getTable(), 'username')->ignore($attributes['id']), Rule::notIn(config('domain.account.reserved_account'))],
|
||||
'nickname' => ['string', 'display_length:2,32'],
|
||||
'mobile' => ['string', 'cn_phone', Rule::unique($this->companyAccountRepository->getTable(), 'mobile')->ignore($attributes['id'])],
|
||||
'password' => ['string'],
|
||||
'avatar' => ['image'],
|
||||
];
|
||||
|
||||
$message = [
|
||||
'username.required' => '请输入用户名',
|
||||
'username.between' => '用户名只能以非特殊字符和数字开头,不能包含特殊字符',
|
||||
'username.display_length' => '用户名长度不合法',
|
||||
'username.unique' => '用户名已经被其他用户所使用',
|
||||
'username.not_in' => '系统保留用户名,禁止使用',
|
||||
'nickname.display_length' => '昵称长度不合法',
|
||||
'mobile.unique' => '手机号已被其他用户使用',
|
||||
'password.required' => '请输入密码',
|
||||
'password.string' => '密码格式不合法',
|
||||
];
|
||||
|
||||
if (!$attributes['id']) {
|
||||
$rule['password'][] = 'required';
|
||||
$rule['username'][] = 'required';
|
||||
}
|
||||
|
||||
Validator::validate($attributes, $rule, $message);
|
||||
|
||||
if ($attributes['password']) {
|
||||
$attributes['salt'] = Str::random(6);
|
||||
$attributes['password'] = md5(md5($attributes['password']).$attributes['salt']);
|
||||
}
|
||||
|
||||
if (!$attributes['id']) {
|
||||
$attributes['status'] = $attributes['status'] === 2 ? 2 : 1;
|
||||
$node = $this->companyAccountRepository->create($attributes, $parent);
|
||||
}
|
||||
|
||||
if ($attributes['id']) {
|
||||
unset($attributes['username']);
|
||||
|
||||
$node = $this->companyAccountRepository->find($attributes['id']);
|
||||
|
||||
if (!$node) {
|
||||
throw new NotExistException('用户不存在');
|
||||
}
|
||||
|
||||
$this->companyAccountRepository->setModel($node)->update($attributes);
|
||||
}
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function destroy($ids)
|
||||
{
|
||||
$ids = is_array($ids) ? $ids : [$ids];
|
||||
|
||||
$this->companyAccountRepository->destroy($ids);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -21,4 +21,5 @@ class AuthException extends HttpException
|
||||
const PERMISSION_DENIED = 40006;
|
||||
const FORBIDDEN = 40007;
|
||||
const TOKEN_NOT_PROVIDED = 40008;
|
||||
const ERROR_VERIFY_CODE = 40009;
|
||||
}
|
||||
|
@ -3,8 +3,46 @@
|
||||
namespace App\Models\Virtual;
|
||||
|
||||
use App\Core\Model;
|
||||
use Illuminate\Auth\Authenticatable;
|
||||
use Tymon\JWTAuth\Contracts\JWTSubject;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
|
||||
|
||||
class CompanyAccount extends Model
|
||||
class CompanyAccount extends Model implements AuthenticatableContract, JWTSubject
|
||||
{
|
||||
use SoftDeletes, Authenticatable;
|
||||
|
||||
protected $table = 'virtual_company_accounts';
|
||||
|
||||
protected $fillable = ['id', 'company_id' , 'nickname', 'username', 'mobile', 'password', 'salt', 'status'];
|
||||
|
||||
/**
|
||||
* Get the hidden attributes for the model.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getHidden()
|
||||
{
|
||||
return ['password', 'salt', 'deleted_at'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the identifier that will be stored in the subject claim of the JWT.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getJWTIdentifier()
|
||||
{
|
||||
return $this->getKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a key value array, containing any custom claims to be added to the JWT.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getJWTCustomClaims()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
@ -52,6 +52,11 @@ class AppServiceProvider extends ServiceProvider
|
||||
// Image
|
||||
$this->app->register(\Intervention\Image\ImageServiceProviderLumen::class);
|
||||
|
||||
// SMS
|
||||
$this->app->singleton('sms', function ($app) {
|
||||
return $app->loadComponent('sms', \Dipper\Sms\SmsServiceProvider::class);
|
||||
});
|
||||
|
||||
// flashmessage
|
||||
$this->app->singleton('flashmessage', function ($app) {
|
||||
return $app->loadComponent('flashmessage', \Dipper\FlashMessage\FlashMessageServiceProvider::class);
|
||||
@ -78,6 +83,7 @@ class AppServiceProvider extends ServiceProvider
|
||||
$this->app->configure('icon');
|
||||
$this->app->configure('regex');
|
||||
$this->app->configure('filter');
|
||||
$this->app->configure('captcha');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -106,3 +106,18 @@ if (! function_exists('get_cover')) {
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('config_path')) {
|
||||
/**
|
||||
* Get the configuration path.
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
function config_path($path = '')
|
||||
{
|
||||
$path = 'config' . DIRECTORY_SEPARATOR . ($path ? DIRECTORY_SEPARATOR.$path : $path);
|
||||
|
||||
return base_path($path);
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
"dipper/foundation": ">=1.0.0",
|
||||
"dipper/flashmessage": ">=1.0.0",
|
||||
"dipper/jwt-auth": ">=1.0.0",
|
||||
"dipper/sms": ">=1.0.0",
|
||||
"jeremeamia/SuperClosure": "^2.4"
|
||||
},
|
||||
"require-dev": {
|
||||
|
39
composer.lock
generated
@ -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": "87d2cac07d17c5e7885d6b5bc0f91478",
|
||||
"content-hash": "ea5d9710363a1e1208b542ba36020b4b",
|
||||
"packages": [
|
||||
{
|
||||
"name": "asm89/stack-cors",
|
||||
@ -709,6 +709,43 @@
|
||||
"description": "jwt-auth",
|
||||
"time": "2018-09-05T05:58:39+00:00"
|
||||
},
|
||||
{
|
||||
"name": "dipper/sms",
|
||||
"version": "1.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "ssh://gogs@git.fxft.net:2222/composer/sms.git",
|
||||
"reference": "6d1e67bf54b201fc07d0c83fb41f7c72cdb7fa84"
|
||||
},
|
||||
"dist": {
|
||||
"type": "tar",
|
||||
"url": "https://composer.fxft.online/dist/dipper/sms/dipper-sms-1.0.0-43d071.tar",
|
||||
"reference": "6d1e67bf54b201fc07d0c83fb41f7c72cdb7fa84",
|
||||
"shasum": "c3f7557716e9020c06b3ea6fcab4558330fd28c4"
|
||||
},
|
||||
"require": {
|
||||
"guzzlehttp/guzzle": "~6.0",
|
||||
"illuminate/support": "5.5.*",
|
||||
"psr/http-message": "~1.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Dipper\\Sms\\": "src/"
|
||||
}
|
||||
},
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "HollyTeng",
|
||||
"email": "n.haoyuan@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "短信发送",
|
||||
"time": "2018-09-05T05:58:47+00:00"
|
||||
},
|
||||
{
|
||||
"name": "dnoegel/php-xdg-base-dir",
|
||||
"version": "0.1",
|
||||
|
@ -36,7 +36,7 @@ return [
|
||||
|
||||
'guards' => [
|
||||
'admin' => ['driver' => 'jwt', 'provider' => 'admin'],
|
||||
'user' => ['driver' => 'jwt', 'provider' => 'user'],
|
||||
'company' => ['driver' => 'jwt', 'provider' => 'company'],
|
||||
// 'api' => ['driver' => 'jwt', 'provider' => 'user'],
|
||||
],
|
||||
|
||||
@ -58,8 +58,8 @@ return [
|
||||
*/
|
||||
|
||||
'providers' => [
|
||||
'user' => ['driver' => 'service', 'name' => App\Domains\User\Services\UserService::class],
|
||||
'admin' => ['driver' => 'service', 'name' => App\Domains\Account\Services\AccountService::class],
|
||||
'company' => ['driver' => 'service', 'name' => App\Domains\Virtual\Services\CompanyAccountService::class],
|
||||
],
|
||||
|
||||
/*
|
||||
|
45
config/captcha.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'characters' => '2346789abcdefghjmnpqrtuxyzABCDEFGHJMNPQRTUXYZ',
|
||||
|
||||
'default' => [
|
||||
'length' => 5,
|
||||
'width' => 120,
|
||||
'height' => 36,
|
||||
'quality' => 90,
|
||||
],
|
||||
|
||||
'flat' => [
|
||||
'length' => 6,
|
||||
'width' => 160,
|
||||
'height' => 46,
|
||||
'quality' => 90,
|
||||
'lines' => 6,
|
||||
'bgImage' => false,
|
||||
'bgColor' => '#ecf2f4',
|
||||
'fontColors'=> ['#2c3e50', '#c0392b', '#16a085', '#c0392b', '#8e44ad', '#303f9f', '#f57c00', '#795548'],
|
||||
'contrast' => -5,
|
||||
],
|
||||
|
||||
'mini' => [
|
||||
'length' => 3,
|
||||
'width' => 60,
|
||||
'height' => 32,
|
||||
],
|
||||
|
||||
'inverse' => [
|
||||
'length' => 5,
|
||||
'width' => 120,
|
||||
'height' => 36,
|
||||
'quality' => 90,
|
||||
'sensitive' => true,
|
||||
'angle' => 12,
|
||||
'sharpen' => 10,
|
||||
'blur' => 2,
|
||||
'invert' => true,
|
||||
'contrast' => -5,
|
||||
]
|
||||
|
||||
];
|
40
config/sms.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
// HTTP 请求的超时时间(秒)
|
||||
'timeout' => 5.0,
|
||||
|
||||
// 默认发送配置
|
||||
'default' => [
|
||||
// 网关调用策略,默认:顺序调用
|
||||
'strategy' => Dipper\Sms\Strategies\OrderStrategy::class,
|
||||
|
||||
// 默认可用的发送网关
|
||||
'gateways' => ['fxft', 'aliyun'],
|
||||
],
|
||||
|
||||
// 可用的网关配置
|
||||
'gateways' => [
|
||||
'aliyun' => [
|
||||
'access_key_id' => env('SMS_ALIYUN_ACCESS_KEY_ID'),
|
||||
'access_key_secret' => env('SMS_ALIYUN_ACCESS_KEY_SECRET'),
|
||||
'sign_name' => env('SMS_ALIYUN_SIGN_NAME'),
|
||||
'template' => [
|
||||
'vcode' => env('SMS_ALIYUN_TEMPLATE_VCODE'),
|
||||
'installed' => env('SMS_ALIYUN_TEMPLATE_INSTALLED'),
|
||||
'order' => env('SMS_ALIYUN_TEMPLATE_ORDER'),
|
||||
],
|
||||
],
|
||||
|
||||
'huyi' => [
|
||||
'api_id' => env('SMS_HUYI_API_ID'),
|
||||
'api_key' => env('SMS_HUYI_API_KEY'),
|
||||
],
|
||||
|
||||
'fxft' => [
|
||||
'username' => env('SMS_FXFT_USERNAME'),
|
||||
'password' => env('SMS_FXFT_PASSWORD'),
|
||||
'url' => env('SMS_FXFT_URL'),
|
||||
],
|
||||
],
|
||||
];
|
@ -20,7 +20,7 @@ class CreateBaseTables extends Migration
|
||||
$table->string('sn', 32)->comment('企业编号');
|
||||
$table->string('name', 32)->default('')->comment('企业名称');
|
||||
$table->string('contacts', 20)->default('')->comment('联系人');
|
||||
$table->string('phone', 20)->default('')->comment('手机号');
|
||||
$table->string('mobile', 20)->default('')->comment('手机号');
|
||||
$table->string('address')->default('')->comment('地址');
|
||||
$table->text('remark')->nullable()->comment('订单备注');
|
||||
$table->timestamps();
|
||||
@ -90,7 +90,7 @@ class CreateBaseTables extends Migration
|
||||
$table->timestamp('order_at')->nullable()->comment('下单时间');
|
||||
$table->string('address')->default('')->comment('收货地址');
|
||||
$table->string('contact')->default('')->comment('联系人');
|
||||
$table->string('phone')->default('')->comment('电话');
|
||||
$table->string('mobile')->default('')->comment('电话');
|
||||
$table->text('logistics_remark')->nullable()->comment('物流备注');
|
||||
$table->text('remark')->nullable()->comment('订单备注');
|
||||
$table->timestamps();
|
||||
@ -163,21 +163,23 @@ class CreateBaseTables extends Migration
|
||||
Schema::create("virtual_company_accounts", function (Blueprint $table) {
|
||||
$table->increments('id')->comment('自增ID');
|
||||
$table->string('company_id', 32)->comment('企业ID');
|
||||
$table->string('phone', 20)->default('')->comment('手机号');
|
||||
$table->string('nickname', 32)->default('')->comment('昵称');
|
||||
$table->string('mobile', 20)->default('')->comment('手机号');
|
||||
$table->string('username', 32)->default('')->comment('登录名');
|
||||
$table->string('password', 32)->default('')->comment('密码');
|
||||
$table->tinyInteger('status')->unsigned()->default(0)->comment('状态 0:正常 1:禁用');
|
||||
$table->string('salt', 6)->default('')->comment('盐');
|
||||
$table->tinyInteger('status')->unsigned()->default(0)->comment('状态 0未激活 1正常 2禁用');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->unique('phone');
|
||||
$table->unique('mobile');
|
||||
});
|
||||
|
||||
Schema::create("virtual_company_addresses", function (Blueprint $table) {
|
||||
$table->increments('id')->comment('自增ID');
|
||||
$table->string('company_id', 32)->comment('企业ID');
|
||||
$table->string('contacts', 20)->default('')->comment('联系人');
|
||||
$table->string('phone', 20)->default('')->comment('手机号');
|
||||
$table->string('mobile', 20)->default('')->comment('手机号');
|
||||
$table->string('area')->default('')->comment('区域');
|
||||
$table->string('address')->default('')->comment('地址');
|
||||
$table->tinyInteger('default')->unsigned()->default(0)->comment('是否默认 0:不是 1:是');
|
||||
|
23
database/seeds/CompanyAccountSeeder.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\Virtual\CompanyAccount;
|
||||
use App\Domains\Virtual\Services\CompanyAccountService;
|
||||
|
||||
class CompanyAccountSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
if (CompanyAccount::where('username', 'fxft')->count()) {
|
||||
return ;
|
||||
}
|
||||
|
||||
app(CompanyAccountService::class)->store(['company_id' => 1,'username' => 'fxft', 'password' => 'fxft2018']);
|
||||
}
|
||||
}
|
@ -15,5 +15,6 @@ class DatabaseSeeder extends Seeder
|
||||
Artisan::call('cache:clear');
|
||||
$this->call(AccountSeeder::class);
|
||||
$this->call(PermissionSeeder::class);
|
||||
$this->call(CompanyAccountSeeder::class);
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,7 @@
|
||||
<?php
|
||||
|
||||
require_once realpath(dirname(__FILE__) . '/TestCase.php');
|
||||
|
||||
$captchaService = app(\App\Domains\Captcha\Services\CaptchaService::class);
|
||||
|
||||
dd($captchaService->check('mbxgn', '$2y$10$.oCSEw.J9.QxAVRgmE8bv..D0vHHv3y6PNAa07y7Oh3358IWEv1au'));
|
||||
|
1
vendor/composer/autoload_classmap.php
vendored
@ -9,6 +9,7 @@ return array(
|
||||
'AccountSeeder' => $baseDir . '/database/seeds/AccountSeeder.php',
|
||||
'ArithmeticError' => $vendorDir . '/symfony/polyfill-php70/Resources/stubs/ArithmeticError.php',
|
||||
'AssertionError' => $vendorDir . '/symfony/polyfill-php70/Resources/stubs/AssertionError.php',
|
||||
'CompanyAccountSeeder' => $baseDir . '/database/seeds/CompanyAccountSeeder.php',
|
||||
'CreateBaseTables' => $baseDir . '/database/migrations/2018_11_27_175137_create_base_tables.php',
|
||||
'CreateFailedJobsTable' => $baseDir . '/database/migrations/2018_11_16_190020_create_failed_jobs_table.php',
|
||||
'CreateOrderTables' => $baseDir . '/database/migrations/2018_11_27_175146_create_order_tables.php',
|
||||
|
4
vendor/composer/autoload_files.php
vendored
@ -15,9 +15,10 @@ return array(
|
||||
'1d1b89d124cc9cb8219922c9d5569199' => $vendorDir . '/hamcrest/hamcrest-php/hamcrest/Hamcrest.php',
|
||||
'3a37ebac017bc098e9a86b35401e7a68' => $vendorDir . '/mongodb/mongodb/src/functions.php',
|
||||
'7b11c4dc42b3b3023073cb14e519683c' => $vendorDir . '/ralouphie/getallheaders/src/getallheaders.php',
|
||||
'bd9634f2d41831496de0d3dfe4c94881' => $vendorDir . '/symfony/polyfill-php56/bootstrap.php',
|
||||
'a0edc8309cc5e1d60e3047b5df6b7052' => $vendorDir . '/guzzlehttp/psr7/src/functions_include.php',
|
||||
'bd9634f2d41831496de0d3dfe4c94881' => $vendorDir . '/symfony/polyfill-php56/bootstrap.php',
|
||||
'c964ee0ededf28c96ebd9db5099ef910' => $vendorDir . '/guzzlehttp/promises/src/functions_include.php',
|
||||
'37a3dc5111fe8f707ab4c132ef1dbc62' => $vendorDir . '/guzzlehttp/guzzle/src/functions_include.php',
|
||||
'abede361264e2ae69ec1eee813a101af' => $vendorDir . '/markbaker/complex/classes/src/functions/abs.php',
|
||||
'21a5860fbef5be28db5ddfbc3cca67c4' => $vendorDir . '/markbaker/complex/classes/src/functions/acos.php',
|
||||
'1546e3f9d127f2a9bb2d1b6c31c26ef1' => $vendorDir . '/markbaker/complex/classes/src/functions/acosh.php',
|
||||
@ -62,7 +63,6 @@ return array(
|
||||
'ac9e33ce6841aa5bf5d16d465a2f03a7' => $vendorDir . '/markbaker/complex/classes/src/operations/divideinto.php',
|
||||
'801c31d8ed748cfa537fa45402288c95' => $vendorDir . '/psy/psysh/src/functions.php',
|
||||
'2cffec82183ee1cea088009cef9a6fc3' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier.composer.php',
|
||||
'37a3dc5111fe8f707ab4c132ef1dbc62' => $vendorDir . '/guzzlehttp/guzzle/src/functions_include.php',
|
||||
'6124b4c8570aa390c21fafd04a26c69f' => $vendorDir . '/myclabs/deep-copy/src/DeepCopy/deep_copy.php',
|
||||
'253c157292f75eb38082b5acb06f3f01' => $vendorDir . '/nikic/fast-route/src/functions.php',
|
||||
'7b310ffe822e5ee3a4f219c3bf86fd38' => $vendorDir . '/dipper/foundation/src/helpers.php',
|
||||
|
1
vendor/composer/autoload_psr4.php
vendored
@ -92,6 +92,7 @@ return array(
|
||||
'Doctrine\\Common\\Inflector\\' => array($vendorDir . '/doctrine/inflector/lib/Doctrine/Common/Inflector'),
|
||||
'Doctrine\\Common\\Cache\\' => array($vendorDir . '/doctrine/cache/lib/Doctrine/Common/Cache'),
|
||||
'Doctrine\\Common\\' => array($vendorDir . '/doctrine/event-manager/lib/Doctrine/Common'),
|
||||
'Dipper\\Sms\\' => array($vendorDir . '/dipper/sms/src'),
|
||||
'Dipper\\JWTAuth\\' => array($vendorDir . '/dipper/jwt-auth'),
|
||||
'Dipper\\Foundation\\' => array($vendorDir . '/dipper/foundation/src'),
|
||||
'Dipper\\FlashMessage\\' => array($vendorDir . '/dipper/flashmessage/src'),
|
||||
|
10
vendor/composer/autoload_static.php
vendored
@ -16,9 +16,10 @@ class ComposerStaticInite79258a3e34ad3e251999111d9f334d9
|
||||
'1d1b89d124cc9cb8219922c9d5569199' => __DIR__ . '/..' . '/hamcrest/hamcrest-php/hamcrest/Hamcrest.php',
|
||||
'3a37ebac017bc098e9a86b35401e7a68' => __DIR__ . '/..' . '/mongodb/mongodb/src/functions.php',
|
||||
'7b11c4dc42b3b3023073cb14e519683c' => __DIR__ . '/..' . '/ralouphie/getallheaders/src/getallheaders.php',
|
||||
'bd9634f2d41831496de0d3dfe4c94881' => __DIR__ . '/..' . '/symfony/polyfill-php56/bootstrap.php',
|
||||
'a0edc8309cc5e1d60e3047b5df6b7052' => __DIR__ . '/..' . '/guzzlehttp/psr7/src/functions_include.php',
|
||||
'bd9634f2d41831496de0d3dfe4c94881' => __DIR__ . '/..' . '/symfony/polyfill-php56/bootstrap.php',
|
||||
'c964ee0ededf28c96ebd9db5099ef910' => __DIR__ . '/..' . '/guzzlehttp/promises/src/functions_include.php',
|
||||
'37a3dc5111fe8f707ab4c132ef1dbc62' => __DIR__ . '/..' . '/guzzlehttp/guzzle/src/functions_include.php',
|
||||
'abede361264e2ae69ec1eee813a101af' => __DIR__ . '/..' . '/markbaker/complex/classes/src/functions/abs.php',
|
||||
'21a5860fbef5be28db5ddfbc3cca67c4' => __DIR__ . '/..' . '/markbaker/complex/classes/src/functions/acos.php',
|
||||
'1546e3f9d127f2a9bb2d1b6c31c26ef1' => __DIR__ . '/..' . '/markbaker/complex/classes/src/functions/acosh.php',
|
||||
@ -63,7 +64,6 @@ class ComposerStaticInite79258a3e34ad3e251999111d9f334d9
|
||||
'ac9e33ce6841aa5bf5d16d465a2f03a7' => __DIR__ . '/..' . '/markbaker/complex/classes/src/operations/divideinto.php',
|
||||
'801c31d8ed748cfa537fa45402288c95' => __DIR__ . '/..' . '/psy/psysh/src/functions.php',
|
||||
'2cffec82183ee1cea088009cef9a6fc3' => __DIR__ . '/..' . '/ezyang/htmlpurifier/library/HTMLPurifier.composer.php',
|
||||
'37a3dc5111fe8f707ab4c132ef1dbc62' => __DIR__ . '/..' . '/guzzlehttp/guzzle/src/functions_include.php',
|
||||
'6124b4c8570aa390c21fafd04a26c69f' => __DIR__ . '/..' . '/myclabs/deep-copy/src/DeepCopy/deep_copy.php',
|
||||
'253c157292f75eb38082b5acb06f3f01' => __DIR__ . '/..' . '/nikic/fast-route/src/functions.php',
|
||||
'7b310ffe822e5ee3a4f219c3bf86fd38' => __DIR__ . '/..' . '/dipper/foundation/src/helpers.php',
|
||||
@ -199,6 +199,7 @@ class ComposerStaticInite79258a3e34ad3e251999111d9f334d9
|
||||
'Doctrine\\Common\\Inflector\\' => 26,
|
||||
'Doctrine\\Common\\Cache\\' => 22,
|
||||
'Doctrine\\Common\\' => 16,
|
||||
'Dipper\\Sms\\' => 11,
|
||||
'Dipper\\JWTAuth\\' => 15,
|
||||
'Dipper\\Foundation\\' => 18,
|
||||
'Dipper\\FlashMessage\\' => 20,
|
||||
@ -574,6 +575,10 @@ class ComposerStaticInite79258a3e34ad3e251999111d9f334d9
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/doctrine/event-manager/lib/Doctrine/Common',
|
||||
),
|
||||
'Dipper\\Sms\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/dipper/sms/src',
|
||||
),
|
||||
'Dipper\\JWTAuth\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/dipper/jwt-auth',
|
||||
@ -693,6 +698,7 @@ class ComposerStaticInite79258a3e34ad3e251999111d9f334d9
|
||||
'AccountSeeder' => __DIR__ . '/../..' . '/database/seeds/AccountSeeder.php',
|
||||
'ArithmeticError' => __DIR__ . '/..' . '/symfony/polyfill-php70/Resources/stubs/ArithmeticError.php',
|
||||
'AssertionError' => __DIR__ . '/..' . '/symfony/polyfill-php70/Resources/stubs/AssertionError.php',
|
||||
'CompanyAccountSeeder' => __DIR__ . '/../..' . '/database/seeds/CompanyAccountSeeder.php',
|
||||
'CreateBaseTables' => __DIR__ . '/../..' . '/database/migrations/2018_11_27_175137_create_base_tables.php',
|
||||
'CreateFailedJobsTable' => __DIR__ . '/../..' . '/database/migrations/2018_11_16_190020_create_failed_jobs_table.php',
|
||||
'CreateOrderTables' => __DIR__ . '/../..' . '/database/migrations/2018_11_27_175146_create_order_tables.php',
|
||||
|
39
vendor/composer/installed.json
vendored
@ -728,6 +728,45 @@
|
||||
],
|
||||
"description": "jwt-auth"
|
||||
},
|
||||
{
|
||||
"name": "dipper/sms",
|
||||
"version": "1.0.0",
|
||||
"version_normalized": "1.0.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "ssh://gogs@git.fxft.net:2222/composer/sms.git",
|
||||
"reference": "6d1e67bf54b201fc07d0c83fb41f7c72cdb7fa84"
|
||||
},
|
||||
"dist": {
|
||||
"type": "tar",
|
||||
"url": "https://composer.fxft.online/dist/dipper/sms/dipper-sms-1.0.0-43d071.tar",
|
||||
"reference": "6d1e67bf54b201fc07d0c83fb41f7c72cdb7fa84",
|
||||
"shasum": "c3f7557716e9020c06b3ea6fcab4558330fd28c4"
|
||||
},
|
||||
"require": {
|
||||
"guzzlehttp/guzzle": "~6.0",
|
||||
"illuminate/support": "5.5.*",
|
||||
"psr/http-message": "~1.0"
|
||||
},
|
||||
"time": "2018-09-05T05:58:47+00:00",
|
||||
"type": "library",
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Dipper\\Sms\\": "src/"
|
||||
}
|
||||
},
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "HollyTeng",
|
||||
"email": "n.haoyuan@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "短信发送"
|
||||
},
|
||||
{
|
||||
"name": "dnoegel/php-xdg-base-dir",
|
||||
"version": "0.1",
|
||||
|
3
vendor/dipper/sms/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
.DS_Store
|
||||
/.vscode
|
||||
/.idea
|
23
vendor/dipper/sms/composer.json
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "dipper/sms",
|
||||
"description": "短信发送",
|
||||
"type": "library",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "HollyTeng",
|
||||
"email": "n.haoyuan@gmail.com"
|
||||
}
|
||||
],
|
||||
"minimum-stability": "dev",
|
||||
"require": {
|
||||
"guzzlehttp/guzzle": "~6.0",
|
||||
"illuminate/support": "5.5.*",
|
||||
"psr/http-message": "~1.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Dipper\\Sms\\": "src/"
|
||||
}
|
||||
}
|
||||
}
|
40
vendor/dipper/sms/config/sms.php
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
// HTTP 请求的超时时间(秒)
|
||||
'timeout' => 5.0,
|
||||
|
||||
// 默认发送配置
|
||||
'default' => [
|
||||
// 网关调用策略,默认:顺序调用
|
||||
'strategy' => Dipper\Sms\Strategies\OrderStrategy::class,
|
||||
|
||||
// 默认可用的发送网关
|
||||
'gateways' => ['aliyun'],
|
||||
],
|
||||
|
||||
// 可用的网关配置
|
||||
'gateways' => [
|
||||
'aliyun' => [
|
||||
'access_key_id' => env('SMS_ALIYUN_ACCESS_KEY_ID'),
|
||||
'access_key_secret' => env('SMS_ALIYUN_ACCESS_KEY_SECRET'),
|
||||
'sign_name' => env('SMS_ALIYUN_SIGN_NAME'),
|
||||
'template' => [
|
||||
'vcode' => env('SMS_ALIYUN_TEMPLATE_VCODE'),
|
||||
'installed' => env('SMS_ALIYUN_TEMPLATE_INSTALLED'),
|
||||
'order' => env('SMS_ALIYUN_TEMPLATE_ORDER'),
|
||||
],
|
||||
],
|
||||
|
||||
'huyi' => [
|
||||
'api_id' => env('SMS_HUYI_API_ID'),
|
||||
'api_key' => env('SMS_HUYI_API_KEY'),
|
||||
],
|
||||
|
||||
'fxft' => [
|
||||
'username' => env('SMS_FXFT_USERNAME'),
|
||||
'password' => env('SMS_FXFT_PASSWORD'),
|
||||
'url' => env('SMS_FXFT_URL'),
|
||||
],
|
||||
],
|
||||
];
|
28
vendor/dipper/sms/src/Contracts/GatewayInterface.php
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Dipper\Sms\Contracts;
|
||||
|
||||
use Dipper\Sms\Support\Config;
|
||||
|
||||
interface GatewayInterface
|
||||
{
|
||||
/**
|
||||
* Get gateway name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* Send a short message.
|
||||
*
|
||||
* @param int|string|array $to
|
||||
* @param \Dipper\Sms\Contracts\MessageInterface $message
|
||||
* @param \Dipper\Sms\Support\Config $config
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \Dipper\Sms\Exceptions\GatewayErrorException
|
||||
*/
|
||||
public function send($to, MessageInterface $message, Config $config);
|
||||
}
|
54
vendor/dipper/sms/src/Contracts/MessageInterface.php
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Dipper\Sms\Contracts;
|
||||
|
||||
/**
|
||||
* Interface MessageInterface.
|
||||
*/
|
||||
interface MessageInterface
|
||||
{
|
||||
const TEXT_MESSAGE = 'text';
|
||||
|
||||
const VOICE_MESSAGE = 'voice';
|
||||
|
||||
/**
|
||||
* Return the message type.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMessageType();
|
||||
|
||||
/**
|
||||
* Return message content.
|
||||
*
|
||||
* @param \Dipper\Sms\Contracts\GatewayInterface|null $gateway
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContent(GatewayInterface $gateway = null);
|
||||
|
||||
/**
|
||||
* Return the template id of message.
|
||||
*
|
||||
* @param \Dipper\Sms\Contracts\GatewayInterface|null $gateway
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTemplate(GatewayInterface $gateway = null);
|
||||
|
||||
/**
|
||||
* Return the template data of message.
|
||||
*
|
||||
* @param \Dipper\Sms\Contracts\GatewayInterface|null $gateway
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getData(GatewayInterface $gateway = null);
|
||||
|
||||
/**
|
||||
* Return message supported gateways.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getGateways();
|
||||
}
|
18
vendor/dipper/sms/src/Contracts/StrategyInterface.php
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Dipper\Sms\Contracts;
|
||||
|
||||
/**
|
||||
* Interface StrategyInterface.
|
||||
*/
|
||||
interface StrategyInterface
|
||||
{
|
||||
/**
|
||||
* Apply the strategy and return result.
|
||||
*
|
||||
* @param array $gateways
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function apply(array $gateways);
|
||||
}
|
7
vendor/dipper/sms/src/Exceptions/Exception.php
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Dipper\Sms\Exceptions;
|
||||
|
||||
class Exception extends \Exception
|
||||
{
|
||||
}
|
23
vendor/dipper/sms/src/Exceptions/GatewayErrorException.php
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Dipper\Sms\Exceptions;
|
||||
|
||||
class GatewayErrorException extends Exception
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $raw = [];
|
||||
|
||||
/**
|
||||
* GatewayErrorException constructor.
|
||||
*
|
||||
* @param array $raw
|
||||
*/
|
||||
public function __construct($message, $code, array $raw = [])
|
||||
{
|
||||
parent::__construct($message, intval($code));
|
||||
|
||||
$this->raw = $raw;
|
||||
}
|
||||
}
|
7
vendor/dipper/sms/src/Exceptions/InvalidArgumentException.php
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Dipper\Sms\Exceptions;
|
||||
|
||||
class InvalidArgumentException extends Exception
|
||||
{
|
||||
}
|
26
vendor/dipper/sms/src/Exceptions/NoGatewayAvailableException.php
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Dipper\Sms\Exceptions;
|
||||
|
||||
use Throwable;
|
||||
|
||||
class NoGatewayAvailableException extends Exception
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $results = [];
|
||||
|
||||
/**
|
||||
* NoGatewayAvailableException constructor.
|
||||
*
|
||||
* @param array $results
|
||||
* @param int $code
|
||||
* @param \Throwable|null $previous
|
||||
*/
|
||||
public function __construct(array $results = [], $code = 0, Throwable $previous = null)
|
||||
{
|
||||
$this->results = $results;
|
||||
parent::__construct('All the gateways have failed.', $code, $previous);
|
||||
}
|
||||
}
|
106
vendor/dipper/sms/src/Gateways/AliyunGateway.php
vendored
Normal file
@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace Dipper\Sms\Gateways;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Dipper\Sms\Support\Config;
|
||||
use Dipper\Sms\Traits\HasHttpRequest;
|
||||
use Dipper\Sms\Contracts\MessageInterface;
|
||||
use Dipper\Sms\Exceptions\GatewayErrorException;
|
||||
|
||||
class AliyunGateway extends Gateway
|
||||
{
|
||||
use HasHttpRequest;
|
||||
|
||||
const ENDPOINT_URL = 'http://dysmsapi.aliyuncs.com';
|
||||
|
||||
const ENDPOINT_METHOD = 'SendSms';
|
||||
|
||||
const ENDPOINT_VERSION = '2017-05-25';
|
||||
|
||||
const ENDPOINT_FORMAT = 'JSON';
|
||||
|
||||
const ENDPOINT_REGION_ID = 'cn-hangzhou';
|
||||
|
||||
const ENDPOINT_SIGNATURE_METHOD = 'HMAC-SHA1';
|
||||
|
||||
const ENDPOINT_SIGNATURE_VERSION = '1.0';
|
||||
|
||||
/**
|
||||
* Get gateway name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'aliyun';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|int|string $to
|
||||
* @param \Dipper\Sms\Contracts\MessageInterface $message
|
||||
* @param \Dipper\Sms\Support\Config $config
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \Dipper\Sms\Exceptions\GatewayErrorException;
|
||||
*/
|
||||
public function send($to, MessageInterface $message, Config $config)
|
||||
{
|
||||
$params = [
|
||||
'RegionId' => self::ENDPOINT_REGION_ID,
|
||||
'AccessKeyId' => $config->get('access_key_id'),
|
||||
'Format' => self::ENDPOINT_FORMAT,
|
||||
'SignatureMethod' => self::ENDPOINT_SIGNATURE_METHOD,
|
||||
'SignatureVersion' => self::ENDPOINT_SIGNATURE_VERSION,
|
||||
'SignatureNonce' => uniqid(),
|
||||
'Timestamp' => $this->getTimestamp(),
|
||||
'Action' => self::ENDPOINT_METHOD,
|
||||
'Version' => self::ENDPOINT_VERSION,
|
||||
'PhoneNumbers' => strval($to),
|
||||
'SignName' => $config->get('sign_name'),
|
||||
'TemplateCode' => $message->getTemplate($this),
|
||||
'TemplateParam' => json_encode($message->getData($this), JSON_FORCE_OBJECT),
|
||||
];
|
||||
|
||||
$params['Signature'] = $this->generateSign($params);
|
||||
|
||||
$result = $this->get(self::ENDPOINT_URL, $params);
|
||||
|
||||
if ('OK' != $result['Code']) {
|
||||
Log::error('短信发送失败', $result);
|
||||
throw new GatewayErrorException($result['Message'], $result['Code'], $result);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Sign.
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function generateSign($params)
|
||||
{
|
||||
ksort($params);
|
||||
$accessKeySecret = $this->config->get('access_key_secret');
|
||||
$stringToSign = 'GET&%2F&'.urlencode(http_build_query($params, null, '&', PHP_QUERY_RFC3986));
|
||||
|
||||
return base64_encode(hash_hmac('sha1', $stringToSign, $accessKeySecret.'&', true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return false|string
|
||||
*/
|
||||
protected function getTimestamp()
|
||||
{
|
||||
$timezone = date_default_timezone_get();
|
||||
date_default_timezone_set('GMT');
|
||||
$timestamp = date('Y-m-d\TH:i:s\Z');
|
||||
date_default_timezone_set($timezone);
|
||||
|
||||
return $timestamp;
|
||||
}
|
||||
}
|
47
vendor/dipper/sms/src/Gateways/ErrorlogGateway.php
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Dipper\Sms\Gateways;
|
||||
|
||||
use Dipper\Sms\Contracts\MessageInterface;
|
||||
use Dipper\Sms\Support\Config;
|
||||
|
||||
class ErrorlogGateway extends Gateway
|
||||
{
|
||||
/**
|
||||
* Get gateway name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'errorlog';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|int|string $to
|
||||
* @param \Dipper\Sms\Contracts\MessageInterface $message
|
||||
* @param \Dipper\Sms\Support\Config $config
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function send($to, MessageInterface $message, Config $config)
|
||||
{
|
||||
if (is_array($to)) {
|
||||
$to = implode(',', $to);
|
||||
}
|
||||
|
||||
$message = sprintf(
|
||||
"[%s] to: %s | message: \"%s\" | template: \"%s\" | data: %s\n",
|
||||
date('Y-m-d H:i:s'),
|
||||
$to,
|
||||
$message->getContent(),
|
||||
$message->getTemplate($this),
|
||||
json_encode($message->getData($this))
|
||||
);
|
||||
|
||||
$file = $this->config->get('file', ini_get('error_log'));
|
||||
$status = error_log($message, 3, $file);
|
||||
|
||||
return compact('status', 'file');
|
||||
}
|
||||
}
|
82
vendor/dipper/sms/src/Gateways/FxftGateway.php
vendored
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace Dipper\Sms\Gateways;
|
||||
|
||||
use Dipper\Sms\Contracts\MessageInterface;
|
||||
use Dipper\Sms\Exceptions\GatewayErrorException;
|
||||
use Dipper\Sms\Support\Config;
|
||||
use Dipper\Sms\Traits\HasHttpRequest;
|
||||
|
||||
class FxftGateway extends Gateway
|
||||
{
|
||||
use HasHttpRequest;
|
||||
|
||||
|
||||
/**
|
||||
* Get gateway name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'fxft';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|int|string $to
|
||||
* @param \Dipper\Sms\Contracts\MessageInterface $message
|
||||
* @param \Dipper\Sms\Support\Config $config
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \Dipper\Sms\Exceptions\GatewayErrorException;
|
||||
*/
|
||||
public function send($to, MessageInterface $message, Config $config)
|
||||
{
|
||||
$params = [
|
||||
'username' => $config->get('username'),
|
||||
'password' => $config->get('password'),
|
||||
'mobile' => strval($to),
|
||||
'content' => $message->getContent(),
|
||||
];
|
||||
|
||||
$params['password'] = $this->generateSign($params);
|
||||
|
||||
$result = $this->post($config->get('url'), $params);
|
||||
|
||||
if ($result < 0) {
|
||||
$res = [
|
||||
'0' => "失败",
|
||||
'-1' => "用户名或者密码不正确",
|
||||
'-2' => "必填选项为空",
|
||||
'-3' => "短信内容0个字节",
|
||||
'-4' => "0个有效号码",
|
||||
'-5' => "余额不够",
|
||||
'-10' => "用户被禁用",
|
||||
'-11' => "短信内容超过500字",
|
||||
'-12' => "无扩展权限(ext字段需填空)",
|
||||
'-13' => "IP校验错误",
|
||||
'-14' => "内容解析异常",
|
||||
'-990' => "未知错误",
|
||||
'-25' => "没有权限(只支持web和http用户)"
|
||||
|
||||
];
|
||||
Log::error('短信发送失败', $res[$result]);
|
||||
throw new GatewayErrorException($res[$result], $result, $res[$result]);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Sign.
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function generateSign($params)
|
||||
{
|
||||
return md5($params['username'] . md5($params['password']));
|
||||
}
|
||||
}
|
83
vendor/dipper/sms/src/Gateways/Gateway.php
vendored
Normal file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace Dipper\Sms\Gateways;
|
||||
|
||||
use Dipper\Sms\Contracts\GatewayInterface;
|
||||
use Dipper\Sms\Support\Config;
|
||||
|
||||
abstract class Gateway implements GatewayInterface
|
||||
{
|
||||
const DEFAULT_TIMEOUT = 5.0;
|
||||
|
||||
/**
|
||||
* @var \Dipper\Sms\Support\Config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
protected $timeout;
|
||||
|
||||
/**
|
||||
* Gateway constructor.
|
||||
*
|
||||
* @param array $config
|
||||
*/
|
||||
public function __construct(array $config)
|
||||
{
|
||||
$this->config = new Config($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return timeout.
|
||||
*
|
||||
* @return int|mixed
|
||||
*/
|
||||
public function getTimeout()
|
||||
{
|
||||
return $this->timeout ?: $this->config->get('timeout', self::DEFAULT_TIMEOUT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set timeout.
|
||||
*
|
||||
* @param int $timeout
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTimeout($timeout)
|
||||
{
|
||||
$this->timeout = floatval($timeout);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Dipper\Sms\Support\Config
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Dipper\Sms\Support\Config $config
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setConfig(Config $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
72
vendor/dipper/sms/src/Gateways/HuyiGateway.php
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Dipper\Sms\Gateways;
|
||||
|
||||
use Dipper\Sms\Contracts\MessageInterface;
|
||||
use Dipper\Sms\Exceptions\GatewayErrorException;
|
||||
use Dipper\Sms\Support\Config;
|
||||
use Dipper\Sms\Traits\HasHttpRequest;
|
||||
|
||||
class HuyiGateway extends Gateway
|
||||
{
|
||||
use HasHttpRequest;
|
||||
|
||||
const ENDPOINT_URL = 'http://106.ihuyi.com/webservice/sms.php?method=Submit';
|
||||
|
||||
const ENDPOINT_FORMAT = 'json';
|
||||
|
||||
const SUCCESS_CODE = 2;
|
||||
|
||||
/**
|
||||
* Get gateway name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'huyi';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|int|string $to
|
||||
* @param \Dipper\Sms\Contracts\MessageInterface $message
|
||||
* @param \Dipper\Sms\Support\Config $config
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \Dipper\Sms\Exceptions\GatewayErrorException;
|
||||
*/
|
||||
public function send($to, MessageInterface $message, Config $config)
|
||||
{
|
||||
$params = [
|
||||
'account' => $config->get('api_id'),
|
||||
'mobile' => strval($to),
|
||||
'content' => $message->getContent(),
|
||||
'time' => time(),
|
||||
'format' => self::ENDPOINT_FORMAT,
|
||||
];
|
||||
|
||||
$params['password'] = $this->generateSign($params);
|
||||
|
||||
$result = $this->post(self::ENDPOINT_URL, $params);
|
||||
|
||||
if (self::SUCCESS_CODE != $result['code']) {
|
||||
Log::error('短信发送失败', $result);
|
||||
throw new GatewayErrorException($result['msg'], $result['code'], $result);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Sign.
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function generateSign($params)
|
||||
{
|
||||
return md5($params['account'].$this->config->get('api_key').$params['mobile'].$params['content'].$params['time']);
|
||||
}
|
||||
}
|
44
vendor/dipper/sms/src/Messages/InstalledMessage.php
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Dipper\Sms\Messages;
|
||||
|
||||
use Dipper\Sms\Contracts\GatewayInterface;
|
||||
|
||||
class InstalledMessage extends Message
|
||||
{
|
||||
protected $attributes;
|
||||
protected $gateways = ['aliyun'];
|
||||
|
||||
public function __construct(array $attributes)
|
||||
{
|
||||
$this->attributes = $attributes;
|
||||
}
|
||||
|
||||
// 定义直接使用内容发送平台的内容
|
||||
public function getContent(GatewayInterface $gateway = null)
|
||||
{
|
||||
return sprintf(
|
||||
'【车友服务】尊敬的客户,您的设备(%s)安装订单于%s完成。详细信息:%s ,感谢您的使用。',
|
||||
$this->attributes['imei'],
|
||||
$this->attributes['created_at'],
|
||||
$this->attributes['detail']
|
||||
);
|
||||
}
|
||||
|
||||
// 定义使用模板发送方式平台所需要的模板 ID
|
||||
public function getTemplate(GatewayInterface $gateway = null)
|
||||
{
|
||||
$config = $gateway->getConfig();
|
||||
return $config['template']['installed'];
|
||||
}
|
||||
|
||||
// 模板参数
|
||||
public function getData(GatewayInterface $gateway = null)
|
||||
{
|
||||
return [
|
||||
'Device' => $this->attributes['imei'],
|
||||
'Order' => $this->attributes['created_at'],
|
||||
'DeviceInfo' => $this->attributes['detail'],
|
||||
];
|
||||
}
|
||||
}
|
175
vendor/dipper/sms/src/Messages/Message.php
vendored
Normal file
@ -0,0 +1,175 @@
|
||||
<?php
|
||||
|
||||
namespace Dipper\Sms\Messages;
|
||||
|
||||
use Dipper\Sms\Contracts\GatewayInterface;
|
||||
use Dipper\Sms\Contracts\MessageInterface;
|
||||
|
||||
class Message implements MessageInterface
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $gateways = [];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $content;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $template;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $data = [];
|
||||
|
||||
/**
|
||||
* Message constructor.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param string $type
|
||||
*/
|
||||
public function __construct(array $attributes = [], $type = MessageInterface::TEXT_MESSAGE)
|
||||
{
|
||||
$this->type = $type;
|
||||
|
||||
foreach ($attributes as $property => $value) {
|
||||
if (property_exists($this, $property)) {
|
||||
$this->$property = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the message type.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMessageType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return message content.
|
||||
*
|
||||
* @param \Dipper\Sms\Contracts\GatewayInterface|null $gateway
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContent(GatewayInterface $gateway = null)
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the template id of message.
|
||||
*
|
||||
* @param \Dipper\Sms\Contracts\GatewayInterface|null $gateway
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTemplate(GatewayInterface $gateway = null)
|
||||
{
|
||||
return $this->template;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setType(string $type)
|
||||
{
|
||||
$this->type = $type;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $content
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setContent($content)
|
||||
{
|
||||
$this->content = $content;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $template
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTemplate($template)
|
||||
{
|
||||
$this->template = $template;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Dipper\Sms\Contracts\GatewayInterface|null $gateway
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getData(GatewayInterface $gateway = null)
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setData(array $data)
|
||||
{
|
||||
$this->data = $data;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getGateways()
|
||||
{
|
||||
return $this->gateways;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $gateways
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setGateways(array $gateways)
|
||||
{
|
||||
$this->gateways = $gateways;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $property
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __get($property)
|
||||
{
|
||||
if (property_exists($this, $property)) {
|
||||
return $this->$property;
|
||||
}
|
||||
}
|
||||
}
|
37
vendor/dipper/sms/src/Messages/OrderMessage.php
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Dipper\Sms\Messages;
|
||||
|
||||
use Dipper\Sms\Contracts\GatewayInterface;
|
||||
|
||||
class OrderMessage extends Message
|
||||
{
|
||||
protected $attributes;
|
||||
protected $gateways = ['aliyun'];
|
||||
|
||||
public function __construct(array $attributes)
|
||||
{
|
||||
$this->attributes = $attributes;
|
||||
}
|
||||
|
||||
// 定义直接使用内容发送平台的内容
|
||||
public function getContent(GatewayInterface $gateway = null)
|
||||
{
|
||||
return sprintf('【车友服务】尊敬的顾客,您的订单%s提交成功,感谢您的使用!若有疑问,请致电客服热线400-999-8900', $this->attributes['order']);
|
||||
}
|
||||
|
||||
// 定义使用模板发送方式平台所需要的模板 ID
|
||||
public function getTemplate(GatewayInterface $gateway = null)
|
||||
{
|
||||
$config = $gateway->getConfig();
|
||||
return $config['template']['order'];
|
||||
}
|
||||
|
||||
// 模板参数
|
||||
public function getData(GatewayInterface $gateway = null)
|
||||
{
|
||||
return [
|
||||
'order' => $this->attributes['order'],
|
||||
];
|
||||
}
|
||||
}
|
38
vendor/dipper/sms/src/Messages/VcodeMessage.php
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Dipper\Sms\Messages;
|
||||
|
||||
use Dipper\Sms\Contracts\GatewayInterface;
|
||||
|
||||
class VcodeMessage extends Message
|
||||
{
|
||||
protected $attributes;
|
||||
protected $gateways = ['aliyun'];
|
||||
|
||||
public function __construct(array $attributes)
|
||||
{
|
||||
$this->attributes = $attributes;
|
||||
}
|
||||
|
||||
// 定义直接使用内容发送平台的内容
|
||||
public function getContent(GatewayInterface $gateway = null)
|
||||
{
|
||||
return sprintf('【车友服务】短信内容验证码%s,您正在进行%s身份验证,打死不要告诉别人哦!', $this->attributes['code'], $this->attributes['product']);
|
||||
}
|
||||
|
||||
// 定义使用模板发送方式平台所需要的模板 ID
|
||||
public function getTemplate(GatewayInterface $gateway = null)
|
||||
{
|
||||
$config = $gateway->getConfig();
|
||||
return $config['template']['vcode'];
|
||||
}
|
||||
|
||||
// 模板参数
|
||||
public function getData(GatewayInterface $gateway = null)
|
||||
{
|
||||
return [
|
||||
'code' => $this->attributes['code'],
|
||||
'product' => $this->attributes['product'],
|
||||
];
|
||||
}
|
||||
}
|