1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace icy2003\php\iapis\wechat\miniprogram; |
4
|
|
|
|
5
|
|
|
use icy2003\php\I; |
6
|
|
|
use icy2003\php\iapis\Api; |
7
|
|
|
use icy2003\php\ihelpers\Arrays; |
8
|
|
|
use icy2003\php\ihelpers\Http; |
9
|
|
|
use icy2003\php\ihelpers\Json; |
10
|
|
|
|
11
|
|
|
class Auth extends Api |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
public function __construct($appid, $secret) |
15
|
|
|
{ |
16
|
|
|
$this->setOption('appid', $appid); |
17
|
|
|
$this->setOption('secret', $secret); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function isSuccess() |
21
|
|
|
{ |
22
|
|
|
if (0 === I::get($this->_result, 'errcode', 0)) { |
23
|
|
|
return true; |
24
|
|
|
} |
25
|
|
|
return false; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function getError() |
29
|
|
|
{ |
30
|
|
|
return [ |
31
|
|
|
'errcode' => I::get($this->_result, 'errcode', 0), |
32
|
|
|
'errmsg' => I::get($this->_result, 'errmsg', ''), |
33
|
|
|
]; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function getAccessToken() |
37
|
|
|
{ |
38
|
|
|
$this->setOption('grant_type', 'client_credential'); |
39
|
|
|
$this->_result = Json::decode(Http::get('https://api.weixin.qq.com/cgi-bin/token', $this->filterOptions([ |
|
|
|
|
40
|
|
|
'grant_type', 'appid', 'secret', |
41
|
|
|
]))); |
42
|
|
|
$this->_toArrayCall = function ($array) { |
43
|
|
|
return Arrays::columns1($array, ['access_token', 'expires_in']); |
44
|
|
|
}; |
45
|
|
|
|
46
|
|
|
return $this; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function code2Session($code) |
50
|
|
|
{ |
51
|
|
|
$this->setOption('grant_type', 'authorization_code'); |
52
|
|
|
$this->setOption('js_code', $code); |
53
|
|
|
$this->_result = Json::decode(Http::get('https://api.weixin.qq.com/sns/jscode2session', $this->filterOptions([ |
|
|
|
|
54
|
|
|
'appid', 'secret', 'js_code', 'grant_type', |
55
|
|
|
]))); |
56
|
|
|
// 这个接口返回没有 errcode |
57
|
|
|
$this->_toArrayCall = function ($array) { |
58
|
|
|
return Arrays::columns1($array, ['openid', 'session_key', 'unionid']); |
59
|
|
|
}; |
60
|
|
|
|
61
|
|
|
return $this; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.