<?php
ob_start();
require_once __DIR__ . '/../config.php';

// 从数据库获取配置
$app_id = getSiteConfig('oauth_qq_app_id');
$app_key = getSiteConfig('oauth_qq_app_key');
$callback = SITE_URL . 'api/qq_callback.php';
if (empty($app_id) || empty($app_key)) {
    die('QQ登录未配置，请联系管理员');
}

// 生成 state
session_start();
$state = md5(uniqid(rand(), true));
$_SESSION['qq_state'] = $state;

// 构建授权 URL
$redirect_uri = urlencode($callback);
$scope = 'get_user_info';
$auth_url = "https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id={$app_id}&redirect_uri={$redirect_uri}&state={$state}&scope={$scope}";

header('Location: ' . $auth_url);
exit;