1.获取apk
/*
获取zip文件中的apk文件
$zip_path zip路径
*/
function get_apk_path($zip_path){
$zip = new \ZipArchive;
if ($zip->open($zip_path) === true) {
$num = $zip->numFiles;
for($i = 0; $i < $num; $i++) {
$apk_name = $zip->getNameIndex($i);
$apk_info = pathinfo($apk_name);
$exts = strtolower($apk_info["extension"]);
if($exts == 'apk'){
$apk_path_file = C('UPLOAD_PATH').'apk/';
$res = $zip->extractTo($apk_path_file, array($apk_name));
if($res){
$zip->close();
if($filename = getUploadsDir('apk')){
$save_name = uniqid();
//获取后缀
$apk_path = $filename.'/'.$save_name.'.'.$exts;
if(copy($apk_path_file.$apk_name, $apk_path_file.$apk_path)){
return $apk_path;
}
}
}else{
return false;
}
}
}
$zip->close();
}
return false;
}
2.利用ApkParser类获取apk基本信息
/*
解析apk并获取信息
$apk_path apk路径
*/
function apk_parser($apk_path){
<span style="white-space:pre"> </span>Vendor('Apk.ApkParser');
<span style="white-space:pre"> </span>$appObj = new \ApkParser();
<span style="white-space:pre"> </span>//apk所在的路径地址
<span style="white-space:pre"> </span>$res = $appObj->open($apk_path);
<span style="white-space:pre"> </span>$data['app_name']=$appObj->getAppName(); // 应用名称
<span style="white-space:pre"> </span>$data['package_name']=$appObj->getPackage(); // 应用包名
<span style="white-space:pre"> </span>$data['version_name']=$appObj->getVersionName(); // 版本名称
<span style="white-space:pre"> </span>$data['version_code']=$appObj->getVersionCode(); // 版本代码
<span style="white-space:pre"> </span>return $data;
}