DDNS.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Components;
  3. use App\Components\DDNS\Aliyun;
  4. use App\Components\DDNS\CloudFlare;
  5. use App\Components\DDNS\DNSPod;
  6. use App\Components\DDNS\Namesilo;
  7. use Log;
  8. /**
  9. * Class DDNS 域名解析.
  10. */
  11. class DDNS
  12. {
  13. /**
  14. * 删除解析记录.
  15. *
  16. * @param string $domain 域名
  17. * @param string|null $type
  18. * @return false|int
  19. */
  20. public static function destroy(string $domain, $type = null)
  21. {
  22. return self::dnsProvider($domain)->destroy($type);
  23. }
  24. private static function dnsProvider($domain)
  25. {
  26. switch (sysConfig('ddns_mode')) {
  27. case 'aliyun':
  28. return new Aliyun($domain);
  29. case 'namesilo':
  30. return new Namesilo($domain);
  31. case 'dnspod':
  32. return new DNSPod($domain);
  33. case 'cloudflare':
  34. return new CloudFlare($domain);
  35. default:
  36. Log::error('未知渠道:'.sysConfig('ddns_mode'));
  37. return false;
  38. }
  39. }
  40. /**
  41. * 修改解析记录.
  42. *
  43. * @param string $domain 域名
  44. * @param string $ip ip地址
  45. * @param string $type 记录类型,默认为 A
  46. * @return array|false|mixed
  47. */
  48. public static function update(string $domain, string $ip, string $type = 'A')
  49. {
  50. return self::dnsProvider($domain)->update($ip, $type);
  51. }
  52. /**
  53. * 添加解析记录.
  54. *
  55. * @param string $domain 域名
  56. * @param string $ip ip地址
  57. * @param string $type 记录类型,默认为 A
  58. * @return array|false|mixed
  59. */
  60. public static function store(string $domain, string $ip, string $type = 'A')
  61. {
  62. return self::dnsProvider($domain)->store($ip, $type);
  63. }
  64. }