PHP implementation of the automatic login Google Play download app _php technique

Source: Internet
Author: User
Tags php define

This article describes the PHP implementation of automatic login Google Play download app, the method has a good practical value. Share to everyone for your reference. The following steps are implemented:

First, the process:

1. Login to Google Play

It takes three steps to log into Google Play:
https://play.google.com/apps/publish/

https://accounts.google.com/ServiceLogin?hl=en&continue=https://play.google.com/apps/publish/

Https://accounts.google.com/ServiceLoginAuth

2. Download App zip

3.unzip

Second, the implementation code is as follows:

<?php define (' Root_path ', DirName (__file__));

Define (' Google_play_cookie_file ', ' google_play_cookie.txt '); /** * Login Google Play, download, unzip * DATE:2013-04-17 * Author:fdipzone * version:1.0/class Androidre
  portdownloader{private $username;
  Private $password;


  Private $dev _ACC;  /* init * @param string $username Google Play account * @param string $password the Google Play password * @param string $dev _acc Google Play Dev Account */Public function __construct ($username = ', $password = ', $dev _acc= ') {$this-&
    Gt;username = $username;
    $this->password = $password;
  $this-&GT;DEV_ACC = $dev _acc; * * * @param string $appname * @param string $sd Start date * @param string $ed End Date * @param string $down 
    LoadFile saved zip name */Public Function run ($appname = ', $sd = ', $ed = ', $downloadFile = ') {$package = $appname;
    $dim = ' overall,country,language,os_version,device,app_version,carrier '; $met = ' Daily_Device_installs,active_device_installs,daily_user_installs,total_user_installs,active_user_installs,daily_
    Device_uninstalls,daily_user_uninstalls,daily_device_upgrades '; $met = "Daily_device_installs,current_device_installs,daily_user_installs,total_user_installs,current_user_ Installs,daily_device_uninstalls,daily_user_uninstalls,daily_device_upgrades ";

    Google Modify 2013-08-06//login Google Play $this->loginauth ($this->username, $this->password); Download $this->downloadreport ($package, $SD, $ed, $dim, $met, $this->dev_acc, $downlo
  
  Adfile); 
  }/* Login Google play,create cookies * @param string $username * @param string $password * @return Boolean * * Private Function Loginauth ($username, $password) {//Step1 $MAINURL = "Https://play.google.com/apps/publis

    h/";
    $ch = Curl_init ();
    curl_setopt ($ch, Curlopt_url, $MAINURL); curl_setopt ($ch, Curlopt_cookiejar, google_play_cookie_file);
    curl_setopt ($ch, Curlopt_cookiefile, google_play_cookie_file);
    curl_setopt ($ch, Curlopt_returntransfer, 1);
    Curl_exec ($ch);

    Curl_close ($ch);
    Step 2 $serviceLoginUrl = "https://accounts.google.com/ServiceLogin?hl=en&continue=". $mainUrl;
    $ch = Curl_init ();
    curl_setopt ($ch, Curlopt_url, $SERVICELOGINURL);
    curl_setopt ($ch, Curlopt_cookiejar, google_play_cookie_file); 
    curl_setopt ($ch, Curlopt_cookiefile, google_play_cookie_file);
    curl_setopt ($ch, Curlopt_returntransfer, 1);
    $serviceLoginRespHtml = curl_exec ($ch);

    Curl_close ($ch); Preg_match ('/name= "DSH" \s*id= "DSH" \s*value= "(. *?)" \s*/i ', $serviceLoginRespHtml, $matches);

    Get dsh $dsh = $matches [1]; Preg_match ('/name= "Galx" \s*value= "(. *?)" \s*/i ', $serviceLoginRespHtml, $matches);

    Get galx $galx = $matches [1];
    Step 3 $loginGoogleUrl = "Https://accounts.google.com/ServiceLoginAuth";
    $postFields = "referer=". $serviceLoginUrl; $postFields. = "&allowautoredirect=false";
    $postFields. = "&continue=". $mainUrl;
    $postFields. = "&dsh=". $dsh;
    $postFields. = "&h1=en";
    $postFields. = "&galx=". $galx;
    $postFields. = "&email=". $username;
    $postFields. = "&passwd=". $password;
    $postFields. = "&signin=sign+in";
    
    $postFields. = "&persistentcookie=yes";
    $ch = Curl_init ();
    curl_setopt ($ch, Curlopt_url, $LOGINGOOGLEURL);
    curl_setopt ($ch, Curlopt_post, 1);
    curl_setopt ($ch, Curlopt_postfields, $postFields);
    curl_setopt ($ch, Curlopt_cookiejar, google_play_cookie_file); 
    curl_setopt ($ch, Curlopt_cookiefile, google_play_cookie_file); 
    curl_setopt ($ch, Curlopt_header, true); 
    curl_setopt ($ch, curlopt_followlocation, true);
    curl_setopt ($ch, Curlopt_returntransfer, 1);
    Curl_exec ($ch);

    Curl_close ($ch);
  Login Cookies Create success return true; }//Download the downloadreport of the file Private function ($package, $SD, $ed, $dim, $met, $dev _acc, $downloadFile) {$url = "https://play.google.com/apps/publish/statistics/download?package
    
    ={$package}&sd={$sd}&ed={$ed}&dim={$dim}&met={$met}&dev_acc={$dev _ACC} ";

    $fp = fopen ($downloadFile, "w"); 
    $ch = Curl_init ();
    curl_setopt ($ch, Curlopt_url, $url); 
    curl_setopt ($ch, Curlopt_returntransfer, 1);
    curl_setopt ($ch, Curlopt_file, $fp); 
    curl_setopt ($ch, Curlopt_cookiefile, google_play_cookie_file); 
    Curl_exec ($ch); 
    Curl_close ($ch);

    Fclose ($FP);
    if (file_exists ($downloadFile)) {return true;

  return false; }/* Unzip the @param string $downloadFile zip file/Public function Unz A string $path decompression path * @param
    Ipreport ($path, $downloadFile) {$exec = "unzip". $downloadFile. "-D". $path;
    Shell_exec ($exec); Unlink ($downloadFile);
Delete zip file}//Demo $username = ' testdev@gmail.com ';
$password = ' abcd1234 '; $dev _ACC = ' 12345678901234567890 ';
$appname = ' Com.testdev ';
$SD = ' 20130417 ';
$ed = ' 20130417 ';
$downloadFile = ' Testdev.zip '; $unzipPath = Root_path. '

/testdev/';
$obj = new Androidreportdownloader ($username, $password, $dev _ACC);

 if ($obj->run ($appname, $SD, $ed, $downloadFile)) {$obj->unzipreport ($unzipPath, $downloadFile);}?>

I believe this article describes the PHP program design has a certain reference value.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.