使用PHP CURL进行Apple服务和支持覆盖查询

时间:2016-12-01 12:30:41

标签: php ios curl post web

我想在网站上使用PHP CURL进行查询:Apple Service and Support Coverage并希望获得序列号为/ IMEI No (example IMEI: 359209071801769)的结果。

我该怎么做?有什么想法吗?

使用下面的代码,我没有得到任何结果,因为我无法发布该值。有什么想法吗?

<?php
    $cookie = "cookie.txt";

    if(!$_POST){
    $curl = curl_init(); 
    curl_setopt($curl, CURLOPT_URL, "https://checkcoverage.apple.com/gc?t=image&timestamp=".round((microtime(true) * 1000) - (60*60*3/1000)));
    curl_setopt($curl, CURLOPT_REFERER, "https://checkcoverage.apple.com/tr/tr/"); 
    curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); 
    curl_setopt($curl, CURLOPT_ENCODING, "gzip");
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 
    curl_setopt($curl, CURLOPT_VERBOSE, true); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
    curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie);
    curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie);
    $gv = curl_exec($curl);

    $sadf = json_decode($gv, true);

    echo '<form action="" method="post">';
    echo '<img src="data:image/jpeg;base64,'.$sadf["binaryValue"].'" /><br />';
    echo 'Type Captcha Code <input type="text" name="captcha" /><br />';
    echo 'Type IMEI<input type="text" name="imei" /><br />';
    echo '<input type="submit" value="Run" />';
    echo '</form>';
    curl_close($curl);
    }else{
    $imei = $_POST["imei"];
    $captcha = $_POST["captcha"];

    $curl = curl_init(); 
    curl_setopt($curl, CURLOPT_URL, "https://checkcoverage.apple.com/tr/tr/");
    curl_setopt($curl, CURLOPT_REFERER, "https://checkcoverage.apple.com/tr/tr/"); 
    curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); 
    curl_setopt($curl, CURLOPT_ENCODING, "gzip");
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 
    curl_setopt($curl, CURLOPT_POST, true); 
    curl_setopt($curl, CURLOPT_VERBOSE, true); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
    curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie);
    curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie);
    preg_match('#csrfToken\: "(.*?)"#si', curl_exec($curl), $token);
    $post = "sno=$imei&ans=$captcha&captchaMode=image&CSRFToken=".$token[1]; 
    curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
    $content = preg_replace("/<head.*>/i", "<head><base href='https://checkcoverage.apple.com/' />", curl_exec($curl), 1);

    if(curl_exec($curl) === false){ 
    echo 'Curl error: ' . curl_error($curl); 
    }else{ 

    echo $content;
    } 
    curl_close($curl);
    }
    ?>

1 个答案:

答案 0 :(得分:0)

  1. 使用empty代替gzip进行编码。如果你指定gzip然后它只会处理gzip,就好像你指定为空它会处理所有。

    curl_setopt($ curl,CURLOPT_ENCODING,“”);

  2. 使用Cookie的完整路径而不是绝对路径。即$cookie = "/var/some/cookie.txt"

  3. 使用http_build_query作为帖子参数而不是原始参数(如果您的帖子参数中有任何特殊字符,则使用{。p>

  4. 使用详细信息运行代码以查看curl发生的情况。

    curl_setopt($ curl,CURLOPT_VERBOSE,true);