APK实际上是压缩文件,PHP可以生成配置文件放入APK包,然后APK包第一次运行的时候读取配置文件的id,然后提交给PHP服务器。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
// 源文件
$apk = "gb.apk" ;
// 生成临时文件
$file = tempnam( "tmp" , "zip" );
// 复制文件
if (false=== file_put_contents ( $file , file_get_contents ( $apk ))){
exit ( 'copy faild!' );
}
// 打开临时文件
$zip = new ZipArchive();
$zip ->open( $file );
// 添加文件
// 由于apk限定只能修改此目录内的文件,否则会报无效apk包
$zip ->addFromString( 'META-INF/extends.json' , json_encode( array ( 'author' => 'deeka' )));
// 关闭zip
$zip ->close();
// 下载文件
header( "Content-Type: application/zip" );
header( "Content-Length: " . filesize ( $file ));
header( "Content-Disposition: attachment; filename=\" { $apk }\ "" );
// 输出二进制流
readfile( $file );
// 删除临时文件
unlink( $file );
|