打包优化

master
ELF 5 years ago
parent 7d018b47af
commit 69a6f9612f

@ -48,10 +48,10 @@ class AutoPackController extends Think
}
$this->checkPackageStatus();
$this->app_package();//app渠道自动打包
// $this->app_package();//app渠道自动打包
$this->channel();
$this->launch_package(false);
$this->leak_detection();
// $this->launch_package(false);
// $this->leak_detection();
}
/**
@ -74,12 +74,10 @@ class AutoPackController extends Think
->where('1=1')
->group('l.id')
->select();
if(!empty($launchGameIds)) {
if(!empty($launchGameIds)) {
$ids = array_column($launchGameIds, 'id');
$launchModel->where(['id'=>['in',$ids]])->setField('launch_packge', 2);
}
$launchIds = $launchModel
@ -92,18 +90,18 @@ class AutoPackController extends Think
->group('apply_id')
->select();
$launchId='';
$launchId = [];
foreach ($launchIds as $launchValue) {
foreach ($launchAllIds as $launchAllValue) {
if($launchValue['apply_id'] == $launchAllValue['apply_id']
&& $launchValue['count'] == $launchAllValue['count']) {
$launchId[]=$launchValue['apply_id'];
$launchId[] = $launchValue['apply_id'];
}
}
}
if(!empty($launchId)) {
$applyModel->where(['id'=>['in',$launchId]])->setField('enable_status', 1);
$applyModel->where(['id'=> ['in',$launchId]])->setField('enable_status', 1);
}
}
@ -292,14 +290,6 @@ class AutoPackController extends Think
/**
* 渠道游戏打包
*
* 针对每个申请游戏检测是否存在投放申请:有则更改投放申请状态,使其进入准备打包状态;无则进行渠道游戏打包
*
* @author: 鹿文学[lwx]<fyj301415926@126.com>
* @since: 2019\4\17 0017 14:27
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
private function channel() {
$zip = new \ZipArchive();
@ -311,140 +301,32 @@ class AutoPackController extends Think
$gameSourceModel = M('Game_source', 'tab_');
$launchModel = M('apply_launch', 'tab_');
$apply_data = $applyModel
-> field('id,game_id,game_name,promote_id,promote_account,sdk_version')
-> where($map)
-> order('bale_sort desc,id desc')
-> limit(200)
-> select();
if (!empty($apply_data)) {
foreach ($apply_data as $key => $value) {
$game_so = $gameSourceModel
-> field('id,file_name,source_version')
-> where(['game_id' => $value['game_id']])
-> find();
if (!file_exists(get_game_source_file_url($value['game_id'])) || null == $game_so) {
$applyModel -> where(['id' => $value['id']]) -> setField('enable_status', -1);
continue;
}
/* 检测是否存在投放申请,存在则更改投放申请信息,否则进行渠道打包 */
$launchCount = $launchModel->where(['apply_id'=>$value['id']])->count();
if($launchCount>0) {
$applyModel->where(['id' => $value['id']]) -> setField('enable_status', 3);
$launchModel->where(['apply_id'=>$value['id'], 'launch_packge'=>['in',[0,2,3]]])->save(['launch_packge'=>2,'launch_down_url'=>'','launch_plist_url'=>'']);
} else {
$applyModel -> where(['id' => $value['id']]) -> setField('enable_status', 3);
if ($value['sdk_version'] == 1) {
$str_ver = ".apk";
$file_name = "GamePack";
$url_ver = "META-INF/mch.properties";
} else {
$zip_open_game_source = zip_open(get_game_source_file_url($value['game_id']));
if ($zip_open_game_source) {
while ($zip_entry = zip_read($zip_open_game_source)) {
if (preg_match("/.app/", zip_entry_name($zip_entry))) {
$ios_app = substr(zip_entry_name($zip_entry), 8) . "<br/>";
}
$new_ios_1 = explode("/", $ios_app);
}
zip_close($zip_open_game_source);
}
$str_ver = ".ipa";
$file_name = "IosGamePack";
$url_ver = "Payload/" . $new_ios_1[0] . "/_CodeSignature/TXChannel";
}
$new_name = "game_package" . $value['game_id'] . "-" . $value['promote_id'] . $str_ver;
$to = "./Uploads/" . $file_name . "/" . $new_name;
$localPath = ROOTTT . ltrim($to, './');
copy(get_game_source_file_url($value['game_id']), $localPath);
$zip_res = $zip -> open(ROOTTT . ltrim($to, './'), \ZipArchive::CREATE);
if ($zip_res == true) {
#打包数据
$pack_data = array(
"game_id" => $value["game_id"],
"game_name" => $value['game_name'],
"game_appid" => get_game_appid($value["game_id"], "id"),
"promote_id" => $value['promote_id'],
"promote_account" => $value['promote_account'],
"source_version" => $game_so['source_version'],
);
$zip -> addFromString($url_ver, json_encode($pack_data));
$zip -> close();
$newname = "game_package" . $value["game_id"] . "-" . $value['promote_id'] . $str_ver;
if (get_tool_status("oss_storage") == 1) {
if (C("oss_storage.is_cname")) {
$to = "http://" . C("oss_storage.domain") . "/" . str_replace("IosGamePack", "GamePack", $file_name) . "/" . $newname;
} else {
$to = "https://" . C("oss_storage.bucket") . "." . C("oss_storage.domain") . "/" . str_replace("IosGamePack", "GamePack", $file_name) . "/" . $newname;
$to = str_replace('-internal', '', $to);
}
if (!empty(C('oss_storage.bd_domain')) && strlen(C('oss_storage.bd_domain')) > 5) {
$to = C('oss_storage.bd_domain') . "/GamePack/" . $newname;
}
$new_to = ROOTTT . "Uploads/" . $file_name . "/" . $newname;
$updata['savename'] = $newname;
$updata['path'] = $new_to;
$this -> upload_game_pak_oss($updata);
if (file_exists($new_to)) {
@unlink($new_to);
}
} elseif (get_tool_status("qiniu_storage") == 1) {
$this -> dleteQiNiuFile($newname);
$url = $this -> upQiNiuFile($newname, ROOTTT . ltrim($to, './'));
if (empty($url)) {
$this -> error('七牛错误,请检查七牛配置,并确保七牛空间权限正确!');
}
@unlink(ROOTTT . ltrim($to, './'));
$to = "http://" . $url;
} elseif (get_tool_status("cos_storage") == 1) {
$new_to = ROOTTT . "Uploads/" . $file_name . "/" . $newname;
$updata['path'] = $new_to;
$updata['savename'] = 'GamePack/'. $newname;
$to = $this->upload_cos($updata);
} elseif (get_tool_status("bos_storage") == 1) {
$newname = "game_package" . $value["game_id"] . "-" . $value['promote_id'] . $str_ver;
$to = "http://" . C("bos_storage.bucket") . "." . C("bos_storage.domain") . "/" . $file_name . "/" . $newname;
$to = str_replace('-internal', '', $to);
$new_to = ROOTTT . "Uploads/" . $file_name . "/" . $newname;
$updata['savename'] = $newname;
$updata['path'] = $new_to;
$this -> upload_bos($updata);
}
$promote = array('game_id' => $value['game_id'], 'promote_id' => $value['promote_id']);
$plist_url = '';
if ($value['sdk_version'] == 2) {
$plist_url = $this -> create_plist($promote['game_id'], $promote['promote_id'], get_payload_name($value['game_id']), $to);
}
$jieguo = $this -> updateinfo($value['id'], $to, $promote, $plist_url);
}
}
$applys = $applyModel
->field('id,game_id,game_name,promote_id,promote_account,sdk_version')
->where($map)
->order('bale_sort desc,id desc')
->limit(200)
->select();
$gameIds = array_unique(array_column($applys, 'game_id'));
$games = M('game', 'tab_')->field(['id', 'game_appid'])->where(['id' => ['in', $gameIds]])->find();
$games = index_by_column('id', $games);
$launchCountList = $launchModel->field(['apply_id', 'count(*) count'])->where(['apply_id' => ['in', $applyIds]])->group('apply_id')->select();
$launchCountList = index_by_column('apply_id', $launchCountList);
$gameSources = M('game_source', 'tab_')->field(['id', 'file_name', 'source_version', 'file_type', 'bao_name'])->where(['id' => ['game_id', $gameIds]])->find();
$gameSources = index_by_column('game_id', $gameSources);
$gameSourceService = new GameSourceService();
if (!empty($applys)) {
foreach ($applys as $apply) {
$gameSource = $gameSources[$apply['game_id']] ?? null;
$game = $games[$apply['game_id']]['game_appid'];
$launchCount = $launchCountList[$apply['id']] ?? 0;
$gameSourceService->channelPack($gameSource, $game, $apply, $launchCount);
}
}
}
@ -456,21 +338,26 @@ class AutoPackController extends Think
$map['a.status'] = 1;
$map['a.enable_status'] = 1;
$map['al.launch_packge'] = array('in', [0, 2, 3]);
$apply = $applymodel -> alias('a')
-> field('a.id,a.game_id,a.game_name,a.promote_account,a.pack_url,a.plist_url,a.promote_id,a.sdk_version,a.enable_status')
-> join('tab_apply_launch as al on (al.apply_id=a.id) ')
-> where($map) -> limit(3) -> group('a.id') -> select();
$apply = $applymodel->alias('a')
->field('a.id,a.game_id,a.game_name,a.promote_account,a.pack_url,a.plist_url,a.promote_id,a.sdk_version,a.enable_status')
->join('tab_apply_launch as al on (al.apply_id=a.id) ')
->where($map)
->limit(300)
->group('a.id')
->select();
foreach ($apply as $key => $value) {
$game_so = $game_somodel -> field('id,file_name,source_version') -> where(['game_id' => $value['game_id']]) -> find();
if (!file_exists(get_game_source_file_url($value['game_id'])) || null == $game_so) {
$gameSource = $gameSourceModel
->field('id,file_name,source_version,file_type')
->where(['game_id' => $value['game_id']])
->find();
$gameSourceUrl = $gameSourceService->getGameSourceUrl($gameSource);
if ($gameSource || !file_exists($gameSourceUrl)) {
M('apply', 'tab_') -> where(['id' => $value['id']]) -> setField('enable_status', -1);
$launchmodel -> where(['apply_id' => $value['id']]) -> setField('launch_packge', 0);
continue;
}
$url = get_game_source_file_url($value['game_id']);
if (!empty($url) && is_file($url)) {
if (!empty($gameSourceUrl) && is_file($gameSourceUrl)) {
$launch = $launchmodel -> where(['apply_id' => $value['id'], 'launch_packge' => array('in', [0, 2, 3])]) -> select();
$zip = new \ZipArchive();
@ -478,19 +365,19 @@ class AutoPackController extends Think
if ($value['sdk_version'] == 1) {
if (!empty($v['game_source_filename'])) {
if ($v['game_source_filename'] == $game_so['file_name']) {
if ($v['game_source_filename'] == $gameSource['file_name']) {
if (!empty($v['launch_down_url'])) {
$launchmodel -> where(['id' => $v['id']]) -> setField(['launch_packge' => 1]);
continue;
}
}
}
$str_ver = ".apk";
$str_ver = '.apk';
$file_name = "GamePack";
$url_ver = "META-INF/mch.properties";
} else {
if (!empty($v['game_source_filename'])) {
if ($v['game_source_filename'] == $game_so['file_name']) {
if ($v['game_source_filename'] == $gameSource['file_name']) {
if (!empty($v['launch_plist_url'])) {
if (!empty($v['launch_down_url'])) {
$launchmodel -> where(['id' => $v['id']]) -> setField(['launch_packge' => 1]);
@ -499,7 +386,7 @@ class AutoPackController extends Think
}
}
}
$zip_open_game_source = zip_open($url);
$zip_open_game_source = zip_open($gameSourceUrl);
if ($zip_open_game_source) {
while ($zip_entry = zip_read($zip_open_game_source)) {
if (preg_match("/.app/", zip_entry_name($zip_entry))) {
@ -516,7 +403,7 @@ class AutoPackController extends Think
}
$new_name = "game_package" . $value['game_id'] . "-" . $value['promote_id'] . "-" . $v['platform_id'] . "-" . $v['position'] . $str_ver;
$to = "./Uploads/" . $file_name . "/" . $new_name;
copy($url, ROOTTT . ltrim($to, './'));
copy($gameSourceUrl, ROOTTT . ltrim($to, './'));
$zip_res = $zip -> open(ROOTTT . ltrim($to, './'), \ZipArchive::CREATE);
if ($zip_res == true) {
#打包数据
@ -526,7 +413,7 @@ class AutoPackController extends Think
"game_appid" => get_game_appid($value["game_id"], "id"),
"promote_id" => $value['promote_id'],
"promote_account" => $value['promote_account'],
"source_version" => $game_so['source_version'],
"source_version" => $gameSource['source_version'],
'launch_id' => $v['platform_id'],
'position' => $v['position'],
);
@ -595,7 +482,7 @@ class AutoPackController extends Think
if ($value['sdk_version'] == 2) {
$plist_url = $this -> create_plist($promote['game_id'], $promote['promote_id'], get_payload_name($value['game_id']), $to, $v['platform_id'], $v['position']);
}
$jg = $this -> update_launch_info(['platform_id' => $v['platform_id'], 'apply_id' => $value['id'], 'position'=>$v['position']], $to, $plist_url, $game_so['file_name']);
$jg = $this -> update_launch_info(['platform_id' => $v['platform_id'], 'apply_id' => $value['id'], 'position'=>$v['position']], $to, $plist_url, $gameSource['file_name']);
}
@ -643,7 +530,7 @@ class AutoPackController extends Think
{
$map['status'] = 1;
$map['enable_status'] = 2;
$arr_id = M('app_apply', 'tab_') -> field('id') -> where($map) -> order('id desc') -> limit(3) -> select();
$arr_id = M('app_apply', 'tab_')->field('id')->where($map)->order('id desc')->limit(300)->select();
if (empty($arr_id)) {
return false;
}
@ -722,8 +609,6 @@ class AutoPackController extends Think
$apply_data['dow_url'] = $to;
$apply_data['enable_status'] = 1;
M('app_apply', 'tab_') -> save($apply_data);
}
}
@ -736,7 +621,7 @@ class AutoPackController extends Think
*/
public function updateinfo($id, $pack_url, $promote, $plist_url)
{
$model = M('Apply', "tab_");
$data = [];
$data['id'] = $id;
$data['pack_url'] = $pack_url;
$data['dow_url'] = '/index.php?s=/Home/Down/down_file/game_id/' . $promote['game_id'] . '/promote_id/' . $promote['promote_id'];
@ -745,7 +630,7 @@ class AutoPackController extends Think
$data['dispose_id'] = UID;
$data['dispose_time'] = NOW_TIME;
$data['plist_url'] = $plist_url;
$res = $model -> save($data);
$res = M('Apply', 'tab_')->save($data);
return $res;
}

@ -9,6 +9,7 @@
namespace Admin\Event;
use Think\Controller;
use Base\Service\GameSourceService;
/**
* 后台首页控制器
@ -20,17 +21,8 @@ class SourceEvent extends Controller
public function add_source()
{
$model = D('Game_source');
$plist = A("Plist");
$data = $_REQUEST;
$data['file_size'] = round($data['file_size'] / pow(1024, 2), 2) . "MB";
/*if ($data['file_type'] == 2) {
if (preg_match("/.ipa/", $data['file_name'])) {
//copy($data['file_url'] . "/" . $data['file_name'], "./Uploads/Ios/original/" . $data['file_name']);
//@unlink($data['file_url'] . "/" . $data['file_name']);
//$data['file_url'] = "./Uploads/Ios/original";
}
}*/
$data['file_url'] = $data['file_url'] . "/" . $data['file_name'];
$data['sdk_version'] = $data['file_type'];
$data['op_id'] = UID;
@ -39,19 +31,27 @@ class SourceEvent extends Controller
$data['create_time'] = NOW_TIME;
$remark = str_replace(array("\r\n", "\r", "\n"), "@@@", $_POST['remark']);
$data['remark'] = json_encode(explode('@@@', $remark));
if ($data['file_type'] == 2) {
$data['plist_url'] = "./Uploads/SourcePlist/" . $data['game_id'] . ".Plist";
$data['org_plist_url'] = "./Uploads/OrgSourcePlist/" . $data['game_id'] . ".Plist";
$plist -> create_plist($data['game_id'], 0, $data['bao_name'], $data['file_url']);
$data['source_version'] = 0;
$game = M('game', 'tab_')->where(['id' => $data['game_id']])->find();
$gameSourceService = new GameSourceService();
$result = $gameSourceService->sourcePack($data, $game);
var_dump($result);
if (!$result['status']) {
var_dump($result);die();
$this->error('添加失败' , U('GameSource/lists', ['type' => $data['type']]));
}
$res = $model -> add($data);
if ($res) {
$data['plist_url'] = $result['data']['plistUrl'];
$data['org_plist_url'] = $result['data']['orgPlistUrl'];
$data['file_url'] = $result['data']['fileUrl'];
$data['original_url'] = $result['data']['originalUrl'];
if (M('game_source', 'tab_')->add($data)) {
//原包打包
$this -> soure_pack($data['game_id'], $data['file_url'], $data['file_type'], 1, $data['bao_name']);
$this -> update_game_size($data);
$this -> success('添加成功', U('GameSource/lists', array('type' => $data['type'])));
$this->update_game_size($data);
var_dump('success');die();
$this->success('添加成功', U('GameSource/lists', ['type' => $data['type']]));
} else {
$this -> error('添加失败', U('GameSource/lists', array('type' => $data['type'])));
var_dump('error');die();
$this->error('添加失败', U('GameSource/lists', ['type' => $data['type']]));
}
}
@ -65,23 +65,8 @@ class SourceEvent extends Controller
$plist = A("Plist");
$data = $_REQUEST;
$url = $data['file_url'];
$urll = $data['file_url2'];
/*if ($data['file_type'] == 2) {
if (preg_match("/.ipa/", $data['file_name']) && ($data['file_name'] != $file_name)) {
//copy($data['file_url'] . "/" . $data['file_name'], "./Uploads/Ios/original/" . $data['file_name']);
//@unlink($data['file_url'] . "/" . $data['file_name']);
//$data['file_url'] = "./Uploads/Ios/original";
//$url = "./Uploads/Ios/original";
}
}*/
$urll = $data['file_url2'];
$data['file_size'] = strpos($data['file_size'], 'MB') ? $data['file_size'] : round($data['file_size'] / pow(1024, 2), 2) . "MB";
/*$extend = substr($data['file_url'], strlen($str) - 3, 3);
if ($extend != "apk" && $extend != "ipa") {
$data['file_url'] = $data['file_url'] . "/" . $data['file_name'];
}*/
$data['file_url'] = $data['file_url'] . "/" . $data['file_name'];
$data['id'] = $id;
$data['op_id'] = UID;
@ -89,69 +74,71 @@ class SourceEvent extends Controller
$data['create_time'] = NOW_TIME;
$remark = str_replace(array("\r\n", "\r", "\n"), "@@@", $_POST['remark']);
$data['remark'] = json_encode(explode('@@@', $remark));
$game_source = $model -> where(array('id' => $id)) -> find();
$game_source = $model->where(['id' => $id])->find();
if($game_source['file_name'] == $data['file_name']) {
if ($from == "dev") {
$this -> success('修改成功', U('Developers/source'));
} else {
$this -> success('修改成功', U('GameSource/lists'));
}
}
if ($data['file_type'] == 2) {
$data['plist_url'] = "./Uploads/SourcePlist/" . $data['game_id'] . ".Plist";
$data['org_plist_url'] = "./Uploads/OrgSourcePlist/" . $data['game_id'] . ".Plist";
$plist -> create_plist($data['game_id'], 0, $data['bao_name'], $data['file_url']);
}
$data['source_version'] = $game_source['source_version'] + 1;
$res = $model -> save($data);
$game = M('game', 'tab_')->where(['id' => $data['game_id']])->find();
$result = $gameSourceService->sourcePack($data, $game);
if (!$result['status']) {
if ($from == "dev") {
$this->error('修改失败', U('Developers/source'));
} else {
$this->error('修改失败', U('GameSource/lists'));
}
}
$data['plist_url'] = $result['data']['plistUrl'];
$data['org_plist_url'] = $result['data']['orgPlistUrl'];
$data['file_url'] = $result['data']['fileUrl'];
$data['original_url'] = $result['data']['originalUrl'];
if ($res) {
//原包打包
$this -> soure_pack($game_source['game_id'], $data['file_url'], $data['file_type'], $data['source_version'], $data['bao_name'], 1, $file_name);
if ($model->save($data)) {
//渠道包加入打包队列
$appmodel = M('Apply', 'tab_');
$app_map['status'] = 1;
$app_map['game_id'] = $game_source['game_id'];
$app_data = $appmodel -> where($app_map) -> select();
$app_data = $appmodel->where($app_map)->select();
if ($app_data) {
M() -> startTrans();
$app_res = $appmodel -> where($app_map) ->save(['enable_status'=>2, 'pack_url'=>'', 'plist_url'=>'']);
M('apply_launch', 'tab_') -> where(['launch_game_id'=>$game_source['game_id']]) -> setField('launch_packge', 0);
M()->startTrans();
$app_res = $appmodel->where($app_map)->save(['enable_status'=>2, 'pack_url'=>'', 'plist_url'=>'']);
M('apply_launch', 'tab_') -> where(['launch_game_id'=>$game_source['game_id']])->setField('launch_packge', 0);
if ($app_res === false) {
M() -> rollback();
M()->rollback();
if ($from == "dev") {
$this -> error('渠道包打包失败', U('Developers/source'));
$this->error('渠道包打包失败', U('Developers/source'));
} else {
$this -> error('渠道包打包失败', U('GameSource/lists'));
$this->error('渠道包打包失败', U('GameSource/lists'));
}
} else {
M() -> commit();
M()->commit();
}
}
@unlink($url . "/" . $file_name);
@unlink($urll . "/" . str_replace('.ipa', '.mobileprovision', $file_name));
$this -> update_game_size($data);
$this->update_game_size($data);
//发送站内信
$user_id = M('ucenter_member') -> where('status=1') -> field('id') -> select();
$content = '游戏:' . get_game_name($data['game_id']) . ' 已更新,请尽快处理渠道包';
$sdk_version = M('game', 'tab_') -> field('sdk_version') -> where(['id' => $data['game_id']]) -> find();
D('Msg') -> sendMsg2($user_id, $content, $sdk_version['sdk_version'], $data['game_id']);
if ($from == "dev") {
$this -> success('修改成功', U('Developers/source'));
$users = M('ucenter_member')->where('status=1') -> field('id')->select();
$content = '游戏:' . $game['game_name'] . ' 已更新,请尽快处理渠道包';
D('Msg')->sendMsg2($users, $content, $game['sdk_version'], $game['id']);
if ($from == "dev") {
$this->success('修改成功', U('Developers/source'));
} else {
$this -> success('修改成功', U('GameSource/lists'));
$this->success('修改成功', U('GameSource/lists'));
}
} else {
if ($from == "dev") {
$this -> error('修改失败', U('Developers/source'));
$this->error('修改失败', U('Developers/source'));
} else {
$this -> error('修改失败', U('GameSource/lists'));
$this->error('修改失败', U('GameSource/lists'));
}
}
@ -280,23 +267,18 @@ class SourceEvent extends Controller
Vendor('OSS.autoload');
$ossClient = new \OSS\OssClient(C("oss_storage.accesskeyid"), C("oss_storage.accesskeysecr"), C("oss_storage.domain"), C("oss_storage.is_cname"));
} catch (OssException $e) {
$this -> error($e -> getMessage());
$this -> error($e->getMessage());
}
$bucket = C('oss_storage.bucket');
// if(preg_match('/.apk/',$return_data['savename']) ){
$oss_name = "SourcePack";
// }else{
// $oss_name="IosGamePack";
// }
$oss_file_path = $oss_name . "/" . $return_data["savename"];
$avatar = $return_data["path"];
try {
$this -> multiuploadFile($ossClient, $bucket, $oss_file_path, $avatar);
$this->multiuploadFile($ossClient, $bucket, $oss_file_path, $avatar);
return true;
} catch (OssException $e) {
/* 返回JSON数据 */
$this -> error($e -> getMessage());
$this->error($e -> getMessage());
}
}

@ -22,4 +22,19 @@ class ApplyService {
M('apply', 'tab_')->where(['game_id' => $gameId, 'promote_id' => ['in', $ids]])->save($save);
}
public function updateAfterPack($apply, $packageUrl, $plistUrl)
{
$data = [];
$data['id'] = $apply['id'];
$data['pack_url'] = $packageUrl;
$data['dow_url'] = '/index.php?s=/Home/Down/down_file/game_id/' . $apply['game_id'] . '/promote_id/' . $apply['promote_id'];
$data['dow_status'] = 1;
$data['enable_status'] = 1;
$data['dispose_id'] = 0;
$data['dispose_time'] = time();
$data['plist_url'] = $plist_url;
$res = M('Apply', 'tab_')->save($data);
return $res;
}
}

@ -11,7 +11,8 @@ class GameSourceService {
}
public function getChannelConfigFile($gameSource) {
public function getChannelConfigFile($gameSource)
{
$configUrl = '';
if ($gameSource['sdk_version'] == 1) {
$configUrl = "META-INF/mch.properties";
@ -32,9 +33,13 @@ class GameSourceService {
return $configUrl;
}
public function getGameSourceUrl($gameSource){
public function getGameSourceUrl($gameSource)
{
if (empty($gameSource)) {
return '';
}
$path = '';
if($gameSource['file_type'] == '1'){
if($gameSource['file_type'] == 1){
$path = './Uploads/SourcePack/';
}else{
$path = './Uploads/Ios/original/';
@ -42,4 +47,294 @@ class GameSourceService {
$fileUrl = $path . $gameSource['file_name'];
return ROOTTT . ltrim($fileUrl, './');
}
public function packChannelInfo($zipFile, $distFile, array $packData)
{
$zip = new \ZipArchive();
if ($zip->open($zipFile, \ZipArchive::CREATE)) {
$zip->addFromString($distFile, json_encode($packData));
$zip->close();
return true;
}
return false;
}
/**
* 原包打包
*/
public function sourcePack($gameSource, $game)
{
$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) {
$oldLocalPath = $localPath;
$localPath = str_replace('Uploads/SourcePack', 'Uploads/Ios/original', $oldLocalPath);
$originalUrl = $relativeUrl;
copy($oldLocalPath, $localPath);
}
$channelConfigFile = $this->getChannelConfigFile($gameSource);
$status = $this->packChannelInfo($localPath, $channelConfigFile, $packData);
if (!$status) {
return [
'status' => false,
'message' => '打包失败,原包加入信息失败!',
];
}
$distFilePath = 'SourcePack/' . $gameSource['file_name'];
$result = $this->uploadPackage($localPath, $distFilePath);
$fileUrl = '';
if ($result['status']) {
$fileUrl = $result['data']['url'];
$fileUrl = $fileUrl == '@' ? $relativeUrl : $fileUrl;
} else {
return [
'status' => false,
'message' => '打包失败上传OSS失败',
];
}
$plistUrl = '';
$orgPlistUrl = '';
if ($game['sdk_version'] == 2) {
$params = [
'domain' => '',
'packageName' => $gameSource['bao_name'],
'gameId' => $game['id'],
'promoteId' => 0,
'packageUrl' => $fileUrl,
'gameIcon' => '',
'type' => 'pack'
];
$result = $this->createPlist($params);
if ($result['status']) {
$plistUrl = $result['data']['path'];
} else {
return [
'status' => false,
'message' => '打包失败生成plist文件失败',
];
}
$params['type'] = 'org';
$result = $this->createPlist($params);
if ($result['status']) {
$orgPlistUrl = $result['data']['path'];
} else {
return [
'status' => false,
'message' => '打包失败生成原包plist文件失败',
];
}
}
return [
'status' => true,
'message' => '打包成功!',
'data' => [
'plistUrl' => $plistUrl,
'orgPlistUrl' => $orgPlistUrl,
'fileUrl' => $fileUrl,
'originalUrl' => $originalUrl,
]
];
}
/**
* 渠道打包
*/
public function channelPack($gameSource, $game, $apply, $launchCount = 0)
{
$gameSourceUrl = $this->getGameSourceUrl($gameSource);
if ($gameSource == null || !file_exists($gameSourceUrl)) {
M('apply', 'tab_')->where(['id' => $apply['id']])->setField('enable_status', -1);
}
/* 检测是否存在投放申请,存在则更改投放申请信息,否则进行渠道打包 */
if ($launchCount > 0) {
M('apply', 'tab_')->where(['id' => $apply['id']])->setField('enable_status', 3);
$launchData = ['launch_packge' => 2, 'launch_down_url'=>'' , 'launch_plist_url'=>''];
M('apply_launch', 'tab_')->where(['apply_id' => $apply['id'], 'launch_packge'=>['in', [0, 2, 3]]])->save($launchData);
}
$savePath = '';
$fileName = 'game_package' . $apply['game_id'] . '-' . $apply['promote_id'];
if ($apply['sdk_version'] == 1) {
$savePath = 'Uploads/GamePack/' . $fileName . '.apk';
} else {
$savePath = 'Uploads/IosGamePack/' . $fileName . '.ipa';
}
$channelConfigFile = $this->getChannelConfigFile($gameSource);
$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'],
];
$status = $this->packChannelInfo($localPath, $channelConfigFile, $packData);
if (!$status) {
return [
'status' => false,
'message' => '打包失败,加入渠道信息失败!',
];
}
$result = $this->uploadPackage($localPath, $savePath, true);
if ($result['status']) {
$packageUrl = $result['data']['url'];
$packageUrl = $packageUrl == '@' ? $relativePath : $packageUrl;
} else {
return [
'status' => false,
'message' => '打包失败上传OSS失败',
];
}
$plistInfo = ['game_id' => $apply['game_id'], 'promote_id' => $apply['promote_id']];
$plistUrl = '';
if ($apply['sdk_version'] == 2) {
$params = [
'domain' => '',
'packageName' => $gameSource['bao_name'],
'gameId' => $game['id'],
'promoteId' => $apply['promote_id'],
'packageUrl' => $packageUrl,
'gameIcon' => '',
'type' => 'pack'
];
$result = $this->createPlist($params);
if ($result['status']) {
$plistUrl = $result['data']['path'];
} else {
return [
'status' => false,
'message' => '打包失败生成plist文件失败',
];
}
}
$applyService->updateAfterPack($apply, $packageUrl, $plistUrl);
return [
'status' => true,
'message' => '打包成功!',
'data' => [
'plistUrl' => $plistUrl,
]
];
}
public function uploadPackage($localFilePath, $distFilePath, $isDeleteLocal = false)
{
if (get_tool_status('oss_storage') == 1) {
$ossService = new OssService();
$result = $ossService->upload($localFilePath, $distFilePath);
if ($isDeleteLocal && file_exists($localFilePath)) {
@unlink($localFilePath);
}
return $result;
} else {
// 不上传OSS等第三方服务器
return [
'status' => true,
'message' => '上传成功',
'data' => [
'url' => '@'
],
];
}
}
//生成游戏渠道plist文件
public function createPlist($params)
{
$domain = $params['domain'] ?? '';
$packageName = $params['packageName'] ?? '';
$gameId = $params['gameId'] ?? 0;
$promoteId = $params['promoteId'] ?? 0;
$packageUrl = $params['packageUrl'] ?? '';
$platformId = $params['platformId'] ?? 0;
$position = $params['position'] ?? 0;
$gameIcon = $params['gameIcon'] ?? '';
$type = $params['type'] ?? '';
if ($gameId == 0) {
return [
'status' => false,
'message' => '游戏ID错误',
];
}
if ($type == '' || !in_array($type, ['org', 'pack'])) {
return [
'status' => false,
'message' => '类型错误',
];
}
$xml = new \DOMDocument();
$xml->load(ROOTTT . 'Uploads/Plist/testdemo.Plist');
$online = $xml->getElementsByTagName('dict'); //查找节点
$elements = $online->item(1)->getElementsByTagName('string'); //第二个节点下所有string
foreach ($elements as $element) {
switch ($element->textContent) {
case 'ipa_url':
if (preg_match("/http/", $packageUrl)) {
$element->nodeValue = $packageUrl;
} else {
$element->nodeValue = "https://" . $domain . ltrim($packageUrl, '.');
}
break;
case 'icon':
if (preg_match("/http/", $gameIcon)) {
$element->nodeValue = $gameIcon;
} else {
$element->nodeValue = "https://" . $domain . $gameIcon;
}
break;
case 'com.dell':
$element->nodeValue = $packageName;
break;
case '1.0.0':
$element->nodeValue = false;
break;
case 'mchdemo':
$element->nodeValue = false;
break;
}
}
$fileName = '';
if ($type == 'pack') {
if ($promoteId == 0) {
$fileName = 'Uploads/SourcePlist/'. $gameId . '.Plist';
} elseif ($platformId > 0) {
$fileName = 'Uploads/GamePlist/'. $gameId . '-' . $promoteId . '-' . $platformId . '-' .$position . '.Plist';
} else {
$fileName = 'Uploads/GamePlist/'. $gameId . '-' . $promoteId . '.Plist';
}
} elseif ($type == 'org') {
$fileName = 'Uploads/OrgSourcePlist/'. $gameId . '.Plist';
}
$xml->save('./' . $fileName);
return [
'status' => true,
'message' => '生成成功',
'data' => [
'path' => './' . $fileName
]
];
}
}

@ -0,0 +1,122 @@
<?php
namespace Base\Service;
use OSS\Core\OssUtil;
use OSS\OssClient;
use OSS\Core\OSsException;
/**
* 目前仅支持阿里云OSS
*/
class OssService {
private $accessKeyId = '';
private $accessKeySecret = '';
private $domain = '';
private $isCName = false;
private $bucket = '';
private $bdDomain = '';
private $client;
private $errorMessage = '';
public function __construct()
{
Vendor('OSS.autoload');
$this->accessKeyId = C('oss_storage.accesskeyid');
$this->accessKeySecret = C('oss_storage.accesskeysecr');
$this->domain = C('oss_storage.domain');
$this->isCName = C('oss_storage.is_cname');
$this->bdDomain = C('oss_storage.bd_domain');
$this->bucket = C('oss_storage.bucket');
$this->client = new OssClient($this->accessKeyId, $this->accessKeySecret, $this->domain, $this->isCName);
}
public function upload($localFilePath, $saveFileName)
{
try {
$this->multiuploadFile($localFilePath, $saveFileName);
return [
'status' => true,
'message' => '上传OSS成功',
'data' => [
'url' => $this->getUrl()
]
];
} catch (OssException $e) {
return [
'status' => false,
'message' => $e->getMessage()
];
}
}
private function multiuploadFile($file, $saveFileName)
{
$uploadId = $this->client->initiateMultipartUpload($this->bucket, $saveFileName);
/*
* step 2. 上传分片
*/
$partSize = 5 * 1000 * 1024;
$uploadFile = $file;
$uploadFileSize = filesize($uploadFile);
$pieces = $this->client->generateMultiuploadParts($uploadFileSize, $partSize);
$responseUploadPart = [];
$uploadPosition = 0;
$isCheckMd5 = true;
foreach ($pieces as $i => $piece) {
$fromPos = $uploadPosition + (integer) $piece[OssClient::OSS_SEEK_TO];
$toPos = (integer) $piece[OssClient::OSS_LENGTH] + $fromPos - 1;
$upOptions = [
OssClient::OSS_FILE_UPLOAD => $uploadFile,
OssClient::OSS_PART_NUM => ($i + 1),
OssClient::OSS_SEEK_TO => $fromPos,
OssClient::OSS_LENGTH => $toPos - $fromPos + 1,
OssClient::OSS_CHECK_MD5 => $isCheckMd5,
];
if ($isCheckMd5) {
$contentMd5 = OssUtil::getMd5SumForFile($uploadFile, $fromPos, $toPos);
$upOptions[OssClient::OSS_CONTENT_MD5] = $contentMd5;
}
// 2. 将每一分片上传到OSS
$responseUploadPart[] = $this->client->uploadPart($this->bucket, $saveFileName, $uploadId, $upOptions);
}
$uploadParts = [];
foreach ($responseUploadPart as $i => $eTag) {
$uploadParts[] = [
'PartNumber' => ($i + 1),
'ETag' => $eTag,
];
}
/**
* step 3. 完成上传
*/
$this->client->completeMultipartUpload($this->bucket, $url, $uploadId, $uploadParts);
}
/**
*删除文件
*/
public function deleteObject($deleteFile)
{
$this->client->deleteObject($this->bucket, $deleteFile);
}
private function getUrl($saveFileName)
{
$url = '';
if ($this->isCName) {
$url = 'http://' . $this->domain . '/' . $saveFileName;
} else {
$url = 'https://' . $this->bucket . '.' . $this->domain . '/' . $saveFileName;
$url = str_replace('-internal', '', $url);
}
/**
* @todo unknown
*/
if (!empty($this->bdDomain) && strlen($this->bdDomain) > 5) {
$url = $this->bdDomain . $saveFileName;
}
}
}
Loading…
Cancel
Save