我有一个PHP脚本,它将一个新的'A'记录添加到Cloudflare区域,但是,默认情况下,这些新的'A'记录被Cloudflare设置为非活动状态,现在几天你无法将它们设置为活动状态创造它们。
因此,要编辑新记录以将其设置为活动记录,您需要“A”记录“rec_id”。在这种情况下,不能使用动作'rec_load_all',因为有太多的区域'A'记录,我不认为你可以过滤请求(可能是错误的,并且可能是错误的)。该区域需要过滤。
我尝试了以下'dns_get_rec_one',但它只返回'NULL',没有错误消息:
function returnId(){
$request = array();
$request['a'] = 'dns_get_rec_one';
$request['tkn'] = $this->tkn;
$request['email'] = $this->apiEmail;
$request['z'] = 'domain.com';
$request['name'] = 'sub.domain.com';
$response = @json_decode(file_get_contents('https://www.cloudflare.com/api_json.html?' . http_build_query($request)), true);
}
由于我对API交互几乎没有经验,所以有任何想法吗?
由于
答案 0 :(得分:1)
好的,我已经提出了一些帮助。
当您对Cloudflare进行CURL'rec_new'调用时,响应包含新“A”记录的'rec_id'。然后,可以将其用作下一个CURL“rec_edit”调用中的“id”,将记录编辑为活动状态。
Cloudflare的工作人员也会在24小时内给予答复并提供帮助。
来自下面的小组的片段:
private function newSub(){
$fields = array(
'a' => 'rec_new',
'tkn' => $this->tkn,
'email' => $this->apiEmail,
'z' => $this->domain,
'type' => 'A',
'name' => $this->subName,
'content' => $this->content,
'ttl' => 1
);
//url-ify the data for the POST
foreach($fields as $key=>$value){
$fields_string .= $key.'='.$value.'&';
}
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, 'https://www.cloudflare.com/api_json.html');
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
//execute post
$response = curl_exec($ch);
//close connection
curl_close($ch);
$response = json_decode($response,true);
if(!$response || $response['result'] != 'success'){
$responseError = $response['msg'];
// ERROR Handling
}else{
// Set rec_id for from the nw A record
$this->rec_id = $response['response']['rec']['obj']['rec_id'];
// Activate
$this->makeActive();
}
}
private function makeActive(){
$request['a'] = 'rec_edit';
$request['tkn'] = $this->tkn;
$request['email'] = $this->apiEmail;
$request['z'] = $this->domain;
$request['id'] = $this->rec_id;
$request['type'] = 'A';
$request['name'] = $this->subName;
$request['content'] = $this->content;
$request['service_mode'] = '1';// Make active
$request['ttl'] = '1';
$response = @json_decode(file_get_contents('https://www.cloudflare.com/api_json.html?' . http_build_query($request)), true);
//var_dump($response); die;
if(!$response || $response['result'] != 'success'){
$responseError = $response['msg'];
// ERROR Handling
}
}
希望这有助于某人。