最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PHP實(shí)現(xiàn)自動(dòng)登入google play下載app report的方法

 更新時(shí)間:2014年09月23日 09:14:56   投稿:shichen2014  
這篇文章主要介紹了PHP實(shí)現(xiàn)自動(dòng)登入google play下載app report的方法,較為詳細(xì)的講述了登陸下載APP及對(duì)應(yīng)的實(shí)現(xiàn)代碼,具有不錯(cuò)的實(shí)用價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了PHP實(shí)現(xiàn)自動(dòng)登入google play下載app report的方法,有不錯(cuò)的實(shí)用價(jià)值。分享給大家供大家參考。具體實(shí)現(xiàn)步驟如下:

一、流程:

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

二、實(shí)現(xiàn)代碼如下:

<?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      結(jié)束日期
  * @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);
}
?>

相信本文所述對(duì)大家的PHP程序設(shè)計(jì)有一定的借鑒價(jià)值。

相關(guān)文章

  • PHP中限制IP段訪問、禁止IP提交表單的代碼

    PHP中限制IP段訪問、禁止IP提交表單的代碼

    最近,小編發(fā)現(xiàn)有一個(gè)云南的網(wǎng)友經(jīng)常在網(wǎng)站發(fā)表一些垃圾信息的評(píng)論,由于使用的事DEDECMS構(gòu)架,系統(tǒng)本身并無禁止IP功能,每天看到這些垃圾評(píng)論,盡管不多,但是讓人感覺不爽,那么如何來限制呢?
    2011-04-04
  • 解析PHP 5.5 新特性

    解析PHP 5.5 新特性

    本篇文章是對(duì)PHP 5.5 的新特性進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-07-07
  • 利用PHP內(nèi)置SERVER開啟web服務(wù)(本地開發(fā)使用)

    利用PHP內(nèi)置SERVER開啟web服務(wù)(本地開發(fā)使用)

    PHP 5.4.0起, CLI SAPI 提供了一個(gè)內(nèi)置的Web服務(wù)器,這個(gè)內(nèi)置的Web服務(wù)器主要用于本地開發(fā)使用,不可用于線上產(chǎn)品環(huán)境,URI請(qǐng)求會(huì)被發(fā)送到PHP所在的的工作目錄Working Directory進(jìn)行處理,除非你使用了-t參數(shù)來自定義不同的目錄
    2020-01-01
  • 老生常談PHP位運(yùn)算的用途

    老生常談PHP位運(yùn)算的用途

    下面小編就為大家?guī)硪黄仙U凱HP位運(yùn)算的用途。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-03-03
  • 淺談如何提高PHP代碼質(zhì)量之單元測(cè)試

    淺談如何提高PHP代碼質(zhì)量之單元測(cè)試

    最常見的測(cè)試軟件的方法可能是編寫單元測(cè)試。它們的目的是測(cè)試代碼的特定單元,基于這樣的假設(shè):一切都按預(yù)期運(yùn)行。為了能夠編寫適當(dāng)?shù)膯卧獪y(cè)試,我們的代碼應(yīng)該遵循一些基本的設(shè)計(jì)規(guī)則。我們應(yīng)該特別關(guān)注 SOLID 原則。
    2021-05-05
  • 深入extjs與php參數(shù)交互的詳解

    深入extjs與php參數(shù)交互的詳解

    本篇文章是對(duì)extjs與php的參數(shù)交互進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-06-06
  • php模擬用戶自動(dòng)在qq空間發(fā)表文章的方法

    php模擬用戶自動(dòng)在qq空間發(fā)表文章的方法

    這篇文章主要介紹了php模擬用戶自動(dòng)在qq空間發(fā)表文章的方法,可實(shí)現(xiàn)模擬用戶提交表單發(fā)布文章的功能,代碼中包含有較為詳盡的注釋便于理解,需要的朋友可以參考下
    2015-01-01
  • 在WINDOWS中設(shè)置計(jì)劃任務(wù)執(zhí)行PHP文件的方法

    在WINDOWS中設(shè)置計(jì)劃任務(wù)執(zhí)行PHP文件的方法

    在網(wǎng)上找了些WINDOWS執(zhí)行PHP的計(jì)劃任務(wù)的方法,有一個(gè)寫得很全,可惜在我這竟然沒通過。最后不得不綜合各門派的方法,才能在我這運(yùn)行成功
    2011-12-12
  • php調(diào)用mysql存儲(chǔ)過程

    php調(diào)用mysql存儲(chǔ)過程

    php調(diào)用mysql存儲(chǔ)過程...
    2007-02-02
  • php新浪微博登錄接口用法實(shí)例

    php新浪微博登錄接口用法實(shí)例

    這篇文章主要介紹了php新浪微博登錄接口用法,以實(shí)例形式分析了新浪微博接口的申請(qǐng)與具體使用技巧,具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2014-12-12

最新評(píng)論

黑龙江省| 五大连池市| 克山县| 江山市| 龙口市| 雅江县| 苏尼特左旗| 卢氏县| 紫金县| 毕节市| 星座| 高州市| 巴彦县| 常山县| 清水县| 上栗县| 胶州市| 霍邱县| 焦作市| 通江县| 红河县| 淅川县| 黔南| 新绛县| 芦山县| 云阳县| 怀柔区| 泸定县| 海兴县| 金沙县| 绥芬河市| 巴马| 盐津县| 宁化县| 巴彦县| 定边县| 台前县| 云南省| 安达市| 赤水市| 博野县|