12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- /*
- * This file is part of the Jiannei/lumen-api-starter.
- *
- * (c) Jiannei <longjian.huang@foxmail.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
- namespace App\Jobs\Base;
- use App\Jobs\Job;
- use Carbon\Carbon;
- use Illuminate\Support\Facades\Hash;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Str;
- class SendAccountMessageJob extends Job
- {
- private $admin;
- /**
- * Create a new job instance.
- */
- public function __construct($admin)
- {
- $this->admin = $admin;
- }
- /**
- * 确定任务应该超时的时间
- *
- * @return \DateTime
- */
- public function retryUntil()
- {
- return Carbon::now()->addHours(8);
- }
- /**
- * Execute the job.
- */
- public function handle()
- {
- $admin = $this->admin;
- try {
- $password = rand(10000000, 99999999);
- $admin->password = Hash::make($password);
- $admin->save();
- $this->sendSMSMsg($admin['mobile'], [
- 'username' => $admin['username'],
- 'name' => $admin['name'],
- 'password' => $password,
- ]);
- } catch (\Exception $exception) {
- Log::error($exception);
- }
- return true;
- }
- private function sendSMSMsg($mobile, $data = [])
- {
- if (!$mobile) return false;
- app('easy_sms')->send($mobile, [
- 'template' => config('sms.template.new_admin_account'),
- 'data' => [
- 'username' => $data['username'],
- // 'name' => $data['name'],
- 'password' => $data['password'],
- ]
- ]);
- }
- }
|