* * 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'], ] ]); } }