|
发表于 2024-5-26 22:26:16
|
显示全部楼层
广东省肇庆市
<?php
// 设置请求URL
$url = 'https://passport.weibo.com/sso/v2/qrcode/image?entry=miniblog&size=180';
// 设置请求头部信息
$headers = array(
'Host: passport.weibo.com',
'Connection: keep-alive',
'sec-ch-ua: "Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"',
'Accept: application/json, text/plain, */*',
'X-Requested-With: XMLHttpRequest',
'X-CSRF-TOKEN: CK-Yco1Rc7C-N7I9J_lspWCmc_DvD-DaAGc74zxH1-gacIgX1=',
'sec-ch-ua-mobile: ?0',
'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36',
'sec-ch-ua-platform: "Windows"',
'Sec-Fetch-Site: same-origin',
'Sec-Fetch-Mode: cors',
'Sec-Fetch-Dest: empty',
'Referer: https://passport.weibo.com/sso/signin?entry=miniblog&source=miniblog&disp=popup&url=https%3A%2F%2Fweibo.com%2Fnewlogin%3Ftabtype%3Dweibo%26gid%3D102803%26openLoginLayer%3D0%26url%3Dhttps%253A%252F%252Fweibo.com%252F',
);
// 初始化 cURL 会话并获取二维码图片的 JSON 数据
$response = pz_curl($url, "", 0, $headers);
//echo $response;
// 解压缩返回的数据
$data = $response;
if ($data !== false) {
$json_data = json_decode($data, true);
if ($json_data && isset($json_data['retcode']) && $json_data['retcode'] === 20000000) {
$qrid = $json_data['data']['qrid'];
//echo "QR ID: " . $qrid . "<br>";
// 显示原始获取到的图片
// echo '<img src="' . $json_data['data']['image'] . '" alt="QR Code" /><br>';
// 构建新的请求URL
$checkUrl = 'https://passport.weibo.com/sso/v2/qrcode/check?tabtype=weibo&gid=102803&openLoginLayer=0&url=https%3A%2F%2Fweibo.com%2F&qrid=' . $qrid . '&disp=popup';
// 打印出 $checkUrl 以进行检查
// echo "Check URL: " . $checkUrl . "<br>";
// 获取并输出二维码状态
// checkQRCodeStatus($checkUrl, $headers);
$sc=pz_curl($checkUrl, "", 0, $headers);
echo $sc;
$jsopn=json_decode($sc,true);
echo "使用状态:".$jsopn['msg'];
} else {
echo "Invalid JSON data or retcode is not 20000000.";
}
} else {
echo "Error decoding compressed data.";
}
/**
* @param string $url 请求地址
* @param string $params 请求数据
* @param int $post 0 get 1 post
* @param array $xyt 添加协议头
* @param array $cookies 添加cookies
* @param null $zdx 重定向 不填为假 1为真
* @param null $fhxyt_COOKIES 返回协议头 cookies 数组方式 0为假 1为真
* @Return bool|false|string|string[]
*/
function pz_curl($url, $params=null, $post=null, $xyt=array(),$cookies=array(),$zdx=null,$fhxyt_COOKIES=null)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
// curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR: 202.108.11.8', 'CLIENT-IP: 202.108.11.8'));
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
curl_setopt($ch, CURLOPT_TIMEOUT, 300);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//判断是否重定向
if ($zdx==1){
curl_setopt($ch, CURLOPT_AUTOREFERER, false);
}
//当前为1的时候返回 协议头和cookies 返回协议头
if ($fhxyt_COOKIES==1){
curl_setopt($ch, CURLOPT_HEADER, 2);
}
//判断cookies是不是空的
if ($cookies[0]<>""){
curl_setopt($ch, CURLOPT_COOKIE, $cookies[0]);
}
//判断是否需要协议头
if (empty($xyt)<>true){
//判断是否需要协议头
curl_setopt($ch, CURLOPT_HTTPHEADER, $xyt);
}
//判断是不是https
$str=substr($url, 0,5);
if ($str=='https') {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // 对认证证书来源的检查
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); // 从证书中检查SSL加密算法是否存在
}
//post判断
if ($post==1) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_URL, $url);
} elseif ($post==null){
curl_setopt($ch, CURLOPT_URL, $url);
}
$response = curl_exec($ch);
curl_close($ch);
if ($fhxyt_COOKIES==1){
$FGH='
';
$data=explode($FGH,$response);
return $data;
}else{
return $response;
}
}
?> |
|