[login] ``` $value) { $canonicalizedQueryString .= '&' . percentEncode($key) . '=' . percentEncode($value); } // 生成用于计算签名的字符串 stringToSign $stringToSign = 'GET&%2F&' . percentencode(substr($canonicalizedQueryString, 1)); // 计算签名,注意accessKeySecret后面要加上字符'&' $signature = base64_encode(hash_hmac('sha1', $stringToSign, $accessKeySecret . '&', true)); return $signature; } function get_action($data, $Version, $host) { date_default_timezone_set("GMT"); $dateTimeFormat = 'Y-m-d\TH:i:s\Z'; global $AccessKey_ID; global $Access_Key_Secret; $publicdata = array( // 公共参数 'Format' => 'JSON', 'Version' => $Version, 'AccessKeyId' => $AccessKey_ID, 'SignatureVersion' => '1.0', 'SignatureMethod' => 'HMAC-SHA1', 'SignatureNonce' => uniqid(), 'Timestamp' => date($dateTimeFormat), 'TimeStamp' => date($dateTimeFormat) ); $data = array_merge($publicdata, $data); $data['Signature'] = computeSignature($data, $Access_Key_Secret); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $host . http_build_query($data)); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); $res = curl_exec($ch); date_default_timezone_set('PRC'); //echo $res; return $res; } //流量JSON function RunInstances() { $data = array( 'Action' => 'RunInstances', 'RegionId' => 'cn-hongkong', 'LaunchTemplateId' => "lt-j6c2m6i40r5dy5s84lv7", 'LaunchTemplateVersion' => "1", 'Password' => 'Mxy6994.....', ); $res = (string) get_action($data, '2014-05-26', 'https://ecs.aliyuncs.com/?'); echo $res; // { // "RequestId": "473469C7-AA6F-4DC5-B3DB-A3DC0DE3****", // "OrderId": "123456****", // "TradePrice": 0.165, // "InstanceIdSets": { // "InstanceIdSet": [ // "[\"i-bp67acfmxazb4pd2****\", \"i-bp1i43l28m7u48p1****\", \"i-bp12yqg7jdyxl11f****\"]" // ] // } // } //保存 global $countFile; file_put_contents($countFile, $res); } function DescribeInstances () { global $countFile; $fileContent = file_get_contents($countFile); $resdata = json_decode($fileContent, true); //取InstanceIdSet $InstanceId = $resdata['InstanceIdSets']['InstanceIdSet'][0]; echo $InstanceId; $data = array( 'Action' => 'DescribeInstances', 'RegionId' => 'cn-hongkong', 'InstanceIds' => "['" . $InstanceId ."']" ); $res = (string) get_action($data, '2014-05-26', 'https://ecs.aliyuncs.com/?'); //取Instances.Instance[0].PublicIpAddress.IpAddress $resdata = json_decode($res, true); $publicIp = $resdata['Instances']['Instance'][0]['PublicIpAddress']['IpAddress'][0]; //换行 print ""; echo $publicIp; // 要访问的 URL $url = "https://i.lil.cx/ahk/cfddns.php?ip=". $publicIp; // 使用 file_get_contents() 访问 URL 并获取响应 $response = file_get_contents($url); // 检查是否成功获取响应 if ($response === FALSE) { echo '无法访问 URL 或获取内容失败'; } else { // 输出响应内容 echo $response; } } $countFile = 'ahkres.txt'; //创建$_REQUEST if (!isset($_REQUEST['msg'])) { exit; } else { if ($_REQUEST['msg'] == 'chuangjian') { RunInstances(); } if ($_REQUEST['msg'] == 'chaxun') { DescribeInstances(); } } ?> ``` ``` 域名不合法 $CFRECORD_NAME\n"; } // 获取WAN IP if (!isset($_REQUEST['ip'])) { exit; } else { $WAN_IP = $_REQUEST['ip']; } // 获取 Cloudflare 的 zone_identifier & record_identifier $CFZONE_ID = getCloudflareId("https://api.cloudflare.com/client/v4/zones?name=$CFZONE_NAME", $CFUSER, $CFKEY); $CFRECORD_ID = getCloudflareId("https://api.cloudflare.com/client/v4/zones/$CFZONE_ID/dns_records?name=$CFRECORD_NAME", $CFUSER, $CFKEY); echo "CFZONE_ID=$CFZONE_ID\n"; echo "CFRECORD_ID=$CFRECORD_ID\n"; echo "Updating DNS to $WAN_IP\n"; $response = updateDNSRecord($CFZONE_ID, $CFRECORD_ID, $CFRECORD_TYPE, $CFRECORD_NAME, $WAN_IP, $CFTTL, $CFUSER, $CFKEY); if (strpos($response, '"success":true') !== false) { echo "成功更新\n"; } else { echo "响应错误\n"; echo "Response: $response\n"; } function getCloudflareId($url, $CFUSER, $CFKEY) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, [ "X-Auth-Email: $CFUSER", "X-Auth-Key: $CFKEY", "Content-Type: application/json", ]); $response = curl_exec($ch); curl_close($ch); $responseData = json_decode($response, true); if (isset($responseData['result'][0]['id'])) { return $responseData['result'][0]['id']; } else { die("获取ID失败: $response"); } } function updateDNSRecord($zoneId, $recordId, $type, $name, $content, $ttl, $CFUSER, $CFKEY) { $url = "https://api.cloudflare.com/client/v4/zones/$zoneId/dns_records/$recordId"; $data = [ "id" => $zoneId, "type" => $type, "name" => $name, "content" => $content, "ttl" => $ttl, ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, [ "X-Auth-Email: $CFUSER", "X-Auth-Key: $CFKEY", "Content-Type: application/json", ]); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); $response = curl_exec($ch); curl_close($ch); return $response; } ?> ``` [/login] 该部分仅登录用户可见 最后修改:2024 年 06 月 01 日 © 允许规范转载 打赏 赞赏作者 赞 如果觉得我的文章对你有用,请随意赞赏