首页 代码源码 正文 收录检测中~

PHP官方API获取群列表接口源码

<?php

function get_qq_group_list($qq, $skey, $p_skey) {
    // 计算bkn值
    $bkn = bkn($skey);

    $url = 'https://qun.qq.com/cgi-bin/qun_mgr/get_group_list';
    $cookie = "p_uin=o{$qq}; uin=o{$qq}; skey={$skey}; p_skey={$p_skey}";
    $postData = "bkn={$bkn}";

    $headers = [
        "User-Agent: Mozilla/5.0 (Linux; Android 10; HLK-AL00 Build/HONORHLK-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.108 Safari/537.36 V1_AND_SQ_8.4.5_1468_YYB_D QQ/8.4.5.4745 NetType/4G WebP/0.4.1 Pixel/1080 StatusBarHeight/51 SimpleUISwitch/0 QQTheme/1000 InMagicWin/0",
        "Cookie: {$cookie}",
        "Referer: https://qun.qq.com/",
        "Content-Type: application/x-www-form-urlencoded",
        "Content-Length: " . strlen($postData)
    ];

    $options = [
        'http' => [
            'method' => 'POST',
            'header' => implode("\r\n", $headers),
            'content' => $postData,
            'timeout' => 30
        ]
    ];
    
    $context = stream_context_create($options);
    $response = file_get_contents($url, false, $context);
    
    return $response;
}

$qq = '123456';
$skey = '你的skey值';
$p_skey = '你的p_skey值';
$groupList = get_qq_group_list($qq, $skey, $p_skey);

$groups = json_decode($groupList, true);
echo "共获取到 " . count($groups['join']) . " 个群聊\n";
foreach ($groups['join'] as $group) {
    echo "群号: {$group['gc']}, 群名: {$group['gn']}\n";
}

function bkn($skey) {
    $len = strlen($skey);
    $hash = 5381;
    for ($i = 0; $i < $len; $i++) {
        $hash += ($hash << 5 & 2147483647) + ord($skey[$i]) & 2147483647;
        $hash &= 2147483647;
    }
    return $hash & 2147483647;
}

QQ群列表

上一篇
微信运动
下一篇
QQ自定义在线机型状态源码

评论(1条)

  1. avatar

    小天 Lv.1 Chrome 49.0.2623.87 Chrome 49.0.2623.87 Windows 7 x64 Edition Windows 7 x64 Edition 回复

    芜湖申诉

    #沙发 湖北省 移动/数据上网公共出口