Knight's Blog

输入关键词,搜索全站文章

QQ聚合登录源码

🚀 QQ快捷登录平台 - 开源免费版


下载链接QQ快捷登录平台.zip

📖 项目简介

QQ快捷登录平台是一个基于PHP + MySQL开发的开源QQ登录接入服务系统。开发者可以通过简单的API调用,快速为自己的网站或应用添加QQ登录功能,无需繁琐的QQ互联申请流程。

本项目完全免费开源,遵循MIT协议,可自由用于个人或商业项目。


✨ 核心特性

特性 说明
🚀 极速接入 5分钟完成接入,提供完整SDK和示例代码
🔒 安全可靠 采用标准OAuth2.0协议,数据传输全程加密
💯 完全免费 开源免费,无功能限制,无调用次数限制
📊 数据统计 提供详细的登录数据统计和可视化报表
🎨 界面美观 基于Bootstrap 5的响应式现代化UI设计
🔧 易于扩展 模块化架构,易于二次开发和功能扩展
📱 多端适配 支持PC端和移动端自适应显示
🛡️ 安全防护 内置防SQL注入、XSS攻击等安全机制

🖼️ 界面预览

首页

  • 现代化响应式设计
  • 清晰的功能展示
  • 实时数据统计展示

用户中心

  • 应用管理(创建、编辑、删除)
  • API密钥管理
  • 登录日志查询
  • 个人资料设置

管理后台

  • 用户管理
  • 应用审核
  • 系统设置
  • 数据统计报表

🛠️ 技术架构

┌─────────────────────────────────────────┐
│           表现层 (Presentation)          │
│    首页 / 用户中心 / 管理后台 / API文档    │
├─────────────────────────────────────────┤
│           控制层 (Controller)            │
│    登录接口 / 回调处理 / 用户管理 / 支付    │
├─────────────────────────────────────────┤
│           业务层 (Service)               │
│    认证服务 / 用户服务 / 日志服务 / 缓存    │
├─────────────────────────────────────────┤
│           数据层 (Data Access)           │
│    MySQL数据库 / PDO / 数据库迁移工具      │
├─────────────────────────────────────────┤
│           核心库 (Core Library)          │
│    数据库类 / 缓存类 / 支付类 / 工具函数    │
└─────────────────────────────────────────┘

技术栈

  • 后端: PHP 7.4+ / PDO / Composer
  • 数据库: MySQL 5.7+ / utf8mb4
  • 前端: Bootstrap 5 / jQuery / Bootstrap Icons
  • 缓存: 文件缓存(可扩展Redis)
  • 协议: OAuth 2.0 / RESTful API

📦 安装部署

2793832095.zip

环境要求

  • PHP >= 7.4
  • MySQL >= 5.7
  • Nginx / Apache
  • SSL证书(强烈推荐)

一键安装

  1. 下载源码到网站根目录
  2. 访问 http://你的域名/setup/ 进入安装向导
  3. 按提示填写数据库信息和管理员账号
  4. 完成安装

Nginx配置参考

server {
    listen 80;
    server_name your-domain.com;
    root /var/www/qq-login-platform;
    index index.php;

    # 伪静态规则
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    # PHP处理
    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    # 禁止访问敏感文件
    location ~ ^/(core|setup)/.*\.(php|php5)$ {
        deny all;
    }
}

📡 API使用文档

接口规范

项目 说明
传输协议 HTTPS(强烈推荐)
数据格式 JSON
字符编码 UTF-8
请求方式 GET / POST
接口前缀 https://your-domain.com/

快速接入示例

HTML方式

<!-- QQ登录按钮 -->
<a href="https://your-domain.com/connect.php?app_id=YOUR_APP_ID&return_url=YOUR_CALLBACK">
    <img src="https://img.icons8.com/color/96/qq.png" width="40" alt="QQ登录">
    <span>QQ一键登录</span>
</a>

JavaScript方式

// QQ登录函数
function qqLogin() {
    const params = new URLSearchParams({
        app_id: 'YOUR_APP_ID',
        return_url: window.location.origin + '/callback',
        state: generateRandomString(16)  // 防CSRF攻击
    });
    window.location.href = 'https://your-domain.com/connect.php?' + params;
}

// 生成随机字符串
function generateRandomString(length) {
    const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    let result = '';
    for (let i = 0; i < length; i++) {
        result += chars.charAt(Math.floor(Math.random() * chars.length));
    }
    return result;
}

PHP完整示例

<?php
/**
 * QQ快捷登录接入示例
 */

class QQLoginSDK
{
    private $apiUrl;
    private $appId;
    private $appKey;

    public function __construct($appId, $appKey, $apiUrl)
    {
        $this->appId = $appId;
        $this->appKey = $appKey;
        $this->apiUrl = rtrim($apiUrl, '/') . '/';
    }

    /**
     * 获取QQ登录跳转地址
     */
    public function getLoginUrl($redirectUri, $state = '')
    {
        $params = [
            'act' => 'login',
            'appid' => $this->appId,
            'appkey' => $this->appKey,
            'type' => 'qq',
            'redirect_uri' => $redirectUri,
            'state' => $state
        ];

        $url = $this->apiUrl . 'connect.php?' . http_build_query($params);
        $response = $this->httpGet($url);
        $data = json_decode($response, true);

        if ($data['code'] === 0) {
            return $data['url'];
        }

        throw new Exception('获取登录地址失败: ' . $data['msg']);
    }

    /**
     * 通过授权码获取用户信息
     */
    public function getUserInfo($code)
    {
        $params = [
            'act' => 'callback',
            'appid' => $this->appId,
            'appkey' => $this->appKey,
            'type' => 'qq',
            'code' => $code
        ];

        $url = $this->apiUrl . 'connect.php?' . http_build_query($params);
        $response = $this->httpGet($url);
        $data = json_decode($response, true);

        if ($data['code'] === 0) {
            return [
                'openid' => $data['social_uid'],
                'nickname' => $data['nickname'],
                'avatar' => $data['faceimg'],
                'gender' => $data['gender'],
                'location' => $data['location'],
                'ip' => $data['ip']
            ];
        }

        throw new Exception('获取用户信息失败: ' . $data['msg']);
    }

    private function httpGet($url)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        $response = curl_exec($ch);
        curl_close($ch);
        return $response;
    }
}

// 使用示例
try {
    $sdk = new QQLoginSDK('YOUR_APP_ID', 'YOUR_APP_KEY', 'https://api.your-domain.com/');

    // 获取登录URL
    $loginUrl = $sdk->getLoginUrl('https://your-site.com/callback', 'random_state');
    header('Location: ' . $loginUrl);

    // 处理回调
    if (isset($_GET['code'])) {
        $userInfo = $sdk->getUserInfo($_GET['code']);
        echo "登录成功!欢迎," . $userInfo['nickname'];
    }
} catch (Exception $e) {
    echo "错误:" . $e->getMessage();
}
?>

🔌 接口列表

1. 获取登录地址

GET /connect.php?act=login

请求参数:

参数 类型 必填 说明
appid string 应用ID
appkey string 应用密钥
type string 固定值:qq
redirect_uri string 回调地址,需URL编码
state string CSRF防护参数

响应示例:

{
    "code": 0,
    "msg": "succ",
    "type": "qq",
    "url": "https://graph.qq.com/oauth2.0/authorize?..."
}

2. 回调获取用户信息

GET /connect.php?act=callback

请求参数:

参数 类型 必填 说明
appid string 应用ID
appkey string 应用密钥
type string 固定值:qq
code string 授权码

响应示例:

{
    "code": 0,
    "msg": "succ",
    "type": "qq",
    "social_uid": "QQ_OPENID",
    "access_token": "ACCESS_TOKEN",
    "nickname": "用户昵称",
    "faceimg": "https://thirdqq.qlogo.cn/...",
    "gender": "男",
    "location": "北京",
    "ip": "192.168.1.1"
}

3. 快捷查询用户信息

GET /connect.php?act=query

请求参数:

参数 类型 必填 说明
appid string 应用ID
appkey string 应用密钥
type string 固定值:qq
social_uid string 用户OpenID

📁 目录结构

qq-login-platform/
├── core/                       # 核心框架
│   ├── Lib/                   # 核心类库
│   │   ├── Db.php            # 数据库操作类
│   │   ├── Cache.php         # 缓存类
│   │   ├── Pay.php           # 支付类
│   │   └── ...
│   ├── helpers/              # 辅助函数
│   │   └── functions.php     # 全局函数
│   ├── App.php               # 应用核心类
│   ├── bootstrap.php         # 引导文件
│   └── config.php            # 配置文件
├── manager/                   # 管理后台
│   ├── index.php             # 后台首页
│   ├── apps.php              # 应用管理
│   ├── members.php           # 用户管理
│   └── ...
├── member/                    # 用户中心
│   ├── index.php             # 用户首页
│   ├── apps.php              # 我的应用
│   ├── login.php             # 登录页面
│   └── ...
├── pay/                       # 支付回调
│   ├── notify.php            # 异步通知
│   └── return.php            # 同步回调
├── setup/                     # 安装程序
│   ├── index.php             # 安装向导
│   └── database.sql          # 数据库结构
├── static/                    # 静态资源
│   └── css/
│       └── style.css         # 主样式文件
├── runtime/                   # 运行时目录
│   └── cache/                # 缓存文件
├── index.php                  # 网站首页
├── connect.php                # 登录接口
├── docs.php                   # 开发文档
└── README.md                  # 项目说明

🛡️ 安全说明

  1. HTTPS强制:生产环境必须使用HTTPS协议
  2. 密钥保护:AppKey不要泄露,不要在客户端代码中使用
  3. 回调验证:回调域名必须与应用注册时一致
  4. CSRF防护:使用state参数防止跨站请求伪造
  5. SQL注入:使用PDO预处理语句,已内置防护
  6. XSS防护:输出内容已进行HTML实体编码

📝 更新日志

v1.0.0 (2026-04-26)

  • ✨ 首次发布
  • ✨ 支持QQ登录接入
  • ✨ 提供完整的管理后台
  • ✨ 提供用户中心功能
  • ✨ 提供开发文档和SDK

📄 开源协议

本项目采用 MIT 协议开源,可自由用于个人或商业项目。

MIT License

Copyright (c) 2026 Knight

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.

💬 交流与反馈

  • 📧 邮箱:3514574884@qq.com
  • 🐧 QQ群:901336980

🎉 致谢:感谢所有使用和支持这个项目的朋友们!


开发者: Knight

最后更新:2026年4月26日

评论

暂无评论,快来抢沙发吧