|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
<?php
|
|
|
|
|
namespace Base\Service;
|
|
|
|
|
|
|
|
|
|
use ZipArchive;
|
|
|
|
|
use Base\Model\PromoteModel;
|
|
|
|
|
use Base\Model\ApplyModel;
|
|
|
|
|
use Base\Tool\Base62;
|
|
|
|
@ -87,8 +88,8 @@ class GameSourceService {
|
|
|
|
|
'source_version' => $gameSource['source_version'],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$zip = new \ZipArchive();
|
|
|
|
|
if (!$zip->open($localPath, \ZipArchive::CREATE)) {
|
|
|
|
|
$zip = new ZipArchive();
|
|
|
|
|
if (!$zip->open($localPath, ZipArchive::CREATE)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -108,7 +109,7 @@ class GameSourceService {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 打入渠道信息文件
|
|
|
|
|
* @param string $zip 包文件
|
|
|
|
|
* @param ZipArchive $zip 包文件
|
|
|
|
|
* @param string $distFile 打入文件名
|
|
|
|
|
* @param array $packData 打入信息
|
|
|
|
|
* @return boolean 是否成功
|
|
|
|
@ -121,9 +122,9 @@ class GameSourceService {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 打入渠道信息目录(用于IOS,主要为了解决IOS13问题)
|
|
|
|
|
* @param string $zip 包文件
|
|
|
|
|
* @param string $distFolder 打入文件夹
|
|
|
|
|
* @return boolean 是否成功
|
|
|
|
|
* @param ZipArchive $zip 包文件
|
|
|
|
|
* @param string $distFolder 打入文件夹
|
|
|
|
|
* @return boolean 是否成功
|
|
|
|
|
*/
|
|
|
|
|
public function packChannelFolder($zip, $distFolder)
|
|
|
|
|
{
|
|
|
|
@ -159,6 +160,11 @@ class GameSourceService {
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->removeOlderFile($gameSource['plist_url']);
|
|
|
|
|
$this->removeOlderFile($gameSource['org_plist_url']);
|
|
|
|
|
$this->removeOlderFile($gameSource['file_url']);
|
|
|
|
|
$this->removeOlderFile($gameSource['original_url']);
|
|
|
|
|
|
|
|
|
|
$distFilePath = 'SourcePack/' . $gameSource['file_name'];
|
|
|
|
|
$result = $this->uploadPackage($localPath, $distFilePath);
|
|
|
|
|
$fileUrl = '';
|
|
|
|
@ -168,7 +174,7 @@ class GameSourceService {
|
|
|
|
|
} else {
|
|
|
|
|
return [
|
|
|
|
|
'status' => false,
|
|
|
|
|
'message' => '打包失败,上传OSS失败!' . $result['message'],
|
|
|
|
|
'message' => '打包失败,上传文件失败!' . $result['message'],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -219,6 +225,31 @@ class GameSourceService {
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function isRemoteFile(string $file)
|
|
|
|
|
{
|
|
|
|
|
if (strpos($file, 'http://') === 0 || strpos($file, 'https://')) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function removeOlderFile(string $file)
|
|
|
|
|
{
|
|
|
|
|
if (!$file) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ($this->isRemoteFile($file)) {
|
|
|
|
|
$urlInfo = parse_url($file);
|
|
|
|
|
$objectName = trim('/', $urlInfo['path']);
|
|
|
|
|
$this->deletePackage($objectName);
|
|
|
|
|
} else {
|
|
|
|
|
$olderPackage = ROOTTT . substr($file, 2);
|
|
|
|
|
if (file_exists($olderPackage)) {
|
|
|
|
|
unlink($olderPackage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 渠道打包
|
|
|
|
|
*/
|
|
|
|
@ -242,8 +273,13 @@ class GameSourceService {
|
|
|
|
|
M('apply_launch', 'tab_')->where(['apply_id' => $apply['id'], 'launch_packge'=>['in', [0, 2, 3]]])->save($launchData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->removeOlderFile($apply['pack_url']);
|
|
|
|
|
$this->removeOlderFile($apply['plist_url']);
|
|
|
|
|
|
|
|
|
|
$savePath = '';
|
|
|
|
|
$fileName = 'game_package' . $apply['game_id'] . '-' . $apply['promote_id'];
|
|
|
|
|
|
|
|
|
|
$fileName = substr(md5(microtime(true) . 'game_package' . $apply['game_id'] . '-' . $apply['promote_id']), 8 , 16);
|
|
|
|
|
|
|
|
|
|
if ($apply['sdk_version'] == 1) {
|
|
|
|
|
$fileName .= '.apk';
|
|
|
|
|
$savePath = 'Uploads/GamePack/' . $fileName;
|
|
|
|
@ -278,7 +314,7 @@ class GameSourceService {
|
|
|
|
|
} else {
|
|
|
|
|
return [
|
|
|
|
|
'status' => false,
|
|
|
|
|
'message' => '打包失败,上传OSS失败!' . $result['message'],
|
|
|
|
|
'message' => '打包失败,上传文件失败!' . $result['message'],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -349,6 +385,37 @@ class GameSourceService {
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function deletePackage($objectName)
|
|
|
|
|
{
|
|
|
|
|
$client = new Client([
|
|
|
|
|
'base_uri' => C('PACKAGE_CHUNK_URL'),
|
|
|
|
|
'timeout' => 30.0,
|
|
|
|
|
]);
|
|
|
|
|
try {
|
|
|
|
|
$response = $client->post('/delete', [
|
|
|
|
|
'verify' => false,
|
|
|
|
|
'form_params' => [
|
|
|
|
|
'file' => $objectName,
|
|
|
|
|
]
|
|
|
|
|
]);
|
|
|
|
|
$result = (string)$response->getBody();
|
|
|
|
|
$result = json_decode($result, true);
|
|
|
|
|
if (!$result) {
|
|
|
|
|
return [
|
|
|
|
|
'status' => false,
|
|
|
|
|
'message' => '请求异常',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
return [
|
|
|
|
|
'status' => false,
|
|
|
|
|
'message' => '请求异常: ' . $e->getMessage(),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function uploadPackageChunk($localFilePath, $distFilePath, $isDeleteLocal = false)
|
|
|
|
|
{
|
|
|
|
|
$client = new Client([
|
|
|
|
@ -449,17 +516,15 @@ class GameSourceService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$fileName = '';
|
|
|
|
|
$fileName = substr(md5($type . '_' . $gameId . '_' . $promoteId . '_' . $platformId . '_' . $position . '_' . microtime()), 8, 16);
|
|
|
|
|
if ($type == 'pack') {
|
|
|
|
|
if ($promoteId == 0) {
|
|
|
|
|
$fileName = 'Uploads/SourcePlist/'. $gameId . '.Plist';
|
|
|
|
|
} elseif ($platformId > 0) {
|
|
|
|
|
$fileName = 'Uploads/GamePlist/'. $gameId . '-' . $promoteId . '-' . $platformId . '-' .$position . '.Plist';
|
|
|
|
|
$fileName = 'Uploads/SourcePlist/'. $fileName . '.Plist';
|
|
|
|
|
} else {
|
|
|
|
|
$fileName = 'Uploads/GamePlist/'. $gameId . '-' . $promoteId . '.Plist';
|
|
|
|
|
$fileName = 'Uploads/GamePlist/'. $fileName . '.Plist';
|
|
|
|
|
}
|
|
|
|
|
} elseif ($type == 'org') {
|
|
|
|
|
$fileName = 'Uploads/OrgSourcePlist/'. $gameId . '.Plist';
|
|
|
|
|
$fileName = 'Uploads/OrgSourcePlist/'. $fileName . '.Plist';
|
|
|
|
|
}
|
|
|
|
|
$xml->save('./' . $fileName);
|
|
|
|
|
return [
|
|
|
|
|