|
|
<?php
|
|
|
namespace Home\Controller;
|
|
|
|
|
|
use Think\Controller;
|
|
|
use User\Api\MemberApi;
|
|
|
use Base\Facade\Request;
|
|
|
use Base\Service\ApplyService;
|
|
|
use Base\Service\PackageDownloadLogService;
|
|
|
use Base\Tool\MobileDetect;
|
|
|
|
|
|
/**
|
|
|
* 前台公共控制器
|
|
|
* 为防止多分组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;
|
|
|
|
|
|
$tempDataDir = RUNTIME_PATH . 'Data';
|
|
|
if(!is_dir($tempDataDir)) {
|
|
|
@mkdir($tempDataDir);
|
|
|
}
|
|
|
|
|
|
$content = file_get_contents($tempDataDir . '/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()
|
|
|
{
|
|
|
|
|
|
// 旧版兼容
|
|
|
A('Home')->landingPage();
|
|
|
die();
|
|
|
|
|
|
$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 landingPage()
|
|
|
{
|
|
|
$testKey = I('test_key', '');
|
|
|
$code = I('code', '');
|
|
|
$gameId = I('gid', 0);
|
|
|
$promoteId = I('pid', 0);
|
|
|
if ($code == '' && ($gameId == 0 || $promoteId == 0)) {
|
|
|
$this->error('访问错误');
|
|
|
}
|
|
|
|
|
|
$identifier = $code != '' ? $code : 'gid/' . $gameId . '/pid/' . $promoteId;
|
|
|
$isBlack = M('device_bans', 'tab_')->where(['type' => 3, 'tag' => ['like', '%' . $identifier . '%']])->limit(1)->getField('id');
|
|
|
if ($isBlack) {
|
|
|
$this->error('该链接已被禁');
|
|
|
}
|
|
|
|
|
|
$applyService = new ApplyService();
|
|
|
if ($code != '') {
|
|
|
$data = $applyService->decodeApplyCode($code);
|
|
|
|
|
|
$result = $applyService->checkApplyCode($data, ApplyService::ENCRYPT_TYPE_LANDING_PAGE);
|
|
|
if (!$result['status']) {
|
|
|
$this->error($result['message']);
|
|
|
}
|
|
|
|
|
|
$gameId = $data['game_id'];
|
|
|
$promoteId = $data['promote_id'];
|
|
|
}
|
|
|
|
|
|
$isWechat = Request::isWechat();
|
|
|
$isIOS = Request::isIOS() || Request::isIPadOS();
|
|
|
$isAndroid = Request::isAndroid();
|
|
|
$isIOS13 = Request::isIOS13();
|
|
|
|
|
|
if ($testKey != '') {
|
|
|
$tempDataDir = RUNTIME_PATH . 'Data';
|
|
|
if(!is_dir($tempDataDir)) {
|
|
|
@mkdir($tempDataDir);
|
|
|
}
|
|
|
$testStr = date('Y-m-d H:i:s') . ' - ' . $testKey . ' - ' . Request::getUserAgent() . PHP_EOL;
|
|
|
file_put_contents($tempDataDir . '/langding_page.log', $testStr, FILE_APPEND);
|
|
|
}
|
|
|
|
|
|
$columns = [
|
|
|
'id',
|
|
|
'sdk_version',
|
|
|
'apply_auth',
|
|
|
'icon',
|
|
|
'screenshot',
|
|
|
'relation_game_id',
|
|
|
'relation_game_name',
|
|
|
'dow_status',
|
|
|
'features',
|
|
|
'flooring_page_imgs',
|
|
|
'game_score',
|
|
|
'recommend_level',
|
|
|
'game_size',
|
|
|
'introduction',
|
|
|
'flooring_page_video',
|
|
|
'flooring_page_video_cover',
|
|
|
'ios_video_top',
|
|
|
'beta_url',
|
|
|
'download_ways'
|
|
|
];
|
|
|
$map = ['id' => intval($gameId)];
|
|
|
$game = M('game', 'tab_')->field($columns)->where($map)->find();
|
|
|
|
|
|
$promote = M('promote', 'tab_')->field(['id', 'parent_id', 'chain', 'level'])->where(['id' => $promoteId])->find();
|
|
|
|
|
|
if ($game['sdk_version'] == 1 && $isIOS) {
|
|
|
$map = [];
|
|
|
$map['relation_game_id'] = $game['relation_game_id'];
|
|
|
$map['sdk_version'] = 2;
|
|
|
$game = M('game', 'tab_')->field($columns)->where($map)->find();
|
|
|
} elseif ($game['sdk_version'] == 2 && $isAndroid) {
|
|
|
$map = [];
|
|
|
$map['relation_game_id'] = $game['relation_game_id'];
|
|
|
$map['sdk_version'] = 1;
|
|
|
$game = M('game', 'tab_')->field($columns)->where($map)->find();
|
|
|
}
|
|
|
$apply = M('apply', 'tab_')->field(['game_id', 'enable_status', 'promote_id'])
|
|
|
->where(['promote_id' => $promoteId, 'game_id' => $game['id']])
|
|
|
->find();
|
|
|
if (!$apply) {
|
|
|
$this->error('该链接已经停止使用');
|
|
|
}
|
|
|
$game['icon'] = get_cover($game['icon'], 'path');
|
|
|
|
|
|
$gameSource = M('GameSource', 'tab_')->field(['create_time', 'org_plist_url', 'is_new_sdk'])->where(array('game_id' => $game['id']))->find();
|
|
|
|
|
|
$imageIds = explode(',', $game['flooring_page_imgs']) ?? [];
|
|
|
$imageUrls = [];
|
|
|
foreach ($imageIds as $imageId) {
|
|
|
$imageUrls[] = get_cover($imageId, 'path');
|
|
|
}
|
|
|
$game['flooring_page_imgs'] = $imageUrls;
|
|
|
$game['flooring_page_video_cover'] = get_cover($game['flooring_page_video_cover'], 'path');
|
|
|
|
|
|
$screenshotIds = explode(',', $game['screenshot']) ?? [];
|
|
|
$screenshotUrls = [];
|
|
|
foreach ($screenshotIds as $screenshotId) {
|
|
|
$screenshotUrls[] = get_cover($screenshotId, 'path');
|
|
|
}
|
|
|
$game['screenshot'] = $screenshotUrls;
|
|
|
|
|
|
$isNewIos = false;
|
|
|
if ($gameSource['is_new_sdk'] == 1) {
|
|
|
$isNewIos = true;
|
|
|
}
|
|
|
|
|
|
// 调试
|
|
|
// $isIOS = true;
|
|
|
|
|
|
$downloadUrl = '';
|
|
|
if (!$isNewIos && $isIOS13) {
|
|
|
$downloadUrl = 'itms-services://?action=download-manifest&url=' . Request::getHost() . ltrim($gameSource['org_plist_url'], '.');
|
|
|
} else {
|
|
|
$applyService = new ApplyService();
|
|
|
$downloadUrl = $applyService->getDownloadUrl($apply);
|
|
|
}
|
|
|
|
|
|
$serviceQQ = M("config", "sys_")->field('value')->where("name='APP_QQ'")->find()['value'];
|
|
|
|
|
|
$ssgUrl = C('DOMAIN_OFFICIAL_MOBILE') . '/mobile.php/Ssg/pay/game_id/' . $game['id'] . '/promote_id/' . $promoteId;
|
|
|
|
|
|
$this->assign("serviceQQ", $serviceQQ);
|
|
|
$this->assign('isNewIos', $isNewIos);
|
|
|
$this->assign('downloadUrl', $downloadUrl);
|
|
|
$this->assign('isIOS13', $isIOS13);
|
|
|
$this->assign('isWechat', $isWechat);
|
|
|
$this->assign('isIOS', $isIOS);
|
|
|
$this->assign('isAndroid', $isAndroid);
|
|
|
$this->assign('apply', $apply);
|
|
|
$this->assign('game', $game);
|
|
|
$this->assign('promoteId', $promoteId);
|
|
|
$this->assign('ssgUrl', $ssgUrl);
|
|
|
$cur_url = base64_encode(base64_encode("http://" . $_SERVER['HTTP_HOST'] . __SELF__));
|
|
|
$this->assign('cur_url', $cur_url);
|
|
|
if ($isIOS) {
|
|
|
$this->display('landingPage');
|
|
|
} else {
|
|
|
$this->display('landingPage2');
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private function get_device_type()
|
|
|
{
|
|
|
//全部变成小写字母
|
|
|
$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
|
|
|
$type = 'other';
|
|
|
//分别进行判断
|
|
|
if(strpos($agent, 'iphone') || strpos($agent, 'ipad'))
|
|
|
{
|
|
|
$type = 'ios';
|
|
|
}
|
|
|
|
|
|
if(strpos($agent, 'android'))
|
|
|
{
|
|
|
$type = 'android';
|
|
|
}
|
|
|
return $type;
|
|
|
}
|
|
|
|
|
|
|
|
|
public function iosDown()
|
|
|
{
|
|
|
$gameId = I('get.gid');
|
|
|
$promoteId = I('get.pid');
|
|
|
$status = I('get.status');
|
|
|
|
|
|
if (empty($gameId) || empty($promoteId)) {
|
|
|
$this->error('链接丢失');
|
|
|
}
|
|
|
|
|
|
$packageDownloadLogService = new PackageDownloadLogService();
|
|
|
$packageDownloadLogService->add([
|
|
|
'user_id' => 0,
|
|
|
'game_id' => $gameId,
|
|
|
'promote_id' => $promoteId,
|
|
|
'type' => 1,
|
|
|
]);
|
|
|
|
|
|
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);
|
|
|
}
|
|
|
}
|
|
|
}
|