打包添加ios13兼容

master
ELF 5 years ago
parent 37ef999710
commit c3502c6120

@ -3,36 +3,55 @@ namespace Base\Service;
use Base\Model\PromoteModel;
use Base\Model\ApplyModel;
use Base\Tool\Base62;
class GameSourceService {
const IS_FIXED_IOS13 = true;
public function __construct()
{
}
/**
* 获取IPA中的.app后缀目录
*/
public function getIpaAppPath($ipaPath)
{
$appPath = '';
$zipGameSource = zip_open($ipaPath);
if ($zipGameSource) {
while ($zipEntry = zip_read($zipGameSource)) {
if (preg_match("/^Payload.*?\.app/", zip_entry_name($zipEntry), $matches)) {
$appPath = $matches[0];
break;
}
}
zip_close($zipGameSource);
}
return $appPath;
}
public function getChannelConfigFile($gameSource)
{
$configUrl = '';
if ($gameSource['sdk_version'] == 1) {
$configUrl = "META-INF/mch.properties";
} else {
$preUrl = '';
$zipGameSource = zip_open($this->getGameSourceUrl($gameSource));
if ($zipGameSource) {
while ($zipEntry = zip_read($zipGameSource)) {
if (preg_match("/^Payload.*?\.app/", zip_entry_name($zipEntry), $matches)) {
$preUrl = $matches[0];
break;
}
}
zip_close($zipGameSource);
}
$configUrl = $preUrl . '/_CodeSignature/TXChannel';
$appPath = $this->getIpaAppPath($this->getGameSourceUrl($gameSource));
$configUrl = $appPath . '/_CodeSignature/TXChannel';
}
return $configUrl;
}
public function getChannelConfigFolder($gameSource, array $packData)
{
$gameSourceUrl = $this->getGameSourceUrl($gameSource);
$appPath = $this->getIpaAppPath($this->getGameSourceUrl($gameSource));
return $appPath . '/' . Base62::encode($packData);
}
public function getGameSourceUrl($gameSource)
{
if (empty($gameSource)) {
@ -47,8 +66,36 @@ class GameSourceService {
$fileUrl = $path . $gameSource['file_name'];
return ROOTTT . ltrim($fileUrl, './');
}
public function packChannel($localPath, $game, $gameSource, $apply = null)
{
$packData = [
'game_id' => $game['id'],
'game_name' => $game['game_name'],
'game_appid' => $game['game_appid'],
'promote_id' => $apply ? $apply['promote_id'] : '',
'promote_account' => $apply ? $apply['promote_account'] : '自然渠道',
'source_version' => $gameSource['source_version'],
];
if (self::IS_FIXED_IOS13 && $game['sdk_version'] == 2) {
$channelFolder = $this->getChannelConfigFolder($gameSource, $packData);
return $this->packChannelFolder($localPath, $channelFolder);
} else {
$channelFile = $this->getChannelConfigFile($gameSource);
return $this->packChannelFile($localPath, $channelFile, $packData);
}
return false;
}
public function packChannelInfo($zipFile, $distFile, array $packData)
/**
* 打入渠道信息文件
* @param string $zipFile 包文件地址
* @param string $distFile 打入文件名
* @param array $packData 打入信息
* @return boolean 是否成功
*/
public function packChannelFile($zipFile, $distFile, array $packData)
{
$zip = new \ZipArchive();
if ($zip->open($zipFile, \ZipArchive::CREATE)) {
@ -59,6 +106,23 @@ class GameSourceService {
return false;
}
/**
* 打入渠道信息目录用于IOS主要为了解决IOS13问题
* @param string $zipFile 包文件地址
* @param string $distFolder 打入文件夹
* @return boolean 是否成功
*/
public function packChannelFolder($zipFile, $distFolder)
{
$zip = new \ZipArchive();
if ($zip->open($zipFile, \ZipArchive::CREATE)) {
$zip->addEmptyDir($distFolder);
$zip->close();
return true;
}
return false;
}
/**
* 原包打包
*/
@ -66,15 +130,6 @@ class GameSourceService {
{
$relativeUrl = $gameSource['file_url'];
$localPath = ROOTTT . ltrim($relativeUrl, './');
$packData = [
'game_id' => $game['id'],
'game_name' => $game['game_name'],
'game_appid' => $game['game_appid'],
'promote_id' => 0,
'promote_account' => '自然注册',
'source_version' => $gameSource['source_version'],
];
$originalUrl = '';
if ($game['sdk_version'] == 2) {
@ -83,8 +138,7 @@ class GameSourceService {
$originalUrl = $relativeUrl;
copy($oldLocalPath, $localPath);
}
$channelConfigFile = $this->getChannelConfigFile($gameSource);
$status = $this->packChannelInfo($localPath, $channelConfigFile, $packData);
$status = $this->packChannel($localPath, $game, $gameSource);
if (!$status) {
return [
'status' => false,
@ -179,18 +233,8 @@ class GameSourceService {
$relativePath = './' . $savePath;
$localPath = ROOTTT . $savePath;
copy($gameSourceUrl, $localPath);
$packData = [
'game_id' => $apply['game_id'],
'game_name' => $apply['game_name'],
'game_appid' => $game['game_appid'],
'promote_id' => $apply['promote_id'],
'promote_account' => $apply['promote_account'],
'source_version' => $gameSource['source_version'],
];
$channelConfigFile = $this->getChannelConfigFile($gameSource);
$status = $this->packChannelInfo($localPath, $channelConfigFile, $packData);
$status = $this->packChannel($localPath, $game, $gameSource, $apply);
if (!$status) {
return [
'status' => false,

Loading…
Cancel
Save