php解析ipa

  • 用composer安装两个库
    rodneyrehm/plist
    abbotton/ios-png-parser
  • tp6框架下的示例代码
 /**
     * @param $targetFile
     * @return mixed
     * @throws IOException
     * @throws PListException
     * @throws DOMException
     */
    public static function ipa($targetFile): mixed
    {
        //临时目录存放info.plist
        $storage_path = runtime_path() . 'ipa' . DS . time() . DS;
        $zip = new \ZipArchive();
        $zip->open($targetFile);
        $zip->extractTo($storage_path);
        $plist_index = $zip->locateName('Info.plist', \ZIPARCHIVE::FL_NOCASE | \ZIPARCHIVE::FL_NODIR);
        $plist_path = $zip->getNameIndex($plist_index);
        $zip->close();
        
        $plist_path = explode("/", $plist_path);
        //拼接logo的路径
        //todo logo名称如何改为变量
        $logo_path = $storage_path . $plist_path[0] . '/' . $plist_path[1] . '/[email protected]';
        // 拼接plist文件完整路
        $fp = $storage_path . $plist_path[0] . '/' . $plist_path[1] . '/Info.plist';
        // 获取plist文件内容
        $content = file_get_contents($fp);
        
        // 解析plist成数组
        $ipa = new CFPropertyList();
        $ipa->parse($content);
        $ipaInfo = $ipa->toArray();
        
        //包的大小(字节)
        $ipaInfo['PACKAGE_SIZE'] = filesize($targetFile);
        //解密logo并编码为base64
        $parser = new \IosPngParser\Parser();
        $decryptedPngFile = $storage_path . $plist_path[0] . '/' . $plist_path[1] . '/AppIcon40x40@2x_tmp.png';
        $parser::fix($logo_path, $decryptedPngFile);
        $ipaInfo['BASE64_LOGO'] = self::base64EncodeImage($decryptedPngFile);
        
        //删除刚才的临时文件(:小心删除系统:)
        exec('rm -rf ' . $storage_path);
        return $ipaInfo;
    }
    
    /**
     * @param $image_file
     * @return string
     * 图片转为base64编码
     */
    private static function base64EncodeImage($image_file): string
    {
        $image_info = getimagesize($image_file);
        $image_data = fread(fopen($image_file, 'r'), filesize($image_file));
        return 'data:' . $image_info['mime'] . ';base64,' . chunk_split(base64_encode($image_data));
    }

你可能感兴趣的:(php解析ipa)