吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3994|回复: 6
收起左侧

[其他转载] QQ 扫码登陆

[复制链接]
jiujiukeji 发表于 2020-4-1 15:23
[PHP] 纯文本查看 复制代码
<?php
header('Access-Control-Allow-Origin:*');
header('Content-type:application/json; charset=utf-8');
error_reporting(0);
date_default_timezone_set("PRC");
!empty($_GET['type']) ? $type = $_GET['type'] : error("请求参数错误,请刷新重试!~~");
switch ($type)
{
    case 'Getqrcode':
        echo json_encode(getqrcode());
        break;
    case 'Getresult':
        !empty($_GET['qrsig']) ? $qrsig=$_GET['qrsig'] : error("请求参数错误,缺少qrsig~~");
        echo json_encode(getresult($qrsig),JSON_UNESCAPED_UNICODE);
        break;
    default:
        echo json_encode(getqrcode());
}
/**
 * 获取二维码
 */
function getqrcode() {
    $qrcode = array();
    $api = 'https://ssl.ptlogin2.qq.com/ptqrshow?appid=549000912&e=2&l=M&s=3&d=72&v=7&t=0.1415855' . time();
    $paras['header'] = 1;
    $ret = get_curl($api, $paras);
    preg_match('/qrsig=(.*?);/', $ret, $matches);
    preg_match_all('/ (\d){3}/', $ret, $Conlen);
    $arr = explode('com;', $ret);
    $qrcode['qrsig'] = $matches[1];
    $qrcode['data'] = base64_encode(trim($arr['1']));
    return $qrcode;
}

/**
 * @param $qrsig
 * @return array
 * 获取登录状态
 */
function getresult($qrsig) {
    $ret = array();
    $api = 'https://ssl.ptlogin2.qq.com/ptqrlogin?u1=' . urlencode('https://qzs.qzone.qq.com/') . '&ptqrtoken=' . getqrtoken($qrsig) . '&ptredirect=0&h=1&t=1&g=1&from_ui=1&ptlang=2052&action=0-1-' . time() . '&js_ver=90220&js_type=1&login_sig=&pt_uistyle=40&aid=549000912&daid=5&has_onekey=1';
    $paras['cookie'] = 'qrsig=' . $qrsig . ';';
    $body = get_curl($api, $paras);
    if (preg_match("/ptuiCB\('(.*?)'\)/", $body, $arr)) {
        $r = explode("','", str_replace("', '", "','", $arr[1]));
        if ($r[0] == 0) {
            preg_match('/uin=(\d+)&/', $body, $uin);
            $ret['code'] = 1;
            $ret['data']['uin'] = $uin[1];
            $ret['msg'] = 'QQ登录成功';
        } elseif ($r[0] == 65) {
            $ret['msg'] = '登录二维码已失效,请刷新重试!';
        } elseif ($r[0] == 66) {
            $ret['msg'] = '请使用手机QQ扫码登录';
        } elseif ($r[0] == 67) {
            $ret['msg'] = '正在验证二维码...';
        } else {
            $ret['msg'] = '未知错误001,请刷新重试!';
        }
    } else {
        $ret['msg'] = '未知错误002,请刷新重试!';
    }
    return $ret;
}


function get_curl($url, $paras = array()) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    $httpheader[] = "Accept:*/*";
    $httpheader[] = "Accept-Encoding:gzip,deflate,sdch";
    $httpheader[] = "Accept-Language:zh-CN,zh;q=0.8";
    $httpheader[] = "Connection:close";
    curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
    if ($paras['ctime']) { // 连接超时
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, $paras['ctime']);
    }
    if ($paras['rtime']) { // 读取超时
        curl_setopt($ch, CURLOPT_TIMEOUT_MS, $paras['rtime']);
    }
    if ($paras['post']) {
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $paras['post']);
    }
    if ($paras['header']) {
        curl_setopt($ch, CURLOPT_HEADER, true);
    }
    if ($paras['cookie']) {
        curl_setopt($ch, CURLOPT_COOKIE, $paras['cookie']);
    }
    if ($paras['refer']) {
        if ($paras['refer'] == 1) {
            curl_setopt($ch, CURLOPT_REFERER, 'http://m.qzone.com/infocenter?g_f=');
        } else {
            curl_setopt($ch, CURLOPT_REFERER, $paras['refer']);
        }
    }
    if ($paras['ua']) {
        curl_setopt($ch, CURLOPT_USERAGENT, $paras['ua']);
    } else {
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36");
    }
    if ($paras['nobody']) {
        curl_setopt($ch, CURLOPT_NOBODY, 1);
    }
    curl_setopt($ch, CURLOPT_ENCODING, "gzip");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $ret = curl_exec($ch);
    curl_close($ch);
    return $ret;
}


/** QQ空间Token算法*/
function getqrtoken($qrsig) {
    $len = strlen($qrsig);
    $hash = 0;
    for ($i = 0; $i < $len; $i++) {
        $hash += (($hash << 5) & 2147483647) + ord($qrsig[$i]) & 2147483647;
        $hash &= 2147483647;
    }
    return $hash & 2147483647;
}

function error($str){
    exit(json_encode([
        "code"=>-1,
        "msg"=>$str
    ],JSON_UNESCAPED_UNICODE));
}

免费评分

参与人数 1吾爱币 +1 热心值 +1 收起 理由
lalaya + 1 + 1 用心讨论,共获提升!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

cj13888 发表于 2020-4-1 15:44
学习借鉴一下,谢谢分享
NingXIU 发表于 2020-4-1 15:49
wubo777 发表于 2020-4-1 16:06
苏浩 发表于 2020-4-1 16:20
这应该是搬来的吧
w92vv 发表于 2020-4-1 16:49
感谢分享
头像被屏蔽
lalaya 发表于 2020-4-1 23:27
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-17 04:38

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表