增加docke部署
This commit is contained in:
252
codes/agent/game-docker/api/source/login/login.php
Normal file
252
codes/agent/game-docker/api/source/login/login.php
Normal file
@@ -0,0 +1,252 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
|
||||
<link href="css/style.css" rel="stylesheet">
|
||||
<link href="css/bootstrap.min.css" rel="stylesheet">
|
||||
<script language="JavaScript" src="js/jquery-2.1.4.min.js"></script>
|
||||
<script language="JavaScript" src="js/common.js"></script>
|
||||
<title>授权登录</title>
|
||||
</head>
|
||||
|
||||
<?php
|
||||
require_once dirname(__FILE__) . '/common.php';
|
||||
|
||||
/// 获取参数(GET)。
|
||||
$app_id = isset($_GET['app_id']) ? $_GET['app_id'] : ''; /// appid
|
||||
$dev_key = isset($_GET['dev_key']) ? $_GET['dev_key'] : ''; /// 开发者key
|
||||
$market_key = isset($_GET['market_key']) ? $_GET['market_key'] : ''; /// 门店key
|
||||
$login_type = isset($_GET['login_type']) ? $_GET['login_type'] : ''; /// 登陆方式
|
||||
$redirect_uri = isset($_GET['redirect_uri']) ? $_GET['redirect_uri'] : ''; /// 回调页面地址
|
||||
$error_uri = isset($_GET['error_uri']) ? $_GET['error_uri'] : ''; /// 错误页面地址
|
||||
$silence = isset($_GET['silence']) ? $_GET['silence'] : null; /// 是否静默方式登录
|
||||
$scode = isset($_GET['scode']) ? $_GET['scode'] : md5(date('Ymdhis') . rand(1000, 9999)); /// 随机数
|
||||
$forms = '';
|
||||
|
||||
/// 其他的参数
|
||||
$attach_array = GetAttachParameters(array('app_id','dev_key','market_key','login_type','redirect_uri','error_uri',), $_GET);
|
||||
|
||||
$attach_param = ''; /// 链接用的附加参数
|
||||
$attach_items = ''; /// 创建表单用的附加参数
|
||||
foreach ($attach_array as $key => $value)
|
||||
{
|
||||
$attach_param .= "&{$key}={$value}";
|
||||
$attach_items .= " <input name=\"{$key}\" type=\"text\" value=\"{$value}\" />" . PHP_EOL;
|
||||
}
|
||||
|
||||
if (empty($redirect_uri))
|
||||
$redirect_uri = rawurlencode(getLocaleUrl());
|
||||
|
||||
if (empty($error_uri))
|
||||
$error_uri = rawurlencode(dirname(getLocaleUrl()) . '/error.php');
|
||||
|
||||
$data = array(
|
||||
'market_key' => $market_key,
|
||||
'logintype' => $login_type,
|
||||
);
|
||||
if (!is_null($silence))
|
||||
$data['silence'] = $silence;
|
||||
|
||||
$api_url = getFullUrl('/api/login/querylist');
|
||||
$response = SendPost($api_url, $data);
|
||||
|
||||
// 如果API调用失败,直接从数据库查询登录方式
|
||||
if (empty($response)) {
|
||||
error_log("Login API Error: Empty response from $api_url, using database fallback");
|
||||
|
||||
try {
|
||||
// 直接连接数据库获取登录方式(从环境变量读取)
|
||||
require_once dirname(dirname(dirname(__DIR__))) . '/env_config.php';
|
||||
$dsn = "mysql:host=" . env('API_DB_HOST', 'rm-bp1btyuwq77591x0jpo.mysql.rds.aliyuncs.com') . ":" . env('API_DB_PORT', '3306') . ";dbname=" . env('API_DB_NAME', 'youlehudong') . ";";
|
||||
$username = env('API_DB_USER', 'games');
|
||||
$passwd = env('API_DB_PASSWORD', 'Games0791!!');
|
||||
$pdo = new PDO($dsn, $username, $passwd, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
|
||||
|
||||
if (empty($market_key)) {
|
||||
$condition = 'is_enabled = 1 and is_silence = ' . intval(empty($silence) ? 0 : $silence);
|
||||
if (!empty($login_type))
|
||||
$condition .= sprintf(' and type_id = %d', intval($login_type));
|
||||
|
||||
$stmt = $pdo->prepare("SELECT type_id,type_key,type_name,image,url,component,is_third,third_flag FROM syweb_logintype_base WHERE $condition");
|
||||
$stmt->execute();
|
||||
} else {
|
||||
$condition = 'a.type_key = b.type_key and a.is_enabled = 1 and b.is_enabled = 1 and market_key = ? and a.is_silence = ' . intval(empty($silence) ? 0 : $silence);
|
||||
if (!empty($login_type))
|
||||
$condition .= sprintf(' and a.type_id = %d', intval($login_type));
|
||||
|
||||
$stmt = $pdo->prepare("SELECT a.type_id,a.type_key,a.type_name,a.image,a.url,a.component,a.is_third,a.third_flag FROM syweb_logintype_base a, syweb_logintype_market b WHERE $condition");
|
||||
$stmt->execute(array($market_key));
|
||||
}
|
||||
|
||||
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// 处理URL为完整路径
|
||||
foreach ($data as $key => &$value) {
|
||||
$value['url'] = getFullUrl($value['url']);
|
||||
}
|
||||
|
||||
$response = rawurlencode(json_encode($data, JSON_UNESCAPED_UNICODE));
|
||||
|
||||
} catch (Exception $e) {
|
||||
error_log("Database fallback error: " . $e->getMessage());
|
||||
|
||||
// 最后的备用方案:返回默认微信登录配置
|
||||
$default_login_types = array(
|
||||
array(
|
||||
'type_id' => 2,
|
||||
'type_key' => '0002',
|
||||
'type_name' => '微信登录',
|
||||
'image' => 'img/wx.png',
|
||||
'url' => getFullUrl('api/login/weixin'),
|
||||
'component' => null,
|
||||
'is_third' => 1,
|
||||
'third_flag' => 'weixin'
|
||||
)
|
||||
);
|
||||
|
||||
$response = rawurlencode(json_encode($default_login_types, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
$result = json_decode(rawurldecode($response));
|
||||
if (empty($result)) /// 为空表示没有获取到任何登录方式
|
||||
{
|
||||
$html = <<<EOL
|
||||
<script>
|
||||
alert('找不到支援的任何登录方式, 请联系相关管理员!');
|
||||
</script>
|
||||
|
||||
EOL;
|
||||
}
|
||||
else /// 正常
|
||||
{
|
||||
$third_array = array(); /// 三方认证方式(不需要输入账号密码的方式)
|
||||
$owner_array = array(); /// 本地认证方式(需要输入账号密码的方式)
|
||||
|
||||
foreach ($result as $item)
|
||||
{
|
||||
$item = (array)$item;
|
||||
if (0 != $item['is_third']) /// 三方认证方式
|
||||
array_push($third_array, $item);
|
||||
else /// 本地认证方式
|
||||
array_push($owner_array, $item);
|
||||
}
|
||||
|
||||
$third_count = count($third_array);
|
||||
$owner_count = count($owner_array);
|
||||
|
||||
$third_html = '';
|
||||
$owner_html = '';
|
||||
|
||||
$splitter = '';
|
||||
$forms = '';
|
||||
|
||||
if (0 == $owner_count && 1 == $third_count) /// 只存在一种三方的校验方式则直接跳转到目标连接
|
||||
{
|
||||
$url = $third_array[0]['url'] . "?appid={$app_id}&devkey={$dev_key}&scode={$scode}&market_key={$market_key}&target={$redirect_uri}&fail_target={$error_uri}{$attach_param}";
|
||||
header("Location: {$url}");
|
||||
exit;
|
||||
}
|
||||
|
||||
/// 如果两种方式都有,则需要分隔元素。
|
||||
if (0 != $owner_count && 0 != $third_count)
|
||||
$splitter = <<<EOL
|
||||
<div class="sigma-content">
|
||||
<div class="sigma-middle-line">
|
||||
<span class="sigma-line-text">更多登录方式</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
EOL;
|
||||
|
||||
|
||||
if (0 != $owner_count) /// 如果本地验证方式不为空则需要用于输入账号密码的表单元素。
|
||||
{
|
||||
$owner_html = ' <div class="fangshi" id="owner">' . PHP_EOL;
|
||||
$forms = '';
|
||||
$index = 0;
|
||||
foreach ($owner_array as $owner)
|
||||
{
|
||||
$index++;
|
||||
|
||||
/// 用来提交数据的表单
|
||||
$forms .= <<<EOL
|
||||
<form style="display:none;" id="frm{$index}" name="frm{$index}" method="post" action="{$owner['url']}">
|
||||
<input name="appid" type="text" value="{$app_id}" />
|
||||
<input name="devkey" type="text" value="{$dev_key}" />
|
||||
<input name="scode" type="text" value="{$scode}" />
|
||||
<input name="market_key" type="text" value="{$market_key}" />
|
||||
<input name="target" type="text" value="{$redirect_uri}" />
|
||||
<input name="fail_target" type="text" value="{$error_uri}" />
|
||||
{$attach_items}
|
||||
</form>
|
||||
|
||||
EOL;
|
||||
|
||||
/// 用来显示的页面元素
|
||||
$owner_html .= <<<EOL
|
||||
<p class="s_row">
|
||||
<span class="img_tb"><img src="img/zh.png"></span>
|
||||
<input type="text" placeholder="账号|手机号|邮箱" autofocus>
|
||||
</p>
|
||||
<p class="s_row" style="margin-bottom: 30px;">
|
||||
<span class="img_tb"><img src="img/mm.png"></span>
|
||||
<input type="text" placeholder="请输入密码">
|
||||
</p>
|
||||
<div class="dr_btn">
|
||||
<button onclick="frm_submit(frm{$index})" class="btn btn-danger">登录</button>
|
||||
</div>
|
||||
<div class="wj_row">
|
||||
<a href="password.php" class="wjmm">忘记密码?</a>
|
||||
<a href="password_detail.php" class="zczh">没有帐号?立即注册>>></a>
|
||||
</div>
|
||||
|
||||
EOL;
|
||||
}
|
||||
|
||||
$owner_html .= ' </div>' . PHP_EOL;
|
||||
}
|
||||
|
||||
|
||||
if (0 != $third_count)
|
||||
{
|
||||
$third_html = ' <div class="fangshi" id="third">' . PHP_EOL;
|
||||
$index = 0;
|
||||
foreach ($third_array as $third)
|
||||
{
|
||||
$index++;
|
||||
$url = $third['url'] . "?appid={$app_id}&devkey={$dev_key}&scode={$scode}&market_key={$market_key}&target={$redirect_uri}&fail_target={$error_uri}{$attach_param}";
|
||||
|
||||
$third_html .= <<<EOL
|
||||
<a class="box" href="{$url}">
|
||||
<img src="{$third['image']}">
|
||||
<label>{$third['type_name']}</label>
|
||||
</a>
|
||||
|
||||
EOL;
|
||||
}
|
||||
}
|
||||
|
||||
$html = $owner_html . $splitter . $third_html;
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
<script>
|
||||
function frm_submit(form) {
|
||||
return form.submit();
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
<body class="body_bg">
|
||||
<?php echo $forms; ?>
|
||||
<header class="yl_logo">
|
||||
<img src="img/yl.png" class="img-responsive">
|
||||
</header>
|
||||
<div class="container-fluid">
|
||||
<?php echo $html; ?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user