cloudflare 批量域名ID

<?php
 
    /**
     * Title:  获取CloudFlare上的所有域名的ID (zone_identifier)
     * Author: Rudon <[email protected]>
     * 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 = '[email protected]'; // 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();