<?php 
/*
接口抓包自Q群机器人→Q群管家的消息设置。
需要提供q群的cookie,在qq群官网([url]https://qun.qq.com[/url])获取。
*/
    function getBkn($skey) {
        $hash = 5381;
        for ($i = 0, $len = strlen($skey); $i < $len; ++$i) {
            $hash += ($hash << 5) + ord($skey[$i]);
        }
        return $hash & 0x7fffffff;
    }
// 检查是否有文件上传
if(isset($_FILES['file'])) {
    // 设置QQ群机器人接口URL和cookie
    $url = 'https://qun.qq.com/cgi-bin/qunrobots/robots_image';
    $uin = '';
    $skey = '';
    $p_uin = '';
    $p_skey = '';
    $gc = '';//你自己有管理权限的群号。
    $cookie = "";//填写获取到的cookie
    // 获取上传的文件信息
    $file_name = $_FILES['file']['name'];
    $file_size = $_FILES['file']['size'];
    $file_tmp = $_FILES['file']['tmp_name'];
    $file_type = $_FILES['file']['type'];
    // 将文件内容转换为base64编码
    $file_data = base64_encode(file_get_contents($file_tmp));
    // 构造POST请求参数
    $bkn = getBkn($skey);
    $data = array(
            'bkn' => $bkn,
            'gc' => $gc,
            'type' => '1',
            'pic_up' => $file_data
        );
    // 发送POST请求
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_COOKIE, $cookie);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $response = curl_exec($ch);
    curl_close($ch);
    $data = json_decode($response, true);
    if(isset($data['data']['pic_url'])) {
        echo $data['data']['pic_url'];
    } else {
        echo $response;
    }
    function getBkn($skey) {
        $hash = 5381;
        for ($i = 0, $len = strlen($skey); $i < $len; ++$i) {
            $hash += ($hash << 5) + ord($skey[$i]);
        }
        return $hash & 0x7fffffff;
    }
}
?>
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>QQ群图床</title>
</head>
<body>
<div style="width:100%;text-align:center"> 
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
        <label for="file">选择要上传的图片:</label>
        <input type="file" name="file" id="file"><br><br>
        <input type="submit" name="submit" value="上传">
    </form>
</div>
</body>
</html>
QQ群官方图床上传源码
请登录之后再进行评论
登录


