windows下PHP批量生成(自动)打包android程序APK
			
	服务器安装php环境
	下载 android-sdk-windows  下载JDK
	1.打开zip支持 c:/windows/php.ini ,打开 exec
	2.apk 支持
mime添加 .apk application/vnd.android.package-archive
	3.安装javaSDK(要和android的编辑版本一致)
	4.编辑IIS绑定权限(www:www) ,目录没有权限会导致生成失败
	5.配置两个虚拟主机
	A:down.coolaj.cn  用于下载
	B:make.cookaj.cn  用于制作签名
	6. down的index.php
	
		
		
		
			
				
					
						| 
							03
						 | 
						
							 * Created on 2012-5-21
						 | 
					
				
			
		 
		
		
		
		
		
		
		
		
			
				
					
						| 
							11
						 | 
						
							     foreach($_GET as $k=>$v){
						 | 
					
				
			
		 
		
		
		
		
		
		
		
		
		
			
				
					
						| 
							20
						 | 
						
							    }elseif ($id && preg_match('/^U/', $id)) { 
						 | 
					
				
			
		 
		
			
				
					
						| 
							21
						 | 
						
							        $id = base64_decode(substr($id,1).'=')>>2;
						 | 
					
				
			
		 
		
		
		
		
		
		
		
			
				
					
						| 
							28
						 | 
						
							if(file_exists('bbshenqi'.$id.".apk") || empty($id)){
						 | 
					
				
			
		 
		
		
		
		
		
		
		
		
		
			
				
					
						| 
							37
						 | 
						
							        if(file_exists('bbshenqi'.$id.".apk")){
						 | 
					
				
			
		 
		
			
				
					
						| 
							38
						 | 
						
							            echo '<meta http-equiv="content-type" content="text/html; charset=gbk" />';
						 | 
					
				
			
		 
		
		
		
		
		
		
		
		
	 
 
	
	7.makeapk.php
	
		
		
		
			
				
					
						| 
							03
						 | 
						
							function zip($dir,$filename,$missfile=array(),$addfromString=array()){
						 | 
					
				
			
		 
		
			
				
					
						| 
							04
						 | 
						
							    if(!file_exists($dir) || !is_dir($dir)){
						 | 
					
				
			
		 
		
			
				
					
						| 
							05
						 | 
						
							        die(' can not exists dir '.$dir);
						 | 
					
				
			
		 
		
		
			
				
					
						| 
							07
						 | 
						
							    if(strtolower(end(explode('.',$filename))) != 'zip'){
						 | 
					
				
			
		 
		
			
				
					
						| 
							08
						 | 
						
							        die('only Support zip files');
						 | 
					
				
			
		 
		
		
			
				
					
						| 
							10
						 | 
						
							    $dir = str_replace('\\','/',$dir);
						 | 
					
				
			
		 
		
			
				
					
						| 
							11
						 | 
						
							    $filename = str_replace('\\','/',$filename);
						 | 
					
				
			
		 
		
			
				
					
						| 
							12
						 | 
						
							    if(file_exists($filename)){
						 | 
					
				
			
		 
		
			
				
					
						| 
							13
						 | 
						
							        die('the zip file '.$filename.' has exists !');
						 | 
					
				
			
		 
		
		
		
			
				
					
						| 
							16
						 | 
						
							    getfiles($dir,$files);
						 | 
					
				
			
		 
		
		
			
				
					
						| 
							18
						 | 
						
							        die(' the dir is empty');
						 | 
					
				
			
		 
		
		
		
			
				
					
						| 
							21
						 | 
						
							    $zip = new ZipArchive;
						 | 
					
				
			
		 
		
			
				
					
						| 
							22
						 | 
						
							    $res = $zip->open($filename, ZipArchive::CREATE);
						 | 
					
				
			
		 
		
		
			
				
					
						| 
							24
						 | 
						
							        foreach($files as $v){
						 | 
					
				
			
		 
		
			
				
					
						| 
							25
						 | 
						
							            if(!in_array(str_replace($dir.'/','',$v),$missfile)){
						 | 
					
				
			
		 
		
			
				
					
						| 
							26
						 | 
						
							                $zip->addFile($v,str_replace($dir.'/','',$v));
						 | 
					
				
			
		 
		
			
				
					
						| 
							27
						 | 
						
							                //$zip->addFile($v,str_replace($dir.'/','./',$v));
						 | 
					
				
			
		 
		
		
		
			
				
					
						| 
							30
						 | 
						
							        if(!empty($addfromString)){
						 | 
					
				
			
		 
		
			
				
					
						| 
							31
						 | 
						
							            foreach($addfromString as $v){
						 | 
					
				
			
		 
		
			
				
					
						| 
							32
						 | 
						
							                $zip->addFromString($v[0],$v[1]);
						 | 
					
				
			
		 
		
		
		
		
			
				
					
						| 
							36
						 | 
						
							        //echo 'unsigin apk ok!<br>';
						 | 
					
				
			
		 
		
		
		
		
		
		
			
				
					
						| 
							42
						 | 
						
							function getfiles($dir,&$files=array()){
						 | 
					
				
			
		 
		
			
				
					
						| 
							43
						 | 
						
							    if(!file_exists($dir) || !is_dir($dir)){return;}
						 | 
					
				
			
		 
		
			
				
					
						| 
							44
						 | 
						
							    if(substr($dir,-1)=='/'){
						 | 
					
				
			
		 
		
			
				
					
						| 
							45
						 | 
						
							        $dir = substr($dir,0,strlen($dir)-1);
						 | 
					
				
			
		 
		
		
			
				
					
						| 
							47
						 | 
						
							    $_files = scandir($dir);
						 | 
					
				
			
		 
		
			
				
					
						| 
							48
						 | 
						
							    foreach($_files as $v){
						 | 
					
				
			
		 
		
			
				
					
						| 
							49
						 | 
						
							        if($v != '.' && $v!='..'){
						 | 
					
				
			
		 
		
			
				
					
						| 
							50
						 | 
						
							            if(is_dir($dir.'/'.$v)){
						 | 
					
				
			
		 
		
			
				
					
						| 
							51
						 | 
						
							                getfiles($dir.'/'.$v,$files);
						 | 
					
				
			
		 
		
		
			
				
					
						| 
							53
						 | 
						
							                $files[] = $dir.'/'.$v;
						 | 
					
				
			
		 
		
		
		
		
		
		
		
			
				
					
						| 
							60
						 | 
						
							function file_content_replace($filename, $search, $replace){
						 | 
					
				
			
		 
		
			
				
					
						| 
							61
						 | 
						
							    $string = file_get_contents($filename);
						 | 
					
				
			
		 
		
			
				
					
						| 
							62
						 | 
						
							    $new_string = str_replace($search, $replace, $string);
						 | 
					
				
			
		 
		
			
				
					
						| 
							63
						 | 
						
							    if($string !=$new_string) file_put_contents($filename, $new_string);
						 | 
					
				
			
		 
		
		
		
			
				
					
						| 
							66
						 | 
						
							function goapk ($file){
						 | 
					
				
			
		 
		
			
				
					
						| 
							67
						 | 
						
							    exec("del bbshenqi.zip");
						 | 
					
				
			
		 
		
			
				
					
						| 
							68
						 | 
						
							    exec("del bbshenqi.apk");
						 | 
					
				
			
		 
		
			
				
					
						| 
							69
						 | 
						
							    exec("del gosign.bat");
						 | 
					
				
			
		 
		
			
				
					
						| 
							70
						 | 
						
							    exec("del D:\android\apk\bbshenqi\assets\unionid.txt");
						 | 
					
				
			
		 
		
			
				
					
						| 
							71
						 | 
						
							    exec("copy /Y demo.bat gosign.bat");
						 | 
					
				
			
		 
		
			
				
					
						| 
							72
						 | 
						
							    file_content_replace("gosign.bat","00000.apk",$file.'.apk');
						 | 
					
				
			
		 
		
			
				
					
						| 
							73
						 | 
						
							    exec('echo '.$file.'>D:\android\apk\bbshenqi\assets\unionid.txt');
						 | 
					
				
			
		 
		
			
				
					
						| 
							74
						 | 
						
							    zip("bbshenqi", "bbshenqi.zip");
						 | 
					
				
			
		 
		
			
				
					
						| 
							75
						 | 
						
							    exec("copy /Y bbshenqi.zip bbshenqi.apk");
						 | 
					
				
			
		 
		
		
		
		
			
				
					
						| 
							79
						 | 
						
							    $name = $_GET['apkname'];  
						 | 
					
				
			
		 
		
		
		
		
		
		
		
		
		
		
	 
 
	8.demo.bat
	
		
			
				
					
						| 
							1
						 | 
						
							"C:/Program Files/Java/jdk1.6.0_45/bin/jarsigner" -verbose -keystore key.keystore -storepass yourpass -storetype jks -sigfile CERT -signedjar bbshenqi_signed.apk bbshenqi.apk key.keystore
						 | 
					
				
			
		 
		
			
				
					
						| 
							2
						 | 
						
							"D:\android\android-sdk-windows\tools\zipalign" -v 4 bbshenqi_signed.apk d:\apk\bbshenqi00000.apk
						 | 
					
				
			
		 
		
			
				
					
						| 
							3
						 | 
						
							del bbshenqi_signed.apk
						 | 
					
				
			
		 
		
	 
 
	 
	大功告成!