Exemple #1
0
        /// <summary>
        /// 根据主解析记录删除相关的解析记录(可选实现)
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public override DomainRecordActionResult DeleteSubDomainRecords(DeleteDomainRecordParam param)
        {
            RecordListResult result = client.RecordList(new RecordListRequestParam()
            {
                domain = param.DomainName
            }).GetAwaiter().GetResult();

            if (result.Code != "0")
            {
                throw new Exception($"Get domain record info from tencent cloud failed. error id is {result.Code}, {result.Message}");
            }
            StringBuilder sb             = new StringBuilder();
            bool          isDeleteFailed = false;

            foreach (var item in result.Data.Records)
            {
                try
                {
                    if (item.name != param.RR)
                    {
                        continue;
                    }
                    var recordDeleteResult = client.RecordDelete(new RecordDeleteRequestParam()
                    {
                        domain   = param.DomainName,
                        recordId = item.id,
                    }).GetAwaiter().GetResult();
                    if (recordDeleteResult.Code != "0")
                    {
                        throw new Exception($"Delete record info from tencent cloud failed({recordDeleteResult.Code}). {recordDeleteResult.Message}");
                    }
                }
                catch (Exception ex)
                {
                    sb.AppendLine(ex.Message);
                    isDeleteFailed = true;
                }
            }
            if (isDeleteFailed)
            {
                throw new Exception(sb.ToString());
            }
            return(new DomainRecordActionResult()
            {
                Status = true,
                RR = param.RR,
            });
        }
Exemple #2
0
        public async Task <RecordListResult> RecordList(RecordListRequestParam param)
        {
            if (string.IsNullOrEmpty(param.domain))
            {
                throw new Exception("Domain can not null.");
            }
            try
            {
                RecordListResult result = await HttpRequest <RecordListResult>(param);

                return(result);
            }
            catch (Exception ex)
            {
                throw new Exception($"Tencent cloud ddns request error. {ex.Message}");
            }
        }
Exemple #3
0
        /// <summary>
        /// 获取域名全部解析记录
        /// </summary>
        /// <param name="domain"></param>
        /// <returns></returns>
        public override List <DomainRecord> DescribeSubDomainRecords(string domain)
        {
            if (string.IsNullOrEmpty(domain))
            {
                throw new Exception("domain can not null.");
            }
            TencentCloudDomianInfo info = GetDomianInfo(domain);

            if (info == null)
            {
                throw new Exception("Get tencent domain info from domain string failed.");
            }
            RecordListResult result = client.RecordList(new RecordListRequestParam()
            {
                domain = info.DomainName,
            }).GetAwaiter().GetResult();

            if (result.Code != "0")
            {
                throw new Exception($"Get domain record info from tencent cloud failed. error id is {result.Code}, {result.Message}");
            }
            List <DomainRecord> infos = new List <DomainRecord>();

            foreach (var item in result.Data.Records)
            {
                if (item.name == info.RR)
                {
                    infos.Add(new DomainRecord()
                    {
                        RR         = item.name,
                        Status     = item.status,
                        RecordId   = item.id.ToString(),
                        DomainName = result.Data.Domain.name,
                        TTL        = item.ttl,
                        Line       = item.line,
                        Type       = item.type,
                        Value      = item.value,
                    });
                }
            }
            return(infos);
        }
Exemple #4
0
        /// <summary>
        /// 根据recordId获取解析的详细信息(可选实现)
        /// </summary>
        /// <param name="recordId"></param>
        /// <returns></returns>
        public override DomainRecordInfo DescribeDomainRecordInfo(string recordId, string domain)
        {
            if (string.IsNullOrEmpty(recordId) && string.IsNullOrEmpty(domain))
            {
                throw new Exception("Recordid or domain can not null.");
            }
            TencentCloudDomianInfo info = GetDomianInfo(domain);

            if (info == null)
            {
                throw new Exception("Get tencent domain info from domain string failed.");
            }
            RecordListResult result = client.RecordList(new RecordListRequestParam()
            {
                domain = domain
            }).GetAwaiter().GetResult();

            if (result.Code != "0")
            {
                throw new Exception($"Get domain record info from tencent cloud failed. error id is {result.Code}, {result.Message}");
            }
            foreach (var item in result.Data.Records)
            {
                if (item.id.ToString() == recordId)
                {
                    return(new DomainRecordInfo()
                    {
                        RR = item.name,
                        Status = item.status,
                        RecordId = recordId,
                        DomainName = result.Data.Domain.name,
                        TTL = item.ttl,
                        Line = item.line,
                        Type = item.type,
                        Value = item.value,
                    });
                }
            }
            throw new Exception($"Get domain record info from tencent cloud failed. can not find record from this recordid({recordId})");
        }
Exemple #5
0
        static async Task Main(string[] args)
        {
            ICnsSdk ddns = new CnsSdk("你的SecretId", "你的SecretKey");
            //域名添加测试
            //DomainCreateRequestParam domainCreateRequestParam = new DomainCreateRequestParam()
            //{
            //    domain = "你的域名.net"
            //};
            //DomainCreateResult result = await ddns.DomainCreate(domainCreateRequestParam);
            //if (result.Code != "0")
            //{
            //    Console.WriteLine($"请求失败,错误代码:{result.Code},错误描述:{result.Message}");
            //}
            //else
            //{
            //    Console.WriteLine($"请求成功。添加解析的域名:{result.Data.Domain.Domain}");
            //}

            //设置域名解析状态
            //SetDomainStatusResult result = await ddns.SetDomainStatus(new SetDomainStatusRequestParam()
            //{
            //    domain = "你的域名.net",
            //    status = "disable"
            //});
            //if (result.Code != "0")
            //{
            //    Console.WriteLine($"请求失败,错误代码:{result.Code},错误描述:{result.Message}");
            //}
            //else
            //{
            //    Console.WriteLine($"请求成功。");
            //}

            //删除解析
            //DomainDeleteResult result = await ddns.DomainDelete(new DomainDeleteRequestParam()
            //{
            //    domain = "你的域名.net",
            //});
            //if (result.Code != "0")
            //{
            //    Console.WriteLine($"请求失败,错误代码:{result.Code},错误描述:{result.Message}");
            //}
            //else
            //{
            //    Console.WriteLine($"请求成功。");
            //}

            //全部域名列表
            //DomainListResult result = await ddns.DomainList(new DomainListRequestParam());
            //if (result.Code != "0")
            //{
            //    Console.WriteLine($"请求失败,错误代码:{result.Code},错误描述:{result.Message}");
            //}
            //else
            //{
            //    Console.WriteLine($"请求成功。当前共有{result.Data.Info.domain_total}条记录。");
            //}

            //创建解析记录
            //RecordCreateResult result = await ddns.RecordCreate(new RecordCreateRequestParam()
            //{
            //    domain = "你的域名.net",
            //    subDomain = "1112",
            //    recordType = Enum.RecordType.A,
            //    value = "1.0.0.0"
            //});
            //if (result.Code != "0")
            //{
            //    Console.WriteLine($"请求失败,错误代码:{result.Code},错误描述:{result.Message}");
            //}
            //else
            //{
            //    Console.WriteLine($"请求成功。记录名称:{result.Data.Record.Name}。");
            //}


            //解析记录状态修改
            //565216111
            //RecordStatusResult result = await ddns.RecordStatus(new RecordStatusRequestParam()
            //{
            //    domain = "你的域名.net",
            //    recordId = 565216111,
            //    status = "disable"
            //});
            //if (result.Code != "0")
            //{
            //    Console.WriteLine($"请求失败,错误代码:{result.Code},错误描述:{result.Message}");
            //}
            //else
            //{
            //    Console.WriteLine($"请求成功。状态:{result.CodeDesc}。");
            //}


            //解析记录删除
            //565216111
            //RecordDeleteResult result = await ddns.RecordDelete(new RecordDeleteRequestParam()
            //{
            //    domain = "你的域名.net",
            //    recordId = 565216111
            //});
            //if (result.Code != "0")
            //{
            //    Console.WriteLine($"请求失败,错误代码:{result.Code},错误描述:{result.Message}");
            //}
            //else
            //{
            //    Console.WriteLine($"请求成功,该记录已经删除。");
            //}

            //解析记录修改
            //565241026
            //RecordModifyResult result = await ddns.RecordModify(new RecordModifyRequestParam()
            //{
            //    domain = "你的域名.net",
            //    recordId = 565824016,
            //    subDomain = "66677",
            //    recordType = Enum.RecordType.CNAME,
            //    value = "cname.dnspod.com"
            //});
            //if (result.Code != "0")
            //{
            //    Console.WriteLine($"请求失败,错误代码:{result.Code},错误描述:{result.Message}");
            //}
            //else
            //{
            //    Console.WriteLine($"请求成功,已修改。");
            //}

            //获取域名解析记录列表
            RecordListResult resultList = await ddns.RecordList(new RecordListRequestParam()
            {
                domain = "你的域名.net",
            });

            if (resultList.Code != "0")
            {
                Console.WriteLine($"请求失败,错误代码:{resultList.Code},错误描述:{resultList.Message}");
            }
            else
            {
                Console.WriteLine($"请求成功。记录条数:{resultList.Data.Info.record_total}。");
                foreach (var itrm in resultList.Data.Records)
                {
                    Console.WriteLine($"记录ID:{itrm.id}\t记录类型:{itrm.type}\t记录域名:{itrm.name}.{resultList.Data.Domain.name}");
                }
            }

            Console.ReadKey(false);
        }