docodeit /
wechat
| 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 | * |
||
| 23 | * @return string |
||
| 24 | */ |
||
| 25 | public function msgid() |
||
| 26 | { |
||
| 27 | $query = [ |
||
| 28 | 'query' => [ |
||
| 29 | 't' => 'mass/send', |
||
| 30 | 'lang' => 'zh_CN', |
||
| 31 | ], |
||
| 32 | ]; |
||
| 33 | $url = 'cgi-bin/masssendpage'; |
||
| 34 | $res = $this->httpGet($url, $query); |
||
| 35 | $operation_seq = false; |
||
| 36 | $matchRes = preg_match('/operation_seq:[\s]+\"(.*?)\"/i', $res, $match); |
||
| 37 | if ($matchRes) { |
||
| 38 | $operation_seq = $match[1]; |
||
| 39 | } |
||
| 40 | |||
| 41 | return $operation_seq; |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * 获取ticket. |
||
| 46 | */ |
||
| 47 | public function ticket() |
||
| 48 | { |
||
| 49 | $options = [ |
||
| 50 | 'token' => $this->token, |
||
| 51 | 'lang' => 'zh_CN', |
||
| 52 | 'f' => 'json', |
||
| 53 | 'ajax' => '1', |
||
| 54 | 'random' => $this->getMillisecond(), |
||
| 55 | 'action' => 'get_ticket', |
||
| 56 | ]; |
||
| 57 | $url = 'misc/safeassistant?lang=zh_CN'; |
||
| 58 | $res = $this->httpPost($url, $options); |
||
| 59 | $ticket = false; |
||
| 60 | if ($res) { |
||
| 61 | if ($json = $this->jsonDecode($res)) { |
||
| 62 | $ticket = $json->ticket; |
||
| 63 | } |
||
| 64 | } |
||
| 65 | |||
| 66 | return $ticket; |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * 获取uuid. |
||
| 71 | * |
||
| 72 | * @param $ticket |
||
| 73 | * |
||
| 74 | * @return string|bool |
||
| 75 | */ |
||
| 76 | public function uuid($ticket) |
||
| 77 | { |
||
| 78 | $options = [ |
||
| 79 | 'token' => $this->token, |
||
| 80 | 'lang' => 'zh_CN', |
||
| 81 | 'f' => 'json', |
||
| 82 | 'ajax' => '1', |
||
| 83 | 'random' => $this->getMillisecond(), |
||
| 84 | 'state' => '0', |
||
| 85 | 'login_type' => 'safe_center', |
||
| 86 | 'type' => 'json', |
||
| 87 | 'ticket' => $ticket, |
||
| 88 | ]; |
||
| 89 | $uuid = false; |
||
| 90 | $url = 'safe/safeqrconnect?lang=zh_CN'; |
||
| 91 | $res = $this->httpPost($url, $options); |
||
| 92 | if ($res) { |
||
| 93 | if ($json = $this->jsonDecode($res)) { |
||
| 94 | $uuid = $json->uuid; |
||
| 95 | } |
||
| 96 | } |
||
| 97 | |||
| 98 | return $uuid; |
||
| 99 | } |
||
| 100 | |||
| 101 | /** |
||
| 102 | * 获取二维码图片. |
||
| 103 | */ |
||
| 104 | public function getQrCode() |
||
| 105 | { |
||
| 106 | $msgid = $this->msgid(); |
||
| 107 | $ticket = $this->ticket(); |
||
| 108 | $uuid = $this->uuid($ticket); |
||
| 109 | $query = [ |
||
| 110 | 'query' => [ |
||
| 111 | 'ticket' => $ticket, |
||
| 112 | 'uuid' => $uuid, |
||
| 113 | 'action' => 'check', |
||
| 114 | 'type' => 'msgs', |
||
| 115 | 'msgid' => $msgid, |
||
| 116 | ], |
||
| 117 | ]; |
||
| 118 | $text = "https://mp.weixin.qq.com/safe/safeqrcode?ticket=$ticket&uuid=$uuid&action=check&type=msgs&msgid=$msgid"; |
||
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
| 119 | $qr = new QrCode(); |
||
| 120 | // $qr->show($text); |
||
| 121 | $qr->show('https://login.weixin.qq.com/qrcode/wYHHLQ9y5A=='); |
||
| 122 | $url = 'safe/safeqrcode'; |
||
| 123 | $res = $this->httpGet($url, $query); |
||
| 124 | file_put_contents('qr.jpg', $res); |
||
| 125 | } |
||
| 126 | |||
| 127 | /** |
||
| 128 | * 检查二维码是否扫码 |
||
| 129 | * |
||
| 130 | * @param $uuid |
||
| 131 | * @param $token |
||
| 132 | */ |
||
| 133 | public function checkScan($token, $uuid) |
||
| 134 | { |
||
| 135 | $time = $this->getMillisecond(); |
||
| 136 | $options = [ |
||
| 137 | 'token' => $token, |
||
| 138 | 'lang' => 'zh_CN', |
||
| 139 | 'f' => 'json', |
||
| 140 | 'ajax' => '1', |
||
| 141 | 'random' => $time, |
||
| 142 | 'uuid' => $uuid, |
||
| 143 | 'action' => 'json', |
||
| 144 | 'type' => 'json', |
||
| 145 | ]; |
||
| 146 | $url = 'safe/safeuuid?timespam='.$time.'&lang=zh_CN'; |
||
| 147 | $res = $this->httpPost($url, $options); |
||
| 148 | if ($res) { |
||
| 149 | var_dump($res); |
||
|
0 ignored issues
–
show
|
|||
| 150 | } |
||
| 151 | } |
||
| 152 | } |
||
| 153 |