1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
// 生成二维码
public function getqrpic()
{
$url = 'https://ssl.ptlogin2.qq.com/ptqrshow?appid=1006102&e=2&l=M&s=4&d=72&v=4&t=0.5409099' . time() . 'daid=1&pt_3rd_aid=0';
$arr = $this->get_curl($url, 0, 0, 0, 1, 0, 0, 1);
preg_match('/qrsig=(.*?);/', $arr['header'], $match);
if ($qrsig = $match[1]) {
Json::msg(0, 'success', ['qrsig' => $qrsig, 'data' => base64_encode($arr['body'])]);
} else {
Json::msg(1, '二维码获取失败');
}
}
// 获取二维码状态
public function qqlogin()
{
error_reporting(0);
if (input('?get.qrsig')) {
$qrsig = input('get.qrsig');
} else {
Json::msg(400, 'qrsig不能为空');
}
$sig = '';
$url = 'https://ssl.ptlogin2.qq.com/ptqrlogin?u1=https%3A%2F%2Fid.qq.com%2Findex.html&ptqrtoken=' . $this->getqrtoken($qrsig) . '&ptredirect=1&h=1&t=1&g=1&from_ui=1&ptlang=2052&action=0-0-' . time() . '0000&js_ver=10291&js_type=1&login_sig=' . $sig . '&pt_uistyle=40&aid=1006102&daid=1&';
$ret = $this->get_curl($url, 0, $url, 'qrsig=' . $qrsig . '; ', 1);
preg_match("/ptuiCB\('(.*?)'\)/", $ret, $ts_arr);
$r = @explode("','", str_replace("', '", "','", $ts_arr[1]));
if ($r[0] == 65) {
Json::msg(205, '二维码已失效');
} elseif ($r[0] == 66) {
Json::msg(202, '二维码未失效');
} elseif ($r[0] == 67) {
Json::msg(204, '正在验证二维码');
} else {
if (strpos($ret, '403')) Json::msg(306, $ret);
}
if (strlen($ret) > 1000) {
$arr = explode(';', $ret);
$data = substr($arr[17], strpos($arr[17], '=o') + 2, strlen($arr[17]));
if (empty($data)) {
Json::msg(400, '请切换二维码' . $ret);
}
$qq = ltrim($data, '0');
// $qq是qq号,下面写你接下来需要处理的语句
}
}
private function get_curl($url, $post = 0, $referer = 0, $cookie = 0, $header = 0, $ua = 0, $nobaody = 0, $split = 0)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
$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 ($post) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
if ($header) {
curl_setopt($ch, CURLOPT_HEADER, TRUE);
}
if ($cookie) {
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
}
if ($referer) {
curl_setopt($ch, CURLOPT_REFERER, $referer);
}
if ($ua) {
curl_setopt($ch, CURLOPT_USERAGENT, $ua);
} else {
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.152 Safari/537.36');
}
if ($nobaody) {
curl_setopt($ch, CURLOPT_NOBODY, 1);
}
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$ret = curl_exec($ch);
if ($split) {
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($ret, 0, $headerSize);
$body = substr($ret, $headerSize);
$ret = array();
$ret['header'] = $header;
$ret['body'] = $body;
}
curl_close($ch);
return $ret;
}
|