getZoneID($CloudFlareConfig['base_domain']); $dns = new Cloudflare\API\Endpoints\DNS($adapter); $records = $dns->listRecords($zoneID, 'A', $CloudFlareConfig['secondary_domain']); $recordId = $records->result[0]->id; $recordIp = $records->result[0]->content; } catch (Exception $e) { logMessage('ERROR', $e->getMessage()); die; } $res = shell_exec('curl -s https://ip.cn'); $res = @json_decode($res, true); if (!empty($res['ip'])) { $realIp = $res['ip']; if ($realIp !== $recordIp) { $msg = 'ip changed from ' . $recordIp . ' to ' . $realIp; $details = [ 'type' => 'A', 'name' => $CloudFlareConfig['secondary_domain'], 'content' => $realIp ]; try { $dns->updateRecordDetails($zoneID, $recordId, $details); $cmd = <<< CMD curl -s 'https://oapi.dingtalk.com/robot/send?access_token={$globalConfig['dingtalk_token']}' -H 'Content-Type: application/json' -d "{\"msgtype\": \"text\",\"text\": {\"content\": \"$msg\"}}" CMD; shell_exec($cmd); logMessage('SUCCESS', $msg); } catch (Exception $e) { logMessage('ERROR', $e->getMessage()); } } else { logMessage('VOID', 'ip same'); } } else { logMessage('ERROR', 'get real ip fail'); } function logMessage($type, $msg = '') { echo date('Y-m-d H:i:s') . ' ' . $type . ': ' . $msg . PHP_EOL; }