// +---------------------------------------------------------------------- namespace Home\Controller; use Think\Controller; use User\Api\MemberApi; /** * 前台公共控制器 * 为防止多分组Controller名称冲突,公共Controller名称统一使用分组名称 */ class HomeController extends Controller { /* 空操作,用于输出404页面 */ public function _empty() { $this->redirect('Index/index'); } protected function _initialize() { /* 读取站点配置 */ $config = api('Config/lists'); C($config); //添加配置 //var_dump($config); if (!C('WEB_SITE_CLOSE')) { $this->error('站点已经关闭,请稍后访问~'); } } public function rule() { $this->display(); } public function generateWechatSign() { $url = I('url', ''); $appid = 'wx5a1463c00253851b'; $secret = 'd3219c70a45c5e1954be4608b288d38b'; $tokenUrl = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appid . '&secret=' . $secret; $content = file_get_contents(RUNTIME_PATH . 'Data/wechat_ticket'); $ticketData = null; if ($content) { $ticketData = json_decode($content, true); } $isExpired = false; $ticket = ''; if ($ticketData) { $isExpired = time() > $ticketData['expired_at'] ? true : false; $time = $ticketData['time']; $ticket = $ticketData['ticket']; } if (!$ticketData || $isExpired) { $ticket = $ticketData['ticket']; $result = file_get_contents($tokenUrl); $result = json_decode($result, true); if (!$result || isset($result['errcode'])) { $this->ajaxReturn([ 'status' => false, 'msg' => '获取失败', ]); } $accessToken = $result['access_token']; $ticketUrl = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=' . $accessToken . '&type=jsapi'; $result = file_get_contents($ticketUrl); $result = json_decode($result, true); if (!$result || $result['errcode'] != 0) { $this->ajaxReturn([ 'status' => false, 'msg' => '获取失败', ]); } $ticket = $result['ticket']; file_put_contents(RUNTIME_PATH . 'Data/wechat_ticket', json_encode(['ticket' => $ticket, 'expired_at' => time() + 3600])); } $randStr = 'aaabbbxeclsx'; $time = time(); $signStr = 'jsapi_ticket=' . $ticket . '&noncestr=' . $randStr . '×tamp=' . $time . '&url=' . $url; $sign = sha1($signStr); $this->ajaxReturn([ 'status' => true, 'msg' => '获取成功', 'data' => [ 'sign' => $sign, 'randStr' => $randStr, 'time' => $time, 'appid' => $appid, ] ]); } public function promitionofregestion() { $gameData = M('Game', 'tab_') ->field('relation_game_id,sdk_version') ->where(array('id' => intval($_GET['gid']))) ->find(); $RelationGameId = $gameData['relation_game_id']; $gameSdkType = $gameData['sdk_version']; $map['tab_game.relation_game_id'] = $RelationGameId; $data = M('game', 'tab_') ->field('tab_game.id,tab_game.sdk_version,tab_game.icon,tab_game.screenshot,tab_game.relation_game_id,tab_game.relation_game_name,ta.enable_status,tab_game.dow_status,tab_game.features,tab_game.flooring_page_imgs,ta.promote_id') ->join('tab_apply ta ON ta.game_id = tab_game.id and ta.offline_status = 0 and ta.promote_id=' . intval($_GET['pid'])) ->where($map) ->group('tab_game.id') ->select(); foreach ($data as $key => $value) { if (!empty($value['flooring_page_imgs'])) { $data[$key]['flooring_page_imgs'] = explode(',', $value['flooring_page_imgs']); } } $this->assign('data', $data); $this->assign('gameSdkType', $gameSdkType); $this->display(); } public function iosDown() { $gameId = I('get.gid'); $promoteId = I('get.pid'); $status = I('get.status'); if (empty($gameId) || empty($promoteId)) { $this->error('链接丢失'); } if ($status == 1) { $downLink = 'itms-services://?action=download-manifest&url=' . "https://" . $_SERVER["HTTP_HOST"] . ltrim(M('GameSource', 'tab_')->where(array('game_id' => $gameId))->getField('org_plist_url'), '.'); } else { $downLink = get_apply_dow_url($gameId, $promoteId); } $this->assign('downLink', $downLink); $this->display(); } /* * 推广链接(含投放) * @author 鹿文学 */ public function promotionofregistration() { $map['relation_game_id'] = $_GET['gid']; $map['ta.promote_id'] = $_GET['pid']; $data = M('game', 'tab_') ->field('tab_game.id,tab_game.dow_icon,tab_game.back_map,tab_game.back_describe,tab_game.sdk_version,tab_game.dow_status,icon,screenshot,relation_game_id,relation_game_name,enable_status,ta.promote_id,ta.id as applyid,if(tab_game.sdk_version=1,ta.pack_url,ta.plist_url) as channel_url') ->where($map)->join('tab_apply ta ON ta.game_id=tab_game.id')->select(); if (empty($data)) { $res = M('game', 'tab_')->find($_GET['gid']); if ($res) { $data = M('game', 'tab_') ->field('tab_game.id,tab_game.sdk_version,tab_game.dow_status,icon,screenshot,relation_game_id,relation_game_name,enable_status,ta.promote_id,ta.id as applyid,if(tab_game.sdk_version=1,ta.pack_url,ta.plist_url) as channel_url') ->where(['relation_game_id' => $res['relation_game_id']])->join('tab_apply ta ON ta.game_id=tab_game.id')->select(); } } $platform_id = $_GET['lid']; $position = $_GET['p'] ? $_GET['p'] : 1; if ($platform_id && $platform_id > 0) { $launchmodel = M('apply_launch', 'tab_'); foreach ($data as $k => $v) { if ($v['applyid'] > 0) { $launch = $launchmodel->field('launch_down_url,launch_plist_url')->where(['apply_id' => $v['applyid'], 'platform_id' => $platform_id, 'position' => $position])->find(); if ($v['sdk_version'] == 1) { $data[$k]['launch'] = $launch['launch_down_url']; } else { $data[$k]['launch'] = $launch['launch_plist_url']; } } } $this->assign('platform_id', $platform_id); $this->assign('position', $position); $this->assign('is_launch', 1); } $this->assign('data', $data); $this->display(); } public function register() { $userApi = new MemberApi(); $id = $userApi->wap_register($_POST); if ($id > 0) { $this->add_user_play($_POST); $this->ajaxReturn([ 'status' => true, 'msg' => '注册成功' ]); } else { $this->ajaxReturn([ 'status' => false, 'msg' => '数据有误' ]); } } /** *添加玩家信息 */ private function add_user_play($user = array()) { $user_play = M("UserPlay", "tab_"); $map["game_id"] = $user["game_id"]; $map["user_id"] = $user["user_id"]; $map['sdk_version'] = $user['sdk_version']; $res = $user_play->where($map)->find(); if (empty($res)) { $user_entity = get_user_entity($user["user_id"]); $data["user_id"] = $user["user_id"]; $data["user_account"] = $user_entity["account"]; $data["user_nickname"] = $user_entity["nickname"]; $data["game_id"] = $user["game_id"]; $data["game_appid"] = $user["game_appid"]; $data["game_name"] = get_game_name($user["game_id"]); $data["server_id"] = 0; $data["server_name"] = ""; $data["role_id"] = 0; $data['parent_id'] = $user_entity["parent_id"]; $data['parent_name'] = $user_entity["parent_name"]; $data["role_name"] = ""; $data["role_level"] = 0; $data["bind_balance"] = 0; $data["promote_id"] = $user_entity["promote_id"]; $data["promote_account"] = $user_entity["promote_account"]; $data['play_time'] = time(); $data['play_ip'] = get_client_ip(); $data["sdk_version"] = $user["sdk_version"]; $data['ppuid'] = $user['puid'] == '' ? 0 : $user['puid']; $data['check_time'] = time(); $user_play->add($data); } } }