$value)
{
$attach_param .= "&{$key}={$value}";
$attach_items .= " " . 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;
}
}
$html = $owner_html . $splitter . $third_html;
}
?>