error = "原包不能为空"; return false; } $Game = new GameModel(); $game = $Game->getUserData($user_id,$game_id); if($data['file_type'] == 1){//安卓包处理 $result = $this->androidPacket($data['file_name'],$data['file_url']); $data = array_merge($data,$result); }else{//ios处理 if(empty($data['description_file_url'])){ $this->error = "描述文件不能为空"; return false; } $result = $this->iosPacket($data['file_name'],$data['file_url']); $data = array_merge($data,$result); //生成plist文件 $data['plist_url'] = $this->generatePlist($data['file_name'],$data['file_url'],$game,$data['pack_name']); $data['description_url'] = $this->descriptionPacket($data['file_name'],$data['description_file_url'],$data['description_file_name']); } $data = $this->create($data); if(!$data){ return false; } if($data['file_type'] == 1){ $this->sourcePack($data['file_url'],$game); } $data['game_name'] = $game['game_name']; $data['file_id'] = 0; $data['develop_id'] = $user_id; $data['game_id'] = $game_id; $data['bao_name'] = $data['version']; $data['create_time'] = time(); $remark = str_replace(array("\r\n", "\r", "\n"), "@@@", $data['remark']); $data['remark'] = json_encode(explode('@@@',$remark)); $source = $this->where(['develop_id'=>$user_id,'game_id'=>$game_id])->find(); //设置游戏支付回调地址 M("game_set","tab_")->where(['game_id'=>$game_id])->setField("pay_notify_url",I('post.pay_notify_url')); if (empty($source)){ $data['source_version'] = 1; $res = $this->add($data); $this->soure_pack($data['game_id'],$data['file_url'],$data['file_type'],1); $this->update_game_size($data); }else{ $data = array_merge($source,$data); $data['source_version'] = $source['source_version']+1; $this->soure_pack($data['game_id'],$data['file_url'],$data['file_type'],$data['source_version']); $res = $this->save($data); if($res){ $appmodel = M('Apply','tab_'); $app_map['status'] = 1; $app_map['game_id'] = $game_source['game_id']; $app_data = $appmodel->where($app_map)->select(); if($app_data){ M()->startTrans(); $app_res = $appmodel->where($app_map)->setField('enable_status',2); if($app_res === false){ M()->rollback(); }else{ M()->commit(); } } } $this->update_game_size($data); } return $res; } /** * 安卓包处理 * @param $file_name * @param $file_url * @return mixed * author: xmy 280564871@qq.com */ public function androidPacket($file_name,$file_url){ $data['file_name'] = $file_name; $data['file_url'] = $file_url.'/'.$file_name; return $data; } /** * ios包处理 * @param $file_name * @param $file_url * @return mixed * author: xmy 280564871@qq.com */ public function iosPacket($file_name,$file_url){ $data['file_name'] = $file_name; $data['file_url'] = $file_url.'/'.$file_name; $new_path = "./Uploads/Ios/original/" . $data['file_name']; //IOS原包 移到新目录 copy($data['file_url'],$new_path); @unlink($data['file_url']); $data['file_url'] = $new_path; return $data; } /** * 生成IOS plist文件 * @param $file_url * @param $file_name * @param $game * author: xmy 280564871@qq.com */ public function generatePlist($file_name,$file_path,$game,$pack_name){ $game_appid = $game['game_appid']; $Plist = new PlistController(); $Plist->createPlist($game,0,$pack_name,$file_path); $plist_path = "./Uploads/SourcePlist/{$game['id']}.Plist"; return $plist_path; } /* public function generatePlist($file_url,$file_name,$game){ $game_appid = $game['game_appid']; $file_path = $file_url.'/'.$file_name; $Plist = new PlistController(); $Plist->createPlist($game,0,$game_appid,$file_path); $plist_path = "./Uploads/SourcePlist/{$game['id']}.Plist"; return $plist_path; } */ /** * 描述文件处理 * @param $new_name * @param $file_url * @param $file_name * @return string * author: xmy 280564871@qq.com */ public function descriptionPacket($new_name,$file_url,$file_name){ $old_file = $file_url."/".$file_name; $file_name = str_replace(".ipa",".mobileprovision",$new_name); $file_path = $file_url."/".$file_name; rename($old_file,$file_path); return $file_path; } /** * 安卓原包打包 * @param $file_url 文件地址 * @param $game * author: xmy 280564871@qq.com */ public function sourcePack($file_url,$game){ $zip = new \ZipArchive; $zip->open($file_url, \ZipArchive::CREATE); $data = array( "game_id" => $game['id'], "game_name" => $game['game_name'], "game_appid" => $game['game_appid'], "promote_id" => 0, "promote_account"=> "自然注册", ); $zip->addFromString('META-INF/mch.properties', json_encode($data)); $zip->close(); } public function getUserData($user_id,$game_id){ $map['s.develop_id'] = $user_id; $map['s.game_id'] = $game_id; $data = $this->alias("s") ->field("s.*,t.pay_notify_url") ->join("left join tab_game_set t on t.game_id = s.game_id") ->join() ->where($map) ->find(); $data['description_file_name'] = str_replace(".ipa",".mobileprovision",$data['file_name']); $data['description_file_url'] = str_replace('/'.$data['description_file_name'],"",$data['description_url']); return $data; } protected function update_game_size($param=null){ $model = D('Game'); $map['id'] = $param['game_id']; $data['game_size'] = round(filesize($param['file_url'])/pow(1024,2),2)."MB";; // $data['version'] = $param['version']; if($param['file_type']==1){ $data['and_dow_address'] = $param['file_url']; $ggame=$model->where(array('id'=>$map['id']))->find(); if($ggame['sdk_version']!=-1){ if($ggame['sdk_version']==2){ $data['sdk_version']=0; } }else{ $data['sdk_version']=1; } } else{ if($ggame['sdk_version']!=-1){ if($ggame['sdk_version']==1){ $data['sdk_version']=0; } }else{ $data['sdk_version']=2; } $data['ios_dow_address'] = $param['file_url']; } $model->where($map)->save($data); } /** *原包打包 */ protected function soure_pack($game_id=0,$file_url="",$file_type=1,$source_version=1){ $game_info = M("game","tab_")->find($game_id); $data = array( "game_id" => $game_info['id'], "game_name" => $game_info['game_name'], "game_appid" => $game_info['game_appid'], "promote_id" => 0, "promote_account"=> "自然注册", 'source_version' =>$source_version, ); if($file_type==1){ $zip = new \ZipArchive; $res = $zip->open($file_url, \ZipArchive::CREATE); $zip->addFromString('META-INF/mch.properties', json_encode($data)); $zip->close(); }elseif($file_type==2){ $zip_open_game_source = zip_open($file_url); 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) ."
"; } $new_ios_1=explode("/", $ios_app); } } $url_ver="Payload/".$new_ios_1[0]."/_CodeSignature/TXChannel"; $zip = new \ZipArchive; $res = $zip->open($file_url, \ZipArchive::CREATE); $zip->addFromString($url_ver, json_encode($data)); $zip->close(); } } }