TestsLing /
easy-im
| 1 | <?php |
||
| 2 | |||
| 3 | namespace EasyIM\TencentIM\Group; |
||
| 4 | |||
| 5 | use EasyIM\Kernel\BaseClient; |
||
| 6 | use EasyIM\Kernel\Exceptions\InvalidArgumentException; |
||
| 7 | use EasyIM\Kernel\Exceptions\InvalidConfigException; |
||
| 8 | use EasyIM\Kernel\ParameterList; |
||
| 9 | use EasyIM\Kernel\Support\Arr; |
||
| 10 | use EasyIM\Kernel\Support\Collection; |
||
| 11 | use EasyIM\TencentIM\Group\Parameter\Member\ResponseFilterParameter; |
||
| 12 | use EasyIM\TencentIM\Kernel\Constant\GroupConstant; |
||
| 13 | use GuzzleHttp\Exception\GuzzleException; |
||
| 14 | use Psr\Http\Message\ResponseInterface; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Class MemberClient |
||
| 18 | * |
||
| 19 | * @package EasyIM\TencentIM\Group |
||
| 20 | * @author yingzhan <[email protected]> |
||
| 21 | * |
||
| 22 | */ |
||
| 23 | class MemberClient extends BaseClient |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * Get group member details. |
||
| 27 | * |
||
| 28 | * @param string $groupId |
||
| 29 | * @param int $limit |
||
| 30 | * @param int $offset |
||
| 31 | * @param array $memberInfo |
||
| 32 | * @param array $memberRole |
||
| 33 | * @param array $appDefinedDataMember |
||
| 34 | * |
||
| 35 | * @return array|Collection|object|ResponseInterface|string |
||
| 36 | * @throws InvalidConfigException |
||
| 37 | * @throws GuzzleException |
||
| 38 | */ |
||
| 39 | public function getMember( |
||
| 40 | string $groupId, |
||
| 41 | int $limit = 100, |
||
| 42 | int $offset = 0, |
||
| 43 | array $memberInfo = [], |
||
| 44 | array $memberRole = [], |
||
| 45 | array $appDefinedDataMember = [] |
||
| 46 | ) { |
||
| 47 | $params['GroupId'] = $groupId; |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
| 48 | Arr::setNotNullValue($params, 'MemberInfoFilter', $memberInfo); |
||
| 49 | Arr::setNotNullValue($params, 'MemberRoleFilter', $memberRole); |
||
| 50 | Arr::setNotNullValue($params, 'AppDefinedDataFilter_GroupMember', $appDefinedDataMember); |
||
| 51 | Arr::setNotNullValue($params, 'Limit', $limit); |
||
| 52 | Arr::setNotNullValue($params, 'Offset', $offset); |
||
| 53 | |||
| 54 | return $this->httpPostJson('group_open_http_svc/get_group_member_info', $params); |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Increase group members. |
||
| 59 | * |
||
| 60 | * @param string $groupId |
||
| 61 | * @param ParameterList $memberList ...MemberListParameter |
||
| 62 | * @param int $silence |
||
| 63 | * |
||
| 64 | * @return array|Collection|object|ResponseInterface|string |
||
| 65 | * @throws InvalidArgumentException |
||
| 66 | * @throws InvalidConfigException |
||
| 67 | * @throws GuzzleException |
||
| 68 | */ |
||
| 69 | public function addMember(string $groupId, ParameterList $memberList, int $silence = 0) |
||
| 70 | { |
||
| 71 | $params = [ |
||
| 72 | 'GroupId' => $groupId, |
||
| 73 | 'MemberList' => $memberList->transformParameterToArray() |
||
| 74 | ]; |
||
| 75 | Arr::setNotNullValue($params, 'Silence', $silence); |
||
| 76 | |||
| 77 | return $this->httpPostJson('group_open_http_svc/add_group_member', $params); |
||
| 78 | } |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Delete group members. |
||
| 82 | * |
||
| 83 | * @param string $groupId |
||
| 84 | * @param array $memberList |
||
| 85 | * @param int $silence |
||
| 86 | * @param string|null $reason |
||
| 87 | * |
||
| 88 | * @return array|Collection|object|ResponseInterface|string |
||
| 89 | * @throws InvalidConfigException |
||
| 90 | * @throws GuzzleException |
||
| 91 | */ |
||
| 92 | public function deleteMember(string $groupId, array $memberList, int $silence = 0, string $reason = null) |
||
| 93 | { |
||
| 94 | $params = [ |
||
| 95 | 'GroupId' => $groupId, |
||
| 96 | 'MemberToDel_Account' => $memberList |
||
| 97 | ]; |
||
| 98 | Arr::setNotNullValue($params, 'Silence', $silence); |
||
| 99 | Arr::setNotNullValue($params, 'Reason', $reason); |
||
| 100 | |||
| 101 | return $this->httpPostJson('group_open_http_svc/delete_group_member', $params); |
||
| 102 | } |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Modify group member information. |
||
| 106 | * |
||
| 107 | * @param string $groupId |
||
| 108 | * @param string $memberAccount |
||
| 109 | * @param string|null $role |
||
| 110 | * @param string $msgFlag |
||
| 111 | * @param string|null $nameCard |
||
| 112 | * @param ParameterList|null $appDefinedDataMember ...CommonParameter |
||
| 113 | * @param int|null $shuntUpTime |
||
| 114 | * |
||
| 115 | * @return array|Collection|object|ResponseInterface|string |
||
| 116 | * @throws InvalidConfigException |
||
| 117 | * @throws GuzzleException |
||
| 118 | * @throws InvalidArgumentException |
||
| 119 | */ |
||
| 120 | public function modifyMember( |
||
| 121 | string $groupId, |
||
| 122 | string $memberAccount, |
||
| 123 | string $role = null, |
||
| 124 | string $msgFlag = GroupConstant::ACCEPT_AND_NOTIFY, |
||
| 125 | string $nameCard = null, |
||
| 126 | ParameterList $appDefinedDataMember = null, |
||
| 127 | int $shuntUpTime = null |
||
| 128 | ) { |
||
| 129 | $params = [ |
||
| 130 | 'GroupId' => $groupId, |
||
| 131 | 'Member_Account' => $memberAccount |
||
| 132 | ]; |
||
| 133 | Arr::setNotNullValue($params, 'Role', $role); |
||
| 134 | Arr::setNotNullValue($params, 'MsgFlag', $msgFlag); |
||
| 135 | Arr::setNotNullValue($params, 'NameCard', $nameCard); |
||
| 136 | Arr::setNotNullValue($params, 'AppMemberDefinedData', $appDefinedDataMember && $appDefinedDataMember()); |
||
| 137 | Arr::setNotNullValue($params, 'ShutUpTime', $shuntUpTime); |
||
| 138 | |||
| 139 | return $this->httpPostJson('group_open_http_svc/modify_group_member_info', $params); |
||
| 140 | } |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Get the group the user joined. |
||
| 144 | * |
||
| 145 | * @param string $memberAccount |
||
| 146 | * @param int $withHuge |
||
| 147 | * @param int $withNoActive |
||
| 148 | * @param int $limit |
||
| 149 | * @param int $offset |
||
| 150 | * @param string|null $type |
||
| 151 | * @param ResponseFilterParameter|null $filter |
||
| 152 | * |
||
| 153 | * @return array|Collection|object|ResponseInterface|string |
||
| 154 | * @throws InvalidArgumentException |
||
| 155 | * @throws InvalidConfigException |
||
| 156 | * @throws GuzzleException |
||
| 157 | */ |
||
| 158 | public function getJoined( |
||
| 159 | string $memberAccount, |
||
| 160 | int $withHuge = 0, |
||
| 161 | int $withNoActive = 0, |
||
| 162 | int $limit = 10, |
||
| 163 | int $offset = 0, |
||
| 164 | string $type = null, |
||
| 165 | ResponseFilterParameter $filter = null |
||
| 166 | ) { |
||
| 167 | $params = [ |
||
| 168 | 'Member_Account' => $memberAccount |
||
| 169 | ]; |
||
| 170 | Arr::setNotNullValue($params, 'WithHugeGroups', $withHuge); |
||
| 171 | Arr::setNotNullValue($params, 'WithNoActiveGroups', $withNoActive); |
||
| 172 | Arr::setNotNullValue($params, 'Limit', $limit); |
||
| 173 | Arr::setNotNullValue($params, 'Offset', $offset); |
||
| 174 | Arr::setNotNullValue($params, 'GroupType', $type); |
||
| 175 | Arr::setNotNullValue($params, 'ResponseFilter', $filter && $filter->transformToArray()); |
||
| 176 | |||
| 177 | return $this->httpPostJson('group_open_http_svc/get_joined_group_list', $params); |
||
| 178 | } |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Query the user's identity in the group. |
||
| 182 | * |
||
| 183 | * @param string $groupId |
||
| 184 | * @param array $memberAccount |
||
| 185 | * |
||
| 186 | * @return array|Collection|object|ResponseInterface|string |
||
| 187 | * @throws InvalidConfigException |
||
| 188 | * @throws GuzzleException |
||
| 189 | */ |
||
| 190 | public function getRole(string $groupId, array $memberAccount) |
||
| 191 | { |
||
| 192 | $params = [ |
||
| 193 | 'GroupId' => $groupId, |
||
| 194 | 'User_Account' => $memberAccount |
||
| 195 | ]; |
||
| 196 | |||
| 197 | return $this->httpPostJson('group_open_http_svc/get_role_in_group', $params); |
||
| 198 | } |
||
| 199 | } |
||
| 200 |