Commit b51aad00 by lujunyi

短信

parent 98bfbd85
...@@ -51,9 +51,19 @@ WECHAT_MINI_PROGRAM_APPID=wx848e75ebc215b462 ...@@ -51,9 +51,19 @@ WECHAT_MINI_PROGRAM_APPID=wx848e75ebc215b462
WECHAT_MINI_PROGRAM_SECRET= WECHAT_MINI_PROGRAM_SECRET=
# 短信 # 短信
SMS_CHANNEL=chengliye
#SMS_CHANNEL=qcloud
# 诚立业
SMS_USERNAME=tzthy SMS_USERNAME=tzthy
SMS_PASSWORD= SMS_PASSWORD=
# 腾讯短信
QCLOUD_SDK_APP_ID=1400949784
QCLOUD_SECRET_ID=AKIDGQRIxW3bJxVyHOZgfeYK9qKguvjPsAFC
QCLOUD_SECRET_KEY=
QCLOUD_SIGN_NAME=苗侗同知堂医院
# docker-compose 的相关环境变量 # docker-compose 的相关环境变量
COMPOSE_PROJECT_NAME=tzt-admin COMPOSE_PROJECT_NAME=tzt-admin
TZ=Asia/Shanghai TZ=Asia/Shanghai
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
use Dcat\Admin\Layout\Content; use Dcat\Admin\Layout\Content;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\Validator;
use Overtrue\EasySms\EasySms;
class AuthController extends BaseAuthController class AuthController extends BaseAuthController
{ {
...@@ -157,7 +158,7 @@ public function getLoginSmsCode(Request $request) ...@@ -157,7 +158,7 @@ public function getLoginSmsCode(Request $request)
$lastSendTimeKey = "last_sms_time_{$phone}"; $lastSendTimeKey = "last_sms_time_{$phone}";
$lastSendTime = cache()->get($lastSendTimeKey, 0); $lastSendTime = cache()->get($lastSendTimeKey, 0);
if ($currentTime - $lastSendTime < 60) { if ($currentTime - $lastSendTime < 60) {
return response()->json(['error' => '请等待60秒后再试']); // return response()->json(['error' => '请等待60秒后再试']);
} }
// 生成短信验证码 // 生成短信验证码
...@@ -169,10 +170,22 @@ public function getLoginSmsCode(Request $request) ...@@ -169,10 +170,22 @@ public function getLoginSmsCode(Request $request)
// cache()->put($smsCountKey, $smsCount + 1, strtotime('tomorrow') - time()); // 设置为明天0点过期 // cache()->put($smsCountKey, $smsCount + 1, strtotime('tomorrow') - time()); // 设置为明天0点过期
cache()->put($lastSendTimeKey, $currentTime, 60); cache()->put($lastSendTimeKey, $currentTime, 60);
$templateName = 'verification_code'; // 诚立业
$templateData = ['code' => $verificationCode]; if (env('SMS_CHANNEL') == 'chengliye') {
$smsService = new SmsService(); $templateName = 'verification_code';
$response = $smsService->sendSms($phone, $templateName, $templateData); $templateData = ['code' => $verificationCode];
$smsService = new SmsService();
$response = $smsService->sendSms($phone, $templateName, $templateData);
} elseif (env('SMS_CHANNEL') == 'qcloud') { // 腾讯短信
$easySms = new EasySms(config('easysms'));
$easySms->send($phone, [
'content' => "您的验证码为:{$verificationCode},请勿泄露于他人!",
'template' => '2311645',
'data' => [
'code' => $verificationCode,
],
]);
}
return response()->json(['success' => true, 'message' => '验证码已发送']); return response()->json(['success' => true, 'message' => '验证码已发送']);
} }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
"laravel/helpers": "^1.6", "laravel/helpers": "^1.6",
"laravel/sanctum": "^3.3", "laravel/sanctum": "^3.3",
"laravel/tinker": "^2.8", "laravel/tinker": "^2.8",
"overtrue/easy-sms": "^3.0",
"overtrue/laravel-filesystem-cos": "^3.5", "overtrue/laravel-filesystem-cos": "^3.5",
"overtrue/laravel-query-logger": "^3.1", "overtrue/laravel-query-logger": "^3.1",
"overtrue/laravel-wechat": "^6.0", "overtrue/laravel-wechat": "^6.0",
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "dc518d1fd55a42b2a5b3d748a4dc1d94", "content-hash": "07135fceb49742bf4ca446a83fb77bc0",
"packages": [ "packages": [
{ {
"name": "box/spout", "name": "box/spout",
...@@ -3511,6 +3511,60 @@ ...@@ -3511,6 +3511,60 @@
"time": "2024-11-21T10:36:35+00:00" "time": "2024-11-21T10:36:35+00:00"
}, },
{ {
"name": "overtrue/easy-sms",
"version": "3.0.1",
"source": {
"type": "git",
"url": "https://github.com/overtrue/easy-sms.git",
"reference": "b97d8b785ae07fe8c181de8d9d1f7f146a5977f7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/overtrue/easy-sms/zipball/b97d8b785ae07fe8c181de8d9d1f7f146a5977f7",
"reference": "b97d8b785ae07fe8c181de8d9d1f7f146a5977f7",
"shasum": ""
},
"require": {
"ext-json": "*",
"guzzlehttp/guzzle": "^6.2 || ^7.0",
"php": ">=8.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.54",
"jetbrains/phpstorm-attributes": "^1.0",
"mockery/mockery": "^1.4.2",
"phpunit/phpunit": "^9.5.8"
},
"type": "library",
"autoload": {
"psr-4": {
"Overtrue\\EasySms\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "overtrue",
"email": "i@overtrue.me"
}
],
"description": "The easiest way to send short message.",
"support": {
"issues": "https://github.com/overtrue/easy-sms/issues",
"source": "https://github.com/overtrue/easy-sms/tree/3.0.1"
},
"funding": [
{
"url": "https://github.com/overtrue",
"type": "github"
}
],
"time": "2024-07-16T06:07:02+00:00"
},
{
"name": "overtrue/flysystem-cos", "name": "overtrue/flysystem-cos",
"version": "5.1.12", "version": "5.1.12",
"source": { "source": {
......
<?php
/*
* This file is part of the overtrue/laravel-wechat.
*
* (c) overtrue <i@overtrue.me>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
return [
// HTTP 请求的超时时间(秒)
'timeout' => 5.0,
// 默认发送配置
'default' => [
// 网关调用策略,默认:顺序调用
'strategy' => \Overtrue\EasySms\Strategies\OrderStrategy::class,
// 默认可用的发送网关
'gateways' => [
'qcloud',
],
],
// 可用的网关配置
'gateways' => [
'errorlog' => [
'file' => storage_path('logs/easy-sms.log'),
],
'qcloud' => [
'sdk_app_id' => env('QCLOUD_SDK_APP_ID','1400949784'), // 短信应用的 SDK APP ID
'secret_id' => env('QCLOUD_SECRET_ID','AKIDGQRIxW3bJxVyHOZgfeYK9qKguvjPsAFC'), // SECRET ID
'secret_key' => env('QCLOUD_SECRET_KEY','Yu23sWxOk7d0GPPQI1lWDh3FEcs5990f'), // SECRET KEY
'sign_name' => env('QCLOUD_SIGN_NAME','苗侗同知堂医院'), // 短信签名
],
],
];
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment