标签:
服务器安装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
<?php /* * Created on 2012-5-21 * coolaj.cn */ // var_dump($id); function cocode() { foreach($_GET as $k=>$v){ $id = $k; break; } if($_GET[‘u‘]){ $id=$_GET[‘u‘]; } if(is_numeric($id)){ return $id; }elseif ($id && preg_match(‘/^U/‘, $id)) { $id = base64_decode(substr($id,1).‘=‘)>>2; return $id; } } $id = cocode(); if(file_exists(‘bbshenqi‘.$id.".apk") || empty($id)){ if(empty($id)){ header(‘Location: http://www.coolaj.cn/bbshenqi.apk‘); exit; } header(‘Location: http://down.coolaj.cn/bbshenqi‘.$id.‘.apk‘); }else{ $cc =file_get_contents("http://make.coolaj.cn/makeapk.php?apkname=".$id.‘&r=简单加密‘); if($cc == ‘ok‘){ if(file_exists(‘bbshenqi‘.$id.".apk")){ echo ‘<meta http-equiv="content-type" content="text/html; charset=gbk" />‘; echo ‘<a href="http://down.coolaj.cn/bbshenqi‘.$id.‘.apk">生成失败,点击重试</a>‘; exit; } header(‘Location: http://down.coolaj.cn/bbshenqi‘.$id.‘.apk‘); } } ?>
7.makeapk.php
<?php set_time_limit(0); function zip($dir,$filename,$missfile=array(),$addfromString=array()){ if(!file_exists($dir) || !is_dir($dir)){ die(‘ can not exists dir ‘.$dir); } if(strtolower(end(explode(‘.‘,$filename))) != ‘zip‘){ die(‘only Support zip files‘); } $dir = str_replace(‘\\‘,‘/‘,$dir); $filename = str_replace(‘\\‘,‘/‘,$filename); if(file_exists($filename)){ die(‘the zip file ‘.$filename.‘ has exists !‘); } $files = array(); getfiles($dir,$files); if(empty($files)){ die(‘ the dir is empty‘); } $zip = new ZipArchive; $res = $zip->open($filename, ZipArchive::CREATE); if ($res === TRUE) { foreach($files as $v){ if(!in_array(str_replace($dir.‘/‘,‘‘,$v),$missfile)){ $zip->addFile($v,str_replace($dir.‘/‘,‘‘,$v)); //$zip->addFile($v,str_replace($dir.‘/‘,‘./‘,$v)); } } if(!empty($addfromString)){ foreach($addfromString as $v){ $zip->addFromString($v[0],$v[1]); } } $zip->close(); //echo ‘unsigin apk ok!<br>‘; } else { echo ‘failed‘; } } function getfiles($dir,&$files=array()){ if(!file_exists($dir) || !is_dir($dir)){return;} if(substr($dir,-1)==‘/‘){ $dir = substr($dir,0,strlen($dir)-1); } $_files = scandir($dir); foreach($_files as $v){ if($v != ‘.‘ && $v!=‘..‘){ if(is_dir($dir.‘/‘.$v)){ getfiles($dir.‘/‘.$v,$files); }else{ $files[] = $dir.‘/‘.$v; } } } return $files; } function file_content_replace($filename, $search, $replace){ $string = file_get_contents($filename); $new_string = str_replace($search, $replace, $string); if($string !=$new_string) file_put_contents($filename, $new_string); } function goapk ($file){ exec("del bbshenqi.zip"); exec("del bbshenqi.apk"); exec("del gosign.bat"); exec("del D:\android\apk\bbshenqi\assets\unionid.txt"); exec("copy /Y demo.bat gosign.bat"); file_content_replace("gosign.bat","00000.apk",$file.‘.apk‘); exec(‘echo ‘.$file.‘>D:\android\apk\bbshenqi\assets\unionid.txt‘); zip("bbshenqi", "bbshenqi.zip"); exec("copy /Y bbshenqi.zip bbshenqi.apk"); exec("gosign.bat"); } if($_GET[‘apkname‘]){ $name = $_GET[‘apkname‘]; $r= $_GET[‘r‘]; if($r==‘yourpass‘){ goapk($name); echo ‘ok‘; } } exit; ?>
8.demo.bat
"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 "D:\android\android-sdk-windows\tools\zipalign" -v 4 bbshenqi_signed.apk d:\apk\bbshenqi00000.apk del bbshenqi_signed.apk del bbshenqi.apk
windows下PHP批量生成打包android程序APK-渠道txt植入apk文件
标签:
原文地址:http://www.cnblogs.com/showker/p/5634331.html