php指令碼產生google play url的下載連結,下載apk並自動反編譯後擷取android版本號碼

來源:互聯網
上載者:User
需求:

get the offer tracking link
follow the redirect to get google play url
Go to http://apps.evozi.com/apk-downloader/
Enter google play url
Download APK file
Decompile APK file using https://code.google.com/p/android-apktool/wiki/ApktoolOptions#Decompile_Options
Extract this file
[app name]/smali/com/kochava/android/tracker/Global.smali
Extract this line
.field public static final SDK_VERSION:Ljava/lang/String; = "Android20141023"
This output the Kochava SDK version numbe

指令碼的目的就是將上面的操作步驟自動化

運行指令碼之前必須在linux裡安裝apktool和java環境

操作示範:

上面輸入的是應用的包名字,你也可以輸入對應的google play url: https://play.google.com/store/apps/details?hl=en&id=com.priceline.android.negotiator

以下是代碼:

  1 $value){ 17              $value=str_replace(' ','',$value); 18              $t[$key]=$value; 19          } 20          $token_value=explode(":",$t[1]); 21          $t_value=$token_value[1]; 22          $dtrken=explode(":",$t[2]); 23          $patten="/var ".$dtrken[1]." = '(.+)';/";          24          preg_match($patten,$context,$daw); 25          $dtrken[1]=$daw[1]; 26          return array("t"=>$t_value,"dtrken"=>$dtrken); 27    } 28    function ajaxPost($packagename) { 29          $tk=getParameter(); 30          $t=$tk['t']; 31          $dtrken_key=$tk['dtrken'][0]; 32          $dtrken_value=$tk['dtrken'][1]; 33             $post_url='http://api.evozi.com/apk-downloader/download'; 34           $data = 'packagename='.$packagename.'&t='.$t.'&'.$dtrken_key.'='.$dtrken_value.'&fetch=false'; 35             $ch = curl_init(); 36             $headers = array('content-type: application/x-www-form-urlencoded;charset=UTF-8'); 37             curl_setopt($ch, CURLOPT_URL, $post_url); 38             curl_setopt($ch, CURLOPT_POSTFIELDS, $data);  39             curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 40             curl_setopt($ch, CURLOPT_POST, 1); 41             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 42             $results = curl_exec($ch); 43             curl_close($ch); 44             $results = json_decode($results); 45             return $results; 46         } 47         function getVersion($packagename){ 48               $version="/Android[0-9]+/"; 49               $path=$packagename."/smali/com/kochava/android/tracker"; 50               $filename1="Global.smali"; 51               $filename2="a.smali"; 52               if(is_dir($path)){ 53                     $file=scandir($path); 54                     foreach($file as $key=>$value){ 55                           $filename=$value; 56                           if(isset($filename)&file_exists($path."/".$filename)){ 57                                     $context=file_get_contents($path."/".$filename); 58                                     preg_match($version,$context,$v); 59                                     if(!empty($v)){ 60                                        $vs=$v[0];     61                                        break; 62                                     } 63                         } 64                     } 65                     if(isset($vs)){ 66                           $info=array("status"=>200,"description"=>"success detection in the file:".$filename,"version"=>$vs); 67                      }else{ 68                           $info=array("status"=>203,"description"=>"failure detection in all the .smal file:(".$file."),we can't find the android version number"); 69                      } 70               }else{ 71                    $info=array("status"=>201,"description"=>"there is no such directory:".$path); 72               } 73               $info=json_encode($info); 74               return $info; 75         } 76         function getFile($file_path,$file_name){ 77             exec("sudo wget -O $file_name $file_path"); 78         } 79         function deCompileApk($file_name){ 80                   print_r("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++start decompile apk,this may need a long time,please wait...++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++".PHP_EOL); 81                   exec("sudo apktool d $file_name"); 82                   print_r("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++decompile end++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++".PHP_EOL); 83         } 84         function delFile($packagename,$file_name){ 85                   exec("sudo rm -f $file_name"); 86                   exec("sudo rm -rf $packagename"); 87         } 88         $result=ajaxPost($packagename); 89         if($result->status=="success"){ 90              $file_name=$packagename."."."apk"; 91            $downloadUrl=$result->url; 92            $downloadUrl=preg_replace("/&/i", "\&", $downloadUrl); 93        getFile($downloadUrl,$file_name); 94        deCompileApk($file_name); 95        $info=getVersion($packagename); 96        delFile($packagename,$file_name); 97         }else{ 98              $tinfo=array("status"=>204,"description"=>"we can't generate Download Link from http://apps.evozi.com/apk-downloader/,please check your input of google play url or app package name!"); 99              $info=json_encode($tinfo);100         }101         print_r($info.PHP_EOL);102 ?>
  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.