Google Play刮刮评论

时间:2020-01-26 18:43:52

标签: php

<?php if(!isset($_POST['1'])){ ?>

<form action="gp.php" method="POST" name="app">
<input type="text" name="app" placeholder="Write App id">
<input type="submit" name = "1" value="Send" />
<button>Click</button>
</form>

<?php
}else{

if($_POST['app'] == "")
     die("<script>alert('App id not write.')</script><meta http-equiv='Refresh' content='0; URL=/gp.php'>");

$app = $_POST['app'];
$url = "https://play.google.com/store/apps/details?id=$app&hl=tr&showAllReviews=true";

 function connectGpSite($url){

    $ch = curl_init();

  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
  curl_setopt($ch, CURLOPT_TIMEOUT, 15);
  curl_setopt($ch, CURLOPT_VERBOSE, 0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"); //Tarayıcı sürümü
    curl_setopt($ch, CURLOPT_URL, $url);

    $html= curl_exec($ch);
    $buhata = 0;
    $buhata = curl_errno($ch);
    curl_close($ch);
    if ($err!=0){
        $hata = Echo_Curl_Error($buhata);
        if($silent==0){
            echo "<b>Something went wrong. Error code: $err: ".$hata."</b><br />";
        }
        return false;
    }
    return $html;
}

 function connectGpSiteXhr($url, $app, $file = null, $fsid, $bl){

    $useragent = 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko';
    $timeout= 240;
    $dir = dirname(__FILE__);
    $_SERVER["REMOTE_ADDR"] = $_SERVER["REMOTE_ADDR"] ?? '127.0.0.1';
    $cookie_file    = $dir . '/cookies/' . md5($_SERVER['REMOTE_ADDR']) . '.txt';
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);    
    curl_setopt($ch, CURLOPT_FAILONERROR, true);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true );
    curl_setopt($ch, CURLOPT_ENCODING, "" );
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt($ch, CURLOPT_AUTOREFERER, true );
    curl_setopt($ch, CURLOPT_MAXREDIRS, 10 );
    curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
    curl_setopt($ch, CURLOPT_REFERER, 'http://www.google.com/');

    //:param sort: 1 = most hopeful, 2 = newest , 3 = rating
    $sort = 2;
    //:param count: page size
    $count = 40;
    //:param token: token needed for page > 1, each response contains token for next page
    $token = "?";

    $formdata = "[[[\"UsvDTd\",\"[null,null,[2,$sort,[$count,null,\ \"$token\ \"]],[\ \"$app\ \",7]]\",null,\"generic\"]]]";

    $fields = array("f.req" => $formdata);
    $method = "POST";

    if($file!=null){
        if (!curl_setopt($ch, CURLOPT_FILE, $file)){ // Handle error
                die("curl setopt bit the dust: " . curl_error($ch));
        }
        //curl_setopt($ch, CURLOPT_FILE, $file);
        $timeout= 3600;
    }
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout );
    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout );
    if($fields!=null){
        $postvars = http_build_query($fields); // build the urlencoded data
        if($method=="POST"){
            // set the url, number of POST vars, POST data
            curl_setopt($ch, CURLOPT_POST, count($fields));
            curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
        }
        if($method=="GET"){
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
            $url = $url.'?'.$postvars;
        }
    }

            $params = array(
                'f.sid' => $fsid,
                'bl' => $bl,
                'hl' => 'tr',
                'authuser' => '',
                'soc-app' => '121',
                'soc-platform' => '1',
                'soc-device' => '1',
                '_reqid' => '202915',
                'rt' => 'c'
            );

    $url = $url . '?' . http_build_query($params);

    curl_setopt($ch, CURLOPT_URL, $url);
    $content = curl_exec($ch);
    if (!$content){
        $error = curl_error($ch);
        $info = curl_getinfo($ch);
        die("cURL request failed, error = {$error}; info = " . print_r($info, true));
    }
    if(curl_errno($ch)){
        echo 'error:' . curl_error($ch);
    } else {
        return $content;        
    }
    curl_close($ch);
}

    $appinfo =  connectGpSite($url);

    preg_match('#<script data-id="_gd" nonce="(.*?)">window.WIZ_global_data = (.*?);</script>#si', $appinfo, $general);

    $piece = json_decode($general[2]);

    $bl   = $piece->{'cfb2h'};
    $fsid = $piece->{'FdrFJe'};

    $url = "https://play.google.com/_/PlayStoreUi/data/batchexecute";

    $appreview =  connectGpSiteXhr($url, $app, '',$fsid, $bl);

    print_r($appreview);

?>

<?php }  ?>

我正在尝试。获取有关Google Play的所有评论。但是我失败了。我设法得到一些参数。但是我找不到如何获取_reqid和token参数。我想好像有一些遗漏的部分。结果,我得到一个400错误。我找不到我犯的错误。你能帮我吗?谢谢。

0 个答案:

没有答案