*/ class PackageController extends Controller { protected function _initialize() { C(api('Config/lists')); } public function downloadError($message) { $this->assign('message', $message); $this->display('error'); } public function download() { $code = I('code', ''); $gameId = I('game_id', 0); $promoteId = I('promote_id', 0); if ($code == '' && ($gameId == 0 || $promoteId == 0)) { $this->redirect("package/downloadError", ['message' => '访问错误']); } $blackList = []; if (in_array($code, $blackList) || in_array('game_id/' . $gameId . '/promote_id/' . $promoteId, $blackList)) { $this->redirect("package/downloadError", ['message' => '该链接已被禁']); } if ($code != '') { $applyService = new ApplyService(); $data = $applyService->decodeApplyCode($code); $result = $applyService->checkApplyCode($data, ApplyService::ENCRYPT_TYPE_DOWNLOAD); if (!$result['status']) { $this->error($result['message']); } $gameId = $data['game_id']; $promoteId = $data['promote_id']; } $map = []; $map['status'] = 1; $map['enable_status'] = 1; $map['game_id'] = $gameId; $map['promote_id'] = $promoteId; $columns = ['game_id', 'promote_id', 'promote_account', 'pack_url', 'plist_url', 'status', 'enable_status']; $apply = M('apply','tab_')->field($columns)->where($map)->find(); $game = M('game','tab_')->field(['id', 'game_name', 'sdk_version'])->where(['id' => $apply['game_id']])->find(); if (Request::isMobile()) { if (!Request::isAndroid() && $game['sdk_version'] == 1) { $this->redirect("package/downloadError", ['message' => '请使用安卓浏览器下载']); } if (!Request::isIOS() && $game['sdk_version'] == 2) { $this->redirect("package/downloadError", ['message' => '请使用ios浏览器下载']); } } $packageUrl = $game['sdk_version'] == 1 ? $apply['pack_url'] : $apply['plist_url']; M('game','tab_')->where(['id' => $game['id']])->setInc('dow_num'); if (Request::isAndroid()) { $this->gotoPkgUrl($packageUrl); } else if (Request::isIOS()) { $plistUrl = substr($packageUrl, 1, strlen($packageUrl)); header("HTTP/1.1 303 See Other"); header("Location: "."itms-services://?action=download-manifest&url=" . Request::getHost() . "/" . $plistUrl); } else { $this->gotoPkgUrl($packageUrl); } } private function gotoPkgUrl($packageUrl) { if (preg_match("/oss/", $packageUrl)) { $url = str_replace('-internal', '', $packageUrl); echo ""; } elseif (preg_match("/clouddn/", $packageUrl)) { $url = "http://".$packageUrl; redirect($url); } elseif (preg_match("/myqcloud/", $packageUrl)) { redirect($packageUrl); } elseif(preg_match("/bcebos/", $packageUrl)) { redirect($packageUrl); } else { if (!file_exists($packageUrl)) { $this->error('文件不存在哦,亲!'); }else{ redirect(Request::getHost() . ltrim($packageUrl, '.')); } } } }