Client   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 131
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 30
c 1
b 0
f 0
dl 0
loc 131
ccs 0
cts 29
cp 0
rs 10
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A accountImport() 0 10 1
A accountCheck() 0 15 2
A multiAccountImport() 0 7 1
A kick() 0 7 1
A accountDelete() 0 15 2
A queryState() 0 8 1
1
<?php
2
3
namespace EasyIM\TencentIM\Account;
4
5
use EasyIM\Kernel\BaseClient;
6
use EasyIM\Kernel\Support\Arr;
7
8
/**
9
 * Class Client
10
 *
11
 * @package EasyIM\TencentIM\Account
12
 * @author  longing <[email protected]>
13
 */
14
class Client extends BaseClient
15
{
16
    /**
17
     * Import a single account.
18
     *
19
     * @param string $id
20
     * @param string $name
21
     * @param string $avatar
22
     *
23
     * @return array|\EasyIM\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
24
     * @throws \EasyIM\Kernel\Exceptions\InvalidConfigException
25
     * @throws \GuzzleHttp\Exception\GuzzleException
26
     */
27
    public function accountImport(string $id, string $name = null, string $avatar = null)
28
    {
29
        $params = [
30
            'Identifier' => $id
31
        ];
32
33
        Arr::setNotNullValue($params, 'Nick', $name);
34
        Arr::setNotNullValue($params, 'FaceUrl', $avatar);
35
36
        return $this->httpPostJson('im_open_login_svc/account_import', $params);
37
    }
38
39
    /**
40
     * Import multiple accounts.
41
     *
42
     * @param array $accounts
43
     *
44
     * @return array|\EasyIM\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
45
     * @throws \EasyIM\Kernel\Exceptions\InvalidConfigException
46
     * @throws \GuzzleHttp\Exception\GuzzleException
47
     */
48
    public function multiAccountImport(array $accounts)
49
    {
50
        $params = [
51
            'Accounts' => $accounts
52
        ];
53
54
        return $this->httpPostJson('im_open_login_svc/multiaccount_import', $params);
55
    }
56
57
    /**
58
     * Delete Account.
59
     *
60
     * @param array $accounts
61
     *
62
     * @return array|\EasyIM\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
63
     * @throws \EasyIM\Kernel\Exceptions\InvalidConfigException
64
     * @throws \GuzzleHttp\Exception\GuzzleException
65
     */
66
    public function accountDelete(array $accounts)
67
    {
68
        $accountList = [];
69
70
        foreach ($accounts as $user) {
71
            $accountList[]['UserID'] = $user;
72
        }
73
74
        unset($user);
75
76
        $params = [
77
            'DeleteItem' => $accountList
78
        ];
79
80
        return $this->httpPostJson('im_open_login_svc/account_delete', $params);
81
    }
82
83
    /**
84
     * Inquiry account number.
85
     *
86
     * @param array $accounts
87
     *
88
     * @return array|\EasyIM\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
89
     * @throws \EasyIM\Kernel\Exceptions\InvalidConfigException
90
     * @throws \GuzzleHttp\Exception\GuzzleException
91
     */
92
    public function accountCheck(array $accounts)
93
    {
94
        $accountList = [];
95
96
        foreach ($accounts as $user) {
97
            $accountList[]['UserID'] = $user;
98
        }
99
100
        unset($user);
101
102
        $params = [
103
            'CheckItem' => $accountList
104
        ];
105
106
        return $this->httpPostJson('im_open_login_svc/account_check', $params);
107
    }
108
109
    /**
110
     * Invalid account login status.
111
     *
112
     * @param string $id
113
     *
114
     * @return array|\EasyIM\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
115
     * @throws \EasyIM\Kernel\Exceptions\InvalidConfigException
116
     * @throws \GuzzleHttp\Exception\GuzzleException
117
     */
118
    public function kick(string $id)
119
    {
120
        $params = [
121
            'Identifier' => $id
122
        ];
123
124
        return $this->httpPostJson('im_open_login_svc/kick', $params);
125
    }
126
127
    /**
128
     * Query account online status.
129
     *
130
     * @param array $accounts
131
     * @param int   $isNeedDetail
132
     *
133
     * @return array|\EasyIM\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
134
     * @throws \EasyIM\Kernel\Exceptions\InvalidConfigException
135
     * @throws \GuzzleHttp\Exception\GuzzleException
136
     */
137
    public function queryState(array $accounts, int $isNeedDetail = 1)
138
    {
139
        $params = [
140
            'To_Account' => $accounts,
141
            'IsNeedDetail' => $isNeedDetail
142
        ];
143
144
        return $this->httpPostJson('openim/querystate', $params);
145
    }
146
}
147