false, ]; /** * @var array */ protected $fillable = [ 'user_id', 'phone', 'type', 'code', 'is_use', 'expires_at', ]; /** * @var array */ protected $casts = [ 'type' => 'int', 'is_use' => 'bool', 'expires_at' => 'datetime', ]; /** * 允许发送短信的验证码类型 * * @var array */ public static $allowedTypes = [ self::TYPE_REGISTER, self::TYPE_RESET_PASSWORD, self::TYPE_SET_WALLET_PASSWORD, self::TYPE_LOGIN, ]; /** * 阿里云短信模板 * * @var array */ public static $aliyunTemplates = [ // self::TYPE_REGISTER => 'SMS_231444585', // self::TYPE_RESET_PASSWORD => 'SMS_231444585', ]; /** * {@inheritdoc} */ protected static function booted() { static::created(function ($smsCode) { if (app()->isProduction()) { $smsCode->notify(new SmsCodeCreated($smsCode)); } }); } /** * 确认此验证码是否无效 * * @return bool */ public function isInvalid(): bool { return $this->is_use || ($this->expires_at && $this->expires_at->lte(now())); } /** * 阿里云短信模板 * * @return string */ public function getAliyunTemplate() { return static::$aliyunTemplates[$this->type] ?? 'SMS_231444585'; } /** * @param \Illuminate\Notifications\Notification $notification * @return string */ public function routeNotificationForSms($notification): string { return $this->phone; } }