【原创】php 阿里云云解析 动态域名 PHP 通过阿里云API接口实现 DDNS 动态解析

1.解析先,创建一个域名 tj.test.com

【原创】php 阿里云云解析 动态域名 PHP 通过阿里云API接口实现 DDNS 动态解析插图

2.通过api 云解析调试界面获取 tj.test.com 的RecordId

【原创】php 阿里云云解析 动态域名 PHP 通过阿里云API接口实现 DDNS 动态解析插图1

3.编辑php源码:填写好 accessKeyId accessSecrec DomainName RecordId RR

【原创】php 阿里云云解析 动态域名 PHP 通过阿里云API接口实现 DDNS 动态解析插图2

4. 提交运行php ,更新成功

【原创】php 阿里云云解析 动态域名 PHP 通过阿里云API接口实现 DDNS 动态解析插图3

5.后台查看更新成功。

【原创】php 阿里云云解析 动态域名 PHP 通过阿里云API接口实现 DDNS 动态解析插图4

6.php更新A解析源码,记得修改相应的信息。

<?php date_default_timezone_set("GMT"); //绑定 ip 到域名 Ali::Obj()->UpdateDomainRecord(); class Ali { private $accessKeyId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; private $accessSecrec = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; private static $obj = null; public static function Obj () { if(is_null(self::$obj)) { self::$obj = new self(); } return self::$obj; } public function DescribeDomainRecords() { $requestParams = array( "Action" => "DescribeDomainRecords", "DomainName" => "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.com" ); $val = $this->requestAli($requestParams); $this->outPut($val); } /** * 更新 ip */ public function UpdateDomainRecord() { $ip = $this->ip(); $requestParams = array( "Action" => "UpdateDomainRecord", "RecordId" => "11111111111111111111111111111111111111", "RR" => "tj", "Type" => "A", "Value" => $ip, ); $val = $this->requestAli($requestParams); $this->outPut($val." ".$ip); } private function requestAli($requestParams) { $publicParams = array( "Format" => "JSON", "Version" => "2015-01-09", "AccessKeyId" => $this->accessKeyId, "Timestamp" => date("Y-m-d\TH:i:s\Z"), "SignatureMethod" => "HMAC-SHA1", "SignatureVersion" => "1.0", "SignatureNonce" => substr(md5(rand(1,99999999)),rand(1,9),14), ); $params = array_merge($publicParams, $requestParams); $params['Signature'] = $this->sign($params, $this->accessSecrec); $uri = http_build_query($params); $url = 'http://alidns.aliyuncs.com/?'.$uri; return $this->curl($url); } private function ip() { $ip = $this->curl("http://httpbin.org/ip"); $ip = json_decode($ip,true); return $ip['origin']; } private function sign($params, $accessSecrec, $method="GET") { ksort($params); $stringToSign = strtoupper($method).'&'.$this->percentEncode('/').'&'; $tmp = ""; foreach($params as $key=>$val){ $tmp .= '&'.$this->percentEncode($key).'='.$this->percentEncode($val); } $tmp = trim($tmp, '&'); $stringToSign = $stringToSign.$this->percentEncode($tmp); $key = $accessSecrec.'&'; $hmac = hash_hmac("sha1", $stringToSign, $key, true); return base64_encode($hmac); } private function percentEncode($value=null) { $en = urlencode($value); $en = str_replace("+", "%20", $en); $en = str_replace("*", "%2A", $en); $en = str_replace("%7E", "~", $en); return $en; } private function curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 ); $result=curl_exec ($ch); return $result; } private function outPut($msg) { echo date("Y-m-d H:i:s")." ".$msg.PHP_EOL; } } 

7. 获取 域名对应的RecordId 源码示例:

aliyun alidns DescribeDomainRecords --region cn-hangzhou --RegionId cn-hangzhou --DomainName xxxxxxxxx.com
<?php use AlibabaCloud\Client\AlibabaCloud; use AlibabaCloud\Client\Exception\ClientException; use AlibabaCloud\Client\Exception\ServerException; // Download:https://github.com/aliyun/openapi-sdk-php // Usage:https://github.com/aliyun/openapi-sdk-php/blob/master/README.md AlibabaCloud::accessKeyClient('<accessKeyId>', '<accessSecret>') ->regionId('cn-hangzhou') ->asDefaultClient(); try { $result = AlibabaCloud::rpc() ->product('Alidns') // ->scheme('https') // https | http ->version('2015-01-09') ->action('DescribeDomainRecords') ->method('POST') ->host('alidns.aliyuncs.com') ->options([ 'query' => [ 'RegionId' => "cn-hangzhou", 'DomainName' => "xxxxxxxxxxxxxxx.com", ], ]) ->request(); print_r($result->toArray()); } catch (ClientException $e) { echo $e->getErrorMessage() . PHP_EOL; } catch (ServerException $e) { echo $e->getErrorMessage() . PHP_EOL; } 

原文链接:https://blog.csdn.net/jxyk2007/article/details/109219855?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522168476299816800182144178%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=168476299816800182144178&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-25-109219855-null-null.blog_rank_default&utm_term=NAS%E3%80%81%E7%BE%A4%E6%99%96%E3%80%81%E9%98%BF%E9%87%8C%E4%BA%91%E3%80%81%E5%9F%9F%E5%90%8D%E8%A7%A3%E6%9E%90%E3%80%81%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F%E3%80%81ipv6%E3%80%81ddns%E3%80%81%E8%BD%BB%E9%87%8F%E7%BA%A7%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8%E3%80%81%E9%93%81%E5%A8%81%E9%A9%AC%E3%80%81%E5%A8%81%E8%81%94%E9%80%9A%E3%80%81DSM%E3%80%81DSM6.0%E3%80%81%E7%BE%A4%E6%99%96nas%E3%80%81%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8%E3%80%81%E8%9C%97%E7%89%9B%E6%98%9F%E9%99%85%E3%80%81%E9%BB%91%E7%BE%A4%E6%99%96%E3%80%81docker%E3%80%81%E5%AE%B9%E5%99%A8%E9%95%9C%E5%83%8F%E3%80%81%E5%9F%9F%E5%90%8D%E6%B3%A8%E5%86%8C%E3%80%81%E5%AE%9D%E5%A1%94%E3%80%81%E5%8F%8D%E5%90%91%E4%BB%A3%E7%90%86%E3%80%81nginx%E3%80%81frp%E3%80%81%E5%8A%A8%E6%80%81%E5%9F%9F%E5%90%8D%E8%A7%A3%E6%9E%90

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享