Ejemplo n.º 1
0
 public function parse_ipa($path)
 {
     $full_path = UPLOAD_BASE . $path;
     $zip = new ZipArchive();
     if ($zip->open($full_path)) {
         $filename = '';
         for ($i = 0; $i < $zip->numFiles; $i++) {
             $name = $zip->getNameIndex($i);
             if (preg_match('/Payload\\/(.+)?\\.app\\/Info.plist$/i', $name)) {
                 $filename = $name;
                 break;
             }
         }
         if (!$filename) {
             $this->exit_with_error(20, '无法解析IPA文件', 406);
         }
         $plist = $zip->getFromName($filename);
         $tmp_path = '/tmp/' . $this->id . '.plist';
         // 写在临时文件夹里
         file_put_contents($tmp_path, $plist);
         $form = $this->parse_plist($tmp_path);
         $form['ad_size'] = Utils::format_file_size(filesize($full_path));
         // 从数据库读相同包名的广告来补充数据
         if ($form['pack_name']) {
             $ad_service = new AD();
             $info = $ad_service->get_ad_info_by_pack_name($form['pack_name'], ADModel::IOS);
             if ($info) {
                 $info = $this->addPrefixToAssets($info);
                 $form = array_merge($form, $info);
             }
         }
         return array('form' => $form);
     }
     return array('error' => '解压失败');
 }