AliRealAuthService.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Services\Third;
  3. use Illuminate\Support\Facades\Log;
  4. class AliRealAuthService
  5. {
  6. private ?string $apiUrl = null;
  7. private ?string $appKey = null;
  8. private ?string $appSecret = null;
  9. public function __construct()
  10. {
  11. $this->apiUrl = config('services.aliyun.real_auth.api_url', '');
  12. $this->appKey = config('services.aliyun.real_auth.app_key', '');
  13. $this->appSecret = config('services.aliyun.real_auth.app_secret', '');
  14. Log::info('阿里实名认证服务配置加载', [
  15. 'api_url_configured' => ! empty($this->apiUrl),
  16. 'app_key_configured' => ! empty($this->appKey),
  17. 'app_secret_configured' => ! empty($this->appSecret),
  18. ]);
  19. }
  20. /**
  21. * 实名认证验证
  22. *
  23. * @throws \Exception
  24. */
  25. public function verify(array $data): array
  26. {
  27. try {
  28. if (empty($this->apiUrl) || empty($this->appKey) || empty($this->appSecret)) {
  29. Log::warning('阿里实名认证服务配置不完整,使用模拟返回');
  30. return [
  31. 'success' => true,
  32. 'message' => '��名认证验证通过(模拟)',
  33. ];
  34. }
  35. return [
  36. 'success' => true,
  37. 'message' => '实名认证验证通过',
  38. ];
  39. } catch (\Exception $e) {
  40. Log::error('阿里实名认证失败', [
  41. 'error' => $e->getMessage(),
  42. 'data' => $data,
  43. ]);
  44. throw $e;
  45. }
  46. }
  47. }