argument('mobile')); if (preg_match('/^1[3-9]\d{9}$/', $mobile) !== 1) { $this->error('手机号格式无效。'); return self::FAILURE; } $smsEnabled = (bool) config('sms.enabled'); if (! $smsEnabled && ! $this->option('allow-disabled')) { $this->error('SMS_ENABLED=false,默认拒绝执行短信联调;真实发送请设置 SMS_ENABLED=true,dry run 请显式传入 --allow-disabled。'); return self::FAILURE; } if ($smsEnabled && app()->environment('production') && ! $this->option('yes')) { if (! $this->confirm('production 环境将向真实手机号发送短信,是否继续?', false)) { $this->warn('已取消发送。'); return self::FAILURE; } } try { $result = $service->sendLoginCode($mobile, $sender); } catch (ValidationException $exception) { $this->error(implode(';', collect($exception->errors())->flatten()->all())); return self::FAILURE; } $verification = $result->verification->refresh(); $this->line('verification_id: '.$verification->id); $this->line('mobile: '.$this->maskMobile($verification->mobile)); $this->line('status: '.$verification->status); $this->line('provider: '.$verification->provider); $this->line('provider_code: '.($verification->provider_code ?? '')); $this->line('provider_request_id: '.($verification->provider_request_id ?? '')); $this->line('message: '.($verification->provider_message ?: $result->message)); return $result->success ? self::SUCCESS : self::FAILURE; } private function maskMobile(string $mobile): string { if (strlen($mobile) < 11) { return '***'; } return substr($mobile, 0, 3).'****'.substr($mobile, -4); } }