php将apk从服务器下载链接,php脚本生成googleplayurl的下载链接,下载apk并自动反编译后获取android版本号...

需求:

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 ?> 本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉 本文系统来源:php中文网

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值