Example #1
0
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
        curl_setopt($ch, CURLOPT_USERAGENT, 'LocalDomains_PHP/1.0.0(roy@leadnt.com)');
        $result = curl_exec($ch);
        curl_close($ch);
        return $result;
    }
    public function exec()
    {
        $ip = $this->getMyIp();
        $domainInfo = $this->api_call('domain.info', array('domain' => $this->domain));
        $domainId = $domainInfo['domain']['id'];
        $record = $this->api_call('record.list', array('domain_id' => $domainId, 'offset' => '0', 'length' => '1', 'sub_domain' => $this->sub_domain));
        if ($record['info']['record_total'] == 0) {
            $this->api_call('record.create', array('domain_id' => $domainId, 'sub_domain' => $this->sub_domain, 'record_type' => 'A', 'record_line' => '默认', 'value' => $ip, 'ttl' => '3600'));
        } else {
            if ($record['records'][0]['value'] != $ip) {
                $this->api_call('record.modify', array('domain_id' => $domainId, 'record_id' => $record['records'][0]['id'], 'sub_domain' => $this->sub_domain, 'record_type' => 'A', 'record_line' => '默认', 'value' => $ip));
            } else {
                echo '指向正常';
            }
        }
    }
}
$dns = new Dns();
$dns->exec();