DBMNG数据库管理与应用

独立思考能力,对于从事科学研究或其他任何工作,都是十分必要的。
当前位置:首页 > 移动应用 > Android

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

01 <?php
02 /*
03  * Created on 2012-5-21
04  * coolaj.cn
05  */
06  
07 // var_dump($id);
08  
09 function cocode() {
10  
11      foreach($_GET as $k=>$v){
12         $id = $k;
13         break;
14      }
15      if($_GET['u']){
16         $id=$_GET['u'];
17      }
18     if(is_numeric($id)){
19         return $id;
20     }elseif ($id && preg_match('/^U/', $id)) { 
21         $id = base64_decode(substr($id,1).'=')>>2;
22         return $id;
23     }
24 }
25  
26 $id = cocode();
27  
28 if(file_exists('bbshenqi'.$id.".apk") || empty($id)){
29     if(empty($id)){
30         header('Location: http://www.coolaj.cn/bbshenqi.apk');
31         exit;
32     }
33     header('Location: http://down.coolaj.cn/bbshenqi'.$id.'.apk');
34 }else{
35     $cc =file_get_contents("http://make.coolaj.cn/makeapk.php?apkname=".$id.'&r=简单加密');
36     if($cc == 'ok'){
37         if(file_exists('bbshenqi'.$id.".apk")){
38             echo '<meta http-equiv="content-type" content="text/html; charset=gbk" />';
39             echo '<a href="http://down.coolaj.cn/bbshenqi'.$id.'.apk">生成失败,点击重试</a>';
40             exit;
41         }
42         header('Location: http://down.coolaj.cn/bbshenqi'.$id.'.apk');
43     }
44  }
45  
46 ?>

7.makeapk.php

01 <?php
02 set_time_limit(0);
03 function zip($dir,$filename,$missfile=array(),$addfromString=array()){
04     if(!file_exists($dir) || !is_dir($dir)){
05         die(' can not exists dir '.$dir);
06     }
07     if(strtolower(end(explode('.',$filename))) != 'zip'){
08         die('only Support zip files');
09     }
10     $dir = str_replace('\\','/',$dir);
11     $filename = str_replace('\\','/',$filename);
12     if(file_exists($filename)){
13         die('the zip file '.$filename.' has exists !');
14     }
15     $files = array();
16     getfiles($dir,$files);
17     if(empty($files)){
18         die(' the dir is empty');
19     }
20  
21     $zip = new ZipArchive;
22     $res = $zip->open($filename, ZipArchive::CREATE);
23     if ($res === TRUE) {
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));
28             }
29         }
30         if(!empty($addfromString)){
31             foreach($addfromString as $v){
32                 $zip->addFromString($v[0],$v[1]);
33             }
34         }
35         $zip->close();
36         //echo 'unsigin apk ok!<br>';
37     } else {
38         echo 'failed';
39     }
40 }
41  
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);
46     }
47     $_files = scandir($dir);
48     foreach($_files as $v){
49         if($v != '.' && $v!='..'){
50             if(is_dir($dir.'/'.$v)){
51                 getfiles($dir.'/'.$v,$files);
52             }else{
53                 $files[] = $dir.'/'.$v;
54             }
55         }
56     }
57     return $files;
58 }
59  
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);
64 }
65  
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");
76     exec("gosign.bat");
77 }
78 if($_GET['apkname']){
79     $name = $_GET['apkname'];  
80     $r= $_GET['r'];
81     if($r=='yourpass'){
82         goapk($name);
83         echo 'ok';
84     }
85  
86 }
87 exit;
88  
89 ?>

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
4 del bbshenqi.apk

 

大功告成!

本站文章内容,部分来自于互联网,若侵犯了您的权益,请致邮件chuanghui423#sohu.com(请将#换为@)联系,我们会尽快核实后删除。
Copyright © 2006-2023 DBMNG.COM All Rights Reserved. Powered by DEVSOARTECH            豫ICP备11002312号-2

豫公网安备 41010502002439号