mirror of
				https://github.com/v2board/v2board.git
				synced 2025-10-31 09:21:46 +08:00 
			
		
		
		
	update
This commit is contained in:
		| @@ -8,6 +8,7 @@ use App\Http\Controllers\Controller; | ||||
| use Illuminate\Http\Exceptions\HttpResponseException; | ||||
| use Illuminate\Support\Facades\Mail; | ||||
| use Illuminate\Support\Facades\Redis; | ||||
| use App\Jobs\SendEmail; | ||||
|  | ||||
| class CommController extends Controller | ||||
| { | ||||
| @@ -34,21 +35,15 @@ class CommController extends Controller | ||||
|         } | ||||
|         $code = rand(100000, 999999); | ||||
|         $subject = config('v2board.app_name', 'V2Board') . '邮箱验证码'; | ||||
|         Mail::send( | ||||
|             'mail.sendEmailVerify',  | ||||
|             [ | ||||
|                 'code' => $code, | ||||
|                 'name' => config('v2board.app_name', 'V2Board') | ||||
|             ], | ||||
|             function ($message) use($email, $subject) {  | ||||
|                 $message->to($email)->subject($subject);  | ||||
|             } | ||||
|         ); | ||||
|         if (count(Mail::failures()) >= 1) { | ||||
|             // 发送失败 | ||||
|             abort(500, '发送失败'); | ||||
|         } | ||||
|  | ||||
|     	$this->dispatch(new SendEmail([ | ||||
|     		'email' => $email, | ||||
|     		'template_name' => 'mail.sendEmailVerify', | ||||
|     		'template_value' => [ | ||||
|     			'code' => $code, | ||||
|     			'name' => config('v2board.app_name', 'V2Board') | ||||
|     		], | ||||
|     		'subject' => $subject | ||||
|     	])); | ||||
|         Redis::set($redisKey, $code); | ||||
|         Redis::expire($redisKey, 600); | ||||
|         return response([ | ||||
|   | ||||
							
								
								
									
										44
									
								
								app/Jobs/SendEmail.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								app/Jobs/SendEmail.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,44 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Jobs; | ||||
|  | ||||
| use Illuminate\Bus\Queueable; | ||||
| use Illuminate\Contracts\Queue\ShouldQueue; | ||||
| use Illuminate\Foundation\Bus\Dispatchable; | ||||
| use Illuminate\Queue\InteractsWithQueue; | ||||
| use Illuminate\Queue\SerializesModels; | ||||
| use Illuminate\Support\Facades\Mail; | ||||
|  | ||||
| class SendEmail implements ShouldQueue | ||||
| { | ||||
|     use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||||
|     protected $params; | ||||
|     /** | ||||
|      * Create a new job instance. | ||||
|      * | ||||
|      * @return void | ||||
|      */ | ||||
|     public function __construct($params) | ||||
|     { | ||||
|         $this->params = $params; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Execute the job. | ||||
|      * | ||||
|      * @return void | ||||
|      */ | ||||
|     public function handle() | ||||
|     { | ||||
|         $params = $this->params; | ||||
|         $email = $params['email']; | ||||
|         $subject = $params['subject']; | ||||
|         Mail::send( | ||||
|             $params['template_name'],  | ||||
|             $params['template_value'], | ||||
|             function ($message) use($email, $subject) {  | ||||
|                 $message->to($email)->subject($subject);  | ||||
|             } | ||||
|         ); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user