From 54fdf3b762845eb24f29f1652d4e8882e1d2bcfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Wed, 30 Mar 2022 09:12:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81DNSPod=E5=9B=BD=E9=99=85?= =?UTF-8?q?=E7=89=88=EF=BC=88=E9=9C=80=E8=A6=81=E6=B5=8B=E8=AF=95=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/dnsclients/provider_dnspod.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/internal/dnsclients/provider_dnspod.go b/internal/dnsclients/provider_dnspod.go index afdb9b29..32a850cc 100644 --- a/internal/dnsclients/provider_dnspod.go +++ b/internal/dnsclients/provider_dnspod.go @@ -14,13 +14,15 @@ import ( ) const ( - DNSPodMaxTTL int32 = 604800 + DNSPodMaxTTL int32 = 604800 + DNSPodInternational = "international" ) // DNSPodProvider DNSPod服务商 type DNSPodProvider struct { BaseProvider + region string apiId string apiToken string } @@ -29,6 +31,7 @@ type DNSPodProvider struct { func (this *DNSPodProvider) Auth(params maps.Map) error { this.apiId = params.GetString("id") this.apiToken = params.GetString("token") + this.region = params.GetString("region") if len(this.apiId) == 0 { return errors.New("'id' should be not empty") @@ -230,8 +233,11 @@ func (this *DNSPodProvider) DeleteRecord(domain string, record *dnstypes.Record) // 发送请求 func (this *DNSPodProvider) post(path string, params map[string]string) (maps.Map, error) { - apiHost := "https://dnsapi.cn" - query := url.Values{ + var apiHost = "https://dnsapi.cn" + if this.region == DNSPodInternational { // 国际版 + apiHost = "https://api.dnspod.com" + } + var query = url.Values{ "login_token": []string{this.apiId + "," + this.apiToken}, "format": []string{"json"}, "lang": []string{"cn"}, @@ -244,9 +250,9 @@ func (this *DNSPodProvider) post(path string, params map[string]string) (maps.Ma return nil, err } req.Header.Set("Content-Type", "application/x-www-form-urlencoded") - req.Header.Set("User-Agent", "GoEdge Client/1.0.0 (iwind.liu@gmail.com)") + req.Header.Set("User-Agent", "GoEdge-Client/1.0.0 (iwind.liu@gmail.com)") - client := http.Client{} + var client = http.Client{} resp, err := client.Do(req) if err != nil { return nil, err @@ -259,13 +265,13 @@ func (this *DNSPodProvider) post(path string, params map[string]string) (maps.Ma if err != nil { return nil, err } - m := maps.Map{} + var m = maps.Map{} err = json.Unmarshal(body, &m) if err != nil { return nil, err } - status := m.GetMap("status") - code := status.GetString("code") + var status = m.GetMap("status") + var code = status.GetString("code") if code != "1" { return nil, errors.New("code: " + code + ", message: " + status.GetString("message")) }