获取CloudFlare上的所有域名的ID (zone_identifier) – by PHP

获取CloudFlare上的所有域名的ID (zone_identifier) – by PHP效果图CF_api_get_zone_ids.php?php/***Title:获取CloudFlare上的所有域名的ID(zone_identifier)*Author:Rudon285744011@qq.co

效果图获取CloudFlare上的所有域名的ID (zone_identifier) - by PHP

 

CF_api_get_zone_ids.php

<?php

    /**
     * Title:  获取CloudFlare上的所有域名的ID (zone_identifier)
     * Author: Rudon <285744011@qq.com>
     * Date:   2019-03-08
     * 
     * https://dash.cloudflare.com/
     * https://api.cloudflare.com/#getting-started-resource-ids
     * https://api.cloudflare.com/#getting-started-requests  > [Section] Requests + Pagination
     * https://api.cloudflare.com/#zone-list-zones
     * 
     * 
     */


    /* https://dash.cloudflare.com/ Email address associated with your account  */
    $x_email = 'you@yoursite.com'; // Email for current account
    $x_auth_key = 'kj487ykhjilj3glsuliu'; // Global API Key,获取步骤:My profile > API Tokens > 下面的API Keys > Global API Key > View
    $how_many_domains_you_have = 1000;  // Will be used as "per_page" in "Pagination"
    
    
    
    /* Origin command (仅作演示,可在命令行直接运行) */
    $command = <<<CCC
curl -X GET "https://api.cloudflare.com/client/v4/zones?page=1&per_page={$how_many_domains_you_have}&order=type&direction=asc" \
    -H "X-Auth-Email: {$x_email}" \
    -H "X-Auth-Key: {$x_auth_key}" \
    -H "Content-Type: application/json"
CCC;
    
    
    /**
     * https://blog.csdn.net/qq285744011/article/details/87859137
     * 
     * @param type $url
     * @param type $my_head_array | array() | array('key1:value1', 'key2:value2')
     * @return string 
     */
    function geturl($url, $my_head_array = array()){
        $headerArray =array("Content-Type: application/json;","Accept: application/json");
        if(is_array($my_head_array) && count($my_head_array)){
            $headerArray = $my_head_array;
        }
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch,  CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
        $output = curl_exec($ch);
        curl_close($ch);
        return $output;
    }
 
    $curl_url = "https://api.cloudflare.com/client/v4/zones?page=1&per_page={$how_many_domains_you_have}&order=type&direction=asc";
    $curl_head = array(
        "X-Auth-Email: {$x_email}",
        "X-Auth-Key: {$x_auth_key}",
        "Content-Type: application/json"
    );
        
    
    $response_json_str = geturl($curl_url, $curl_head);
    $res_arr = json_decode($response_json_str, TRUE);
    if(!is_array($res_arr) || !count($res_arr)){
        die('Sorry, invalid response:<br />'.$response_json_str);
    }
    if(!key_exists('success', $res_arr) || !$res_arr['success']){
        die('Failed to get the list of zones: <br />'.$response_json_str);
    }
    
    if(!key_exists('result', $res_arr)){
        die('Missing key `result`: <br />'.$response_json_str);
    }
    
    
    $list_ori = $res_arr['result'];
    $final_list = array();
    foreach ($list_ori as $k => $oneZone) {
        $final_list[] = array(
            'domain' => strtolower($oneZone['name']),
            'id' => $oneZone['id']
        );
    }
    
    
    $count_zones = count($final_list);
    $i = 1;
    echo "<h3>{$x_email}</h3>";
    echo '{';
    echo '<br />';
    foreach ($final_list as $oneZone) {
        echo '    "'.$oneZone['domain'].'":"'.$oneZone['id'].'"';
        if($i != $count_zones){
            echo ',';
        }
        echo '<br />';
        $i++;
    }
    echo '}';
    die();
    
    

 

今天的文章获取CloudFlare上的所有域名的ID (zone_identifier) – by PHP分享到此就结束了,感谢您的阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/67319.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注