|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the docodeit/wechat. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) docodeit <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace JinWeChat\OfficialAccount\Mass; |
|
13
|
|
|
|
|
14
|
|
|
use JinWeChat\Kernel\BaseClient; |
|
15
|
|
|
use JinWeChat\Kernel\Console\QrCode; |
|
16
|
|
|
|
|
17
|
|
|
class Client extends BaseClient |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* 获取msgid |
|
21
|
|
|
* 通过页面抓取,正则匹配 |
|
22
|
|
|
* @return string |
|
23
|
|
|
*/ |
|
24
|
|
|
public function msgid() |
|
25
|
|
|
{ |
|
26
|
|
|
$query = [ |
|
27
|
|
|
'query' => [ |
|
28
|
|
|
't' => 'mass/send', |
|
29
|
|
|
'lang' => 'zh_CN' |
|
30
|
|
|
] |
|
31
|
|
|
]; |
|
32
|
|
|
$url = 'cgi-bin/masssendpage'; |
|
33
|
|
|
$res = $this->httpGet($url, $query); |
|
34
|
|
|
$operation_seq = false; |
|
35
|
|
|
$matchRes = preg_match('/operation_seq:[\s]+\"(.*?)\"/i', $res, $match); |
|
|
|
|
|
|
36
|
|
|
if ($matchRes) { |
|
37
|
|
|
$operation_seq = $match[1]; |
|
38
|
|
|
} |
|
39
|
|
|
return $operation_seq; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* 获取ticket |
|
44
|
|
|
*/ |
|
45
|
|
|
public function ticket() |
|
46
|
|
|
{ |
|
47
|
|
|
$options = [ |
|
48
|
|
|
'token' => $this->token, |
|
49
|
|
|
'lang' => 'zh_CN', |
|
50
|
|
|
'f' => 'json', |
|
51
|
|
|
'ajax' => '1', |
|
52
|
|
|
'random' => $this->getMillisecond(), |
|
53
|
|
|
'action' => 'get_ticket' |
|
54
|
|
|
]; |
|
55
|
|
|
$url = 'misc/safeassistant?lang=zh_CN'; |
|
56
|
|
|
$res = $this->httpPost($url, $options); |
|
57
|
|
|
$ticket = false; |
|
58
|
|
|
if ($res) { |
|
59
|
|
|
if ($json = $this->jsonDecode($res)) { |
|
60
|
|
|
$ticket = $json->ticket; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
return $ticket; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* 获取uuid |
|
68
|
|
|
* @param $ticket |
|
69
|
|
|
* @return string|bool |
|
70
|
|
|
*/ |
|
71
|
|
|
public function uuid($ticket) |
|
72
|
|
|
{ |
|
73
|
|
|
$options = [ |
|
74
|
|
|
'token' => $this->token, |
|
75
|
|
|
'lang' => 'zh_CN', |
|
76
|
|
|
'f' => 'json', |
|
77
|
|
|
'ajax' => '1', |
|
78
|
|
|
'random' => $this->getMillisecond(), |
|
79
|
|
|
'state' => '0', |
|
80
|
|
|
'login_type' => 'safe_center', |
|
81
|
|
|
'type' => 'json', |
|
82
|
|
|
'ticket' => $ticket |
|
83
|
|
|
]; |
|
84
|
|
|
$uuid = false; |
|
85
|
|
|
$url = 'safe/safeqrconnect?lang=zh_CN'; |
|
86
|
|
|
$res = $this->httpPost($url, $options); |
|
87
|
|
|
if ($res) { |
|
88
|
|
|
if ($json = $this->jsonDecode($res)) { |
|
89
|
|
|
$uuid = $json->uuid; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
return $uuid; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* 获取二维码图片 |
|
97
|
|
|
*/ |
|
98
|
|
|
public function getQrCode() |
|
99
|
|
|
{ |
|
100
|
|
|
$msgid = $this->msgid(); |
|
101
|
|
|
$ticket = $this->ticket(); |
|
102
|
|
|
$uuid = $this->uuid($ticket); |
|
103
|
|
|
$query = [ |
|
104
|
|
|
'query' => [ |
|
105
|
|
|
'ticket' => $ticket, |
|
106
|
|
|
'uuid' => $uuid, |
|
107
|
|
|
'action' => 'check', |
|
108
|
|
|
'type' => 'msgs', |
|
109
|
|
|
'msgid' => $msgid, |
|
110
|
|
|
] |
|
111
|
|
|
]; |
|
112
|
|
|
$text = "https://mp.weixin.qq.com/safe/safeqrcode?ticket=$ticket&uuid=$uuid&action=check&type=msgs&msgid=$msgid"; |
|
|
|
|
|
|
113
|
|
|
$qr = new QrCode(); |
|
114
|
|
|
// $qr->show($text); |
|
115
|
|
|
$qr->show('https://login.weixin.qq.com/qrcode/wYHHLQ9y5A=='); |
|
116
|
|
|
$url = 'safe/safeqrcode'; |
|
117
|
|
|
$res = $this->httpGet($url, $query); |
|
118
|
|
|
file_put_contents('qr.jpg', $res); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* 检查二维码是否扫码 |
|
123
|
|
|
* @param $uuid |
|
124
|
|
|
* @param $token |
|
125
|
|
|
*/ |
|
126
|
|
|
public function checkScan($token, $uuid) |
|
127
|
|
|
{ |
|
128
|
|
|
$time = $this->getMillisecond(); |
|
129
|
|
|
$options = [ |
|
130
|
|
|
'token' => $token, |
|
131
|
|
|
'lang' => 'zh_CN', |
|
132
|
|
|
'f' => 'json', |
|
133
|
|
|
'ajax' => '1', |
|
134
|
|
|
'random' => $time, |
|
135
|
|
|
'uuid' => $uuid, |
|
136
|
|
|
'action' => 'json', |
|
137
|
|
|
'type' => 'json' |
|
138
|
|
|
]; |
|
139
|
|
|
$url = 'safe/safeuuid?timespam=' . $time . '&lang=zh_CN'; |
|
140
|
|
|
$res = $this->httpPost($url, $options); |
|
141
|
|
|
if ($res) { |
|
142
|
|
|
var_dump($res); |
|
|
|
|
|
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
|