1 | <?php |
||
2 | /** |
||
3 | * Class QQ |
||
4 | * |
||
5 | * @link https://www.icy2003.com/ |
||
6 | * @author icy2003 <[email protected]> |
||
7 | * @copyright Copyright (c) 2020, icy2003 |
||
8 | */ |
||
9 | namespace icy2003\php\iapis; |
||
10 | |||
11 | use icy2003\php\C; |
||
12 | use icy2003\php\I; |
||
13 | use icy2003\php\ihelpers\Charset; |
||
14 | use icy2003\php\ihelpers\Http; |
||
15 | use icy2003\php\ihelpers\Json; |
||
16 | use icy2003\php\ihelpers\Strings; |
||
17 | |||
18 | /** |
||
19 | * QQ 相关接口 |
||
20 | */ |
||
21 | class QQ extends Api |
||
22 | { |
||
23 | /** |
||
24 | |||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $_qq; |
||
29 | |||
30 | /** |
||
31 | * 初始化 |
||
32 | * |
||
33 | * @param string $qq |
||
34 | */ |
||
35 | public function __construct($qq) |
||
36 | { |
||
37 | C::assertTrue(preg_match('|^[1-9]\d{4,10}$|i', $qq) > 0, 'QQ 号格式错误'); |
||
38 | $this->_qq = $qq; |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * 获取 QQ 的昵称和头像地址 |
||
43 | * |
||
44 | * @param array $config 可设置头像规格,默认 3 |
||
45 | * - 1~5 分别表示 `40*40`, `40*40`, `100*100`, `140*140`, `640*640` |
||
46 | * |
||
47 | * @return static |
||
48 | */ |
||
49 | public function fetchInfo($config = ['spec'=>3]) |
||
50 | { |
||
51 | $result = Http::get('http://users.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg', [ |
||
52 | 'uins' => $this->_qq, |
||
53 | ]); |
||
54 | if (Strings::isContains($result, 'portraitCallBack')) { |
||
55 | $json = Json::decode(Strings::partBetween($result, 'portraitCallBack(', ')')); |
||
56 | $this->_result['nickname'] = Charset::toUtf(I::get($json, $this->_qq . '.6'), 'GBK'); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
57 | } |
||
58 | $this->_result['portrait'] = 'https://q2.qlogo.cn/headimg_dl?dst_uin='.$this->_qq.'&spec='. I::get($config, 'spec', 3); |
||
59 | |||
60 | return $this; |
||
61 | } |
||
62 | } |