自动登入google play下载app report

2023-05-16

流程
1.登入google play

登入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.下载app report zip
3.unzip report


代码如下:
<?php
define('ROOT_PATH', dirname(__FILE__));
define('GOOGLE_PLAY_COOKIE_FILE', 'google_play_cookie.txt');

/**
* Login google play, download report, unzip
* Date:     2013-04-17
* Author:   fdipzone
* Version:  1.0
*/
class AndroidReportDownLoader{

    private $username;
    private $password;
    private $dev_acc;


    /* init
    * @param  String $username google play account
    * @param  String $password google play password
    * @param  String $dev_acc  google play dev account
    */
    public function __construct($username='', $password='', $dev_acc=''){
        $this->username = $username;
        $this->password = $password;
        $this->dev_acc = $dev_acc;
    }


    /*
    * @param  String $appname
    * @param  String $sd            开始日期
    * @param  String $ed            结束日期
    * @param  String $downloadFile  保存的zip名称
    */
    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
    */
    private 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 cookies 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         解压的路径
    * @param String $downloadFile zip file
    */
    public function unzipReport($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);
}

?>


本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

自动登入google play下载app report 的相关文章

  • php返回数据格式化类

    DataReturn class php lt php 返回數據格式化類 Date 2011 08 15 Author fdipzone class DataReturn class start private type private x

随机推荐

  • 强制更新图片缓存

    強制更新圖片緩存 64 param Array files 要更新的圖片 64 param int version 版本 function force reload file files 61 array version 61 0 html
  • php XML文件解释类

    XMLParser class php lt php XML 文件分析类 Date 2013 02 01 Author fdipzone Ver 1 0 func loadXmlFile xmlfile 读入xml文件输出Array loa
  • php CSS Update Class

    CSSUpdate class php lt php css 更新类 更新css文件内图片的版本 Date 2013 02 05 Author fdipzone Ver 1 1 Func update Ver 1 1 增加search ch
  • sh cssupdate

    shell sh 更新 css图片版本 bin bash csstmpl path 61 34 home fdipzone php csstmpl 34 css path 61 34 home fdipzone php css 34 rep
  • JS小游戏-宇宙战机

    游戏介绍 业余时间写的一个飞行射击游戏 xff0c 纵向 xff0c 共六关 游戏需求 1 战机可发射子弹 xff0c 子弹可通过获取道具升级 2 战机可放bomb xff0c 可获取道具增加数量 3 战机可蓄力攻击 4 道具有三种 xff
  • php __call 与 __callStatic

    php 5 3 后新增了 call 与 callStatic 魔法方法 call 当要调用的方法不存在或权限不足时 xff0c 会自动调用 call 方法 callStatic 当调用的静态方法不存在或权限不足时 xff0c 会自动调用 c
  • $CF1153A\ Serval\ and\ Bus$

    看大佬的代码都好复杂 xff08 不愧是大佬 orz 蒟蒻提供一种思路 因为求的是最近的车对吧 qwq 所以我们可以用一个 while 循环所以没必要去用什么 for 至于这是 div2 的第一题还是比较水的 code include lt
  • Sublime Text配置JDK

    操作系统 xff1a Windows 7 SP1 Sublime Text是一款轻量级代码编辑器 虽然收费 xff0c 但可以无限期试用 支持多种语言的代码高亮 xff0c 但一些不能直接编译运行 xff0c 今天我为大家带来Sublime
  • JS小游戏-仙剑翻牌

    游戏介绍 这是一个翻牌配对游戏 xff0c 共十关 1 游戏随机从42张牌中抽取9张进行游戏 xff0c 每组为2张相同的牌 xff0c 共18张牌 2 连续翻到两张相同的为胜利 xff0c 当9组全部翻到则过关 如不是翻到连续两张相同的
  • memcached 常用命令及使用说明

    memcached 查看方法 格式 telnet ip port 例如 telnet localhost 11211 退出命令 xff1a quit 一 存储命令 存储命令格式 xff1a lt command name gt lt key
  • PHPMailer - PHP email transport class

    在服务器安装 sendmail sudo apt get install sendmail 启动 sendmail sudo etc init d sendmail start 修改 php ini mail function SMTP 6
  • PHP 遍历文件夹及文件类及处理类

    FindFile class php 用于遍历目录文件 lt php 遍历文件夹及文件类 Date 2013 03 21 Author fdipzone Ver 1 0 class FindFile public files 61 arra
  • sh autolog backup

    shell sh 每天备份log文件 bin bash 每天备份log文件 log path 61 34 home fdipzone logs 34 log目录 backup path 61 34 home fdipzone logs ba
  • Apache rewrite

    1 开启rewrite sudo a2enmod rewrite 2 停用rewrite sudo a2dismod rewrite 3 服务器环境变量 Apache提供给rewirte模块的环境变量大概分成5个类型 第一部分 HTTP h
  • RewriteCond和13个mod_rewrite应用举例Apache伪静态

    1 xff0e 给子域名加www标记 RewriteCond HTTP HOST a z 43 example com NC RewriteCond HTTP HOST www NC RewriteRule http www xample
  • 正向代理与反向代理的区别

    正向代理的概念 正向代理 也就是传说中的代理 他的工作原理就像一个跳板 简单的说 我是一个用户 我访问不了某网站 但是我能访问一个代理服务器 这个代理服务器呢 他能访问那个我不能访问的网站 于是我先连上代理服务器 告诉他我需要那个无法访问网
  • Apache 搭建虚拟主机

    Apache 搭建虚拟主机方法 DocumentRoot xff1a home fdipzone sites demo fdipzone com ServerName xff1a demo fdipzone com 1 进入apache虚拟
  • sh memcached 进程启动及监控

    memcached 进程启动及监控 1 memcached inc sh 设置路径 xff0c 端口等讯息 bin sh config include HOST 61 hostname SITE 61 34 mysite 34 PORT 6
  • 设置进程的显示名称

    有时候在LINUX下 xff0c fork子进程的时候 xff0c 像nginx里的一样 xff0c 想让子进程的名字可以自定义 参考网上文章之后 xff0c 可以通过修改argv 0 的值来改变子进程的名字 xff0c 但是要注意新标题的
  • 自动登入google play下载app report

    流程 1 登入google play 登入google play需要三步 https play google com apps publish https accounts google com ServiceLogin hl 61 en