PHP implementation automatically log in to Google Play Download App report method, appreport_php tutorial

Source: Internet
Author: User

PHP implementation automatically log in to Google Play Download App report method, Appreport


This article describes the PHP implementation of automatic login Google Play download App report method, has a good practical value. Share to everyone for your reference. The specific implementation steps are as follows:

First, the process:

1. Sign in to Google Play

It takes three steps to sign in to 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 the App report zip

3.unzip Report

Second, the implementation code is as follows:

<?phpdefine (' Root_path ', DirName (__file__));d efine (' google_play_cookie_file ', ' google_play_cookie.txt ');/*** Login Google Play, download report, unzip* date:2013-04-17* author:fdipzone* version:1.0*/class Androidreportdownloa  der{private $username;  Private $password;  Private $dev _ACC; /* init * @param string $username Google Play account * @param string $password Google Play password * @param string $d Ev_acc Google Play Dev Account */Public function __construct ($username = ", $password =", $dev _acc= ") {$this->use    Rname = $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 $downloadFi    Le 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 report zip return $this->downloadreport ($package, $SD, $ed, $dim, $met, $this->dev_acc, $downloadFile    ); }/* Login Google play,create cookies * @param string $username * @param string $password * @return Boolean */priv    Ate function Loginauth ($username, $password) {//Step1 $MAINURL = "https://play.google.com/apps/publish/";    $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 Cookie Create success return true;     }//Download report zip file Private Function Downloadreport ($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 report * @param string $path extracted path * @param string $downloadFile zip file */Public function Unziprepo    RT ($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 '; $app name = ' 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);}? >

It is believed that this article has certain reference value to the PHP program design of everybody.


How do I download the app on Google Play?

General registration of a @gmail mailbox can be downloaded

Automatically sign in to your Google site account with PHP

Yes, download an HTTP request analyzer, and after you turn on monitoring, you sign in to your Google account and see what the HTTP data stream looks like. Then use the PHP program to open a socket channel to Google's Web login server, imitate the HTTP data you analyzed, directly to the channel to write data.

Of course, there may be a simpler way, you look at the login page source code, try to direct the user name and password to the address written in the form to submit the success, if you can successfully directly with PHP to submit the user name and password on it.

By the way, Google's login seems to be through the SSL secure channel, using PHP How to use the SSL you can look at it yourself.

http://www.bkjia.com/PHPjc/882899.html www.bkjia.com true http://www.bkjia.com/PHPjc/882899.html techarticle PHP implementation automatically login Google Play download App report method, Appreport This article explains the PHP implementation automatically login Google Play download App report method, has a good practical value. Share ...

  • Related Article

    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.