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\Login; |
13
|
|
|
|
14
|
|
|
use JinWeChat\Kernel\BaseClient; |
15
|
|
|
|
16
|
|
|
class Client extends BaseClient |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* 初始化Cookies |
20
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
21
|
|
|
* @throws \JinWeChat\Kernel\Exceptions\InvalidConfigException |
22
|
|
|
*/ |
23
|
|
|
public function init() |
24
|
|
|
{ |
25
|
|
|
return $this->httpGet(''); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* 发送登陆请求 |
30
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
31
|
|
|
* @throws \JinWeChat\Kernel\Exceptions\InvalidConfigException |
32
|
|
|
*/ |
33
|
|
|
public function startLogin() |
34
|
|
|
{ |
35
|
|
|
$this->init(); |
36
|
|
|
$params = [ |
37
|
|
|
'username' => $this->app['config']['username'], |
38
|
|
|
'pwd' => md5($this->app['config']['password']), |
39
|
|
|
'imgcode' => '', |
40
|
|
|
'f' => 'json', |
41
|
|
|
'userlang' => 'zh_CN', |
42
|
|
|
'token' => '', |
43
|
|
|
'lang' => 'zh_CN', |
44
|
|
|
'ajax' => '1', |
45
|
|
|
]; |
46
|
|
|
return $this->httpPost('cgi-bin/bizlogin?action=startlogin', $params); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* 请求调转链接,根据不同的链接判断公众号状态 |
51
|
|
|
* @throws \JinWeChat\Kernel\Exceptions\InvalidConfigException |
52
|
|
|
*/ |
53
|
|
|
public function redirect() |
54
|
|
|
{ |
55
|
|
|
$url = 'cgi-bin/bizlogin?action=validate&lang=zh_CN&account=' . $this->app['config']['username']; |
56
|
|
|
$this->httpGet($url); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* 保存QrCode到指定文件 |
61
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
62
|
|
|
* @throws \JinWeChat\Kernel\Exceptions\InvalidConfigException |
63
|
|
|
*/ |
64
|
|
|
public function getQrCode() |
65
|
|
|
{ |
66
|
|
|
return $this->httpGet('cgi-bin/loginqrcode?action=getqrcode¶m=4300&rd=855'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* 获取二维码扫码确认状态 |
71
|
|
|
* @throws \JinWeChat\Kernel\Exceptions\InvalidConfigException |
72
|
|
|
*/ |
73
|
|
|
public function ask() |
74
|
|
|
{ |
75
|
|
|
$url = 'cgi-bin/loginqrcode?action=ask&token=&lang=zh_CN&f=json&ajax=1'; |
76
|
|
|
$res = $this->httpGet($url); |
77
|
|
|
return $this->judge($res); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* 判断方法 |
82
|
|
|
* @param $res |
83
|
|
|
* @return bool |
84
|
|
|
* @throws \JinWeChat\Kernel\Exceptions\InvalidConfigException |
85
|
|
|
*/ |
86
|
|
|
public function judge($res) |
87
|
|
|
{ |
88
|
|
|
if (isset($res->status)) { |
89
|
|
|
switch ($res->status) { |
90
|
|
|
case 0://系统繁忙,请稍后再试 |
91
|
|
|
return false; |
92
|
|
|
case 1://未扫码 |
93
|
|
|
$this->ask(); |
94
|
|
|
break; |
95
|
|
|
case 2://已取消 |
96
|
|
|
return false; |
97
|
|
|
break; |
|
|
|
|
98
|
|
|
case 3://超时 |
99
|
|
|
return false; |
100
|
|
|
break; |
101
|
|
|
case 4://已确认 |
102
|
|
|
return true; |
103
|
|
|
break; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
return false; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* 扫码确认后跳转请求跳转地址 |
111
|
|
|
* @throws \JinWeChat\Kernel\Exceptions\InvalidConfigException |
112
|
|
|
*/ |
113
|
|
|
public function bizlogin() |
114
|
|
|
{ |
115
|
|
|
$url = 'https://mp.weixin.qq.com/cgi-bin/bizlogin?action=login'; |
116
|
|
|
$this->httpGet($url); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
The
break
statement is not necessary if it is preceded for example by areturn
statement:If you would like to keep this construct to be consistent with other
case
statements, you can safely mark this issue as a false-positive.