Changes the group for all the specified users. Returns an array containing the OpenID's of the users that failed
to have their group changed.

@param array $userOpenIDs
@param int   $groupID

@return array
516211
public function changeAllGroups (array $userOpenIDs, $groupID)
    {
        if (count($userOpenIDs) < 1) {
            throw new InvalidArgumentException("At least one user is required.");
        }

        // Build requests.
        $requests = function ($users) use ($groupID) {
            foreach (array_chunk($users, 50) as $chunk) {
                yield new Request(
                    "POST",
                    "https://api.weixin.qq.com/cgi-bin/groups/members/batchupdate",
                    [],
                    json_encode([
                        'openid_list' => $chunk,
                        'to_groupid'  => $groupID,
                    ])
                );
            }
        };

        $failed = [];

        (new Pool(
            $this->client,
            $requests($userOpenIDs),
            [   
                'rejected' => function (RequestException $reason) use (&$failed) {
                    $json = json_decode((string)$reason->getRequest()->getBody());

                    if (isset($json->openid_list)) {
                        $failed = array_merge($failed, $json->openid_list);
                    }
                },
            ]
        ))->promise()->wait();

        return $failed;
    }
290510
public function getUserGroup($openid){
        if (!$this->access_token && !$this->checkAuth()) return false;
        $data = array(
                'openid'=>$openid
        );
        $result = $this->http_post(self::API_URL_PREFIX.self::USER_GROUP_URL.'access_token='.$this->access_token,self::json_encode($data));
        if ($result)
        {
            $json = json_decode($result,true);
            if (!$json || !empty($json['errcode'])) {
                $this->errCode = $json['errcode'];
                $this->errMsg = $json['errmsg'];
                return false;
            } else
                if (isset($json['groupid'])) return $json['groupid'];
        }
        return false;
    }
916824
public function removeUser($userId)
    {
        if (true === is_numeric($userId) && true === in_array($userId, $this->users)) {
            foreach (array_keys($this->users, (int)$userId, true) as $key) {
                unset($this->users[$key]);
            }
        }
        return $this;
    }
1036833
public function loadObjectStateGroupData($groupId)
    {
        try {
            return $this->innerGateway->loadObjectStateGroupData($groupId);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
152356
public function assignUser($userGroupId, $userId = [])
    {
        $this->groupId = $userGroupId;

        $this->getLogger()->info('Assigning User IDs ' . json_encode($userId) . ' To User Group ID ' . $this->groupId);
        $response = $this->doPost('/group/members/assign/' . $userGroupId, [
            'userId' => $userId
        ]);

        /** @var XiboUserGroup $userGroup */
        $userGroup = $this->hydrate($response);

        return $userGroup;
    }
569348
public function updateMemberGroup($openId, $toGroupId)
    {
        $result = $this->httpRaw(self::WECHAT_MEMBER_GROUP_UPDATE_URL . 'access_token=' . $this->getAccessToken(), [
            'openid' => $openId,
            'to_groupid' => $toGroupId
        ]);
        return isset($result['errmsg']) && $result['errmsg'] == 'ok';
    }
1065388
public function addGroup($group_id)
    {
        $successful = true;
        
        if ($group_id == null) {
            return false;
        }
        
        // Remove all existing group(s) from user
        $this->groups()->detach();
        
        // Assign group(s) to user
        if (is_array($group_id)) {
            // If multiple roles
            if (count($group_id) > 0) {
                foreach ($group_id as $item) {
                    $new_group = Group::find($item);
                    if ($new_group == null) {
                        $successful = false;
                    } else {
                        $this->groups()->save($new_group);
                    }
                }
            }
        } else {
            $new_group = Group::find($group_id);
            if ($new_group == null) {
                $successful = false;
            } else {
                $this->groups()->save($new_group);
            }
        }
        
        return $successful;
    }
621440
public function tryMatch(string $userOpenID)
    {
        $url = $this->getUrl('trymatch');
        $data = ['user_id' => $userOpenID];
        $request = urlencode(json_encode($data));
        $json = $this->curl->post($url, $request);

        return $json;
    }
583858
public function toOpenId($userId, $agentId)
    {
        $params = [
            'userid'  => $userId,
            'agentid' => $agentId,
        ];

        return $this->parseJSON('json', [self::API_TO_OPENID, $params]);
    }
675428
public function addUser($id, $userId)
    {
        $xml = new \SimpleXMLElement('<?xml version="1.0"?><user_id>'.$userId.'</user_id>');

        return $this->post('/groups/'.$id.'/users.xml', $xml->asXML());
    }
10727
public function moveUser($openid, $to_groupid)
    {
        if (!is_numeric($to_groupid) || !is_string($openid)) {
            $this->setError('参数错误,用户ID格式不正确或组ID不是数字');

            return false;
        }

        $queryStr = ['openid' => $openid, 'to_groupid' => $to_groupid];

        $res = $this->_post('members/update', $queryStr);

        return $res;
    }
443101
public function deleteAction($groupId)
    {
        $group = $this->get('open_orchestra_user.repository.group')->find($groupId);
        $this->denyAccessUnlessGranted(ContributionActionInterface::DELETE, $group);

        if ($group instanceof GroupInterface && $this->get('open_orchestra_backoffice.business_rules_manager')->isGranted(BusinessActionInterface::DELETE, $group)) {
            $objectManager = $this->get('object_manager');
            $objectManager->remove($group);
            $objectManager->flush();
            $this->dispatchEvent(GroupEvents::GROUP_DELETE, new GroupEvent($group));
        }

        return array();
    }
359993
public function getGroup($groupId)
    {
        static $groups = array();

        if (! isset($groups[$groupId])) {
            $groups[$groupId] = $this->_loadClass('Group', true, array($groupId));
    }

        return $groups[$groupId];
    }
1174944
public function updateGroup($groupId)
    {
        $group = wei()->group()->findOrInitById($groupId);
        $ret = wei()->event->until('groupMove', [[$this['id']], $group]);
        if ($ret) {
            return $ret;
        }

        $this->save(['groupId' => $groupId]);

        return ['code' => 1, 'message' => '操作成功'];
    }
1071297
public function getGroup(string $groupid)
    {
        $cl = $this->getGroupClass();
        $group = new $cl;
        return $group->obtainByGroupID($groupid);
    }
1182155
public function getUserCapabilities(string $userId): array
    {
        if (empty($this->userCapabilities)) {
            $this->userCapabilities = Utils::fetchUserCapabilities($userId);
        }

        return $this->userCapabilities;
    }
548188
public function addUser($userId)
    {
        if (true === is_numeric($userId) && false === in_array($userId, $this->users)) {
            $this->users[] = (int)$userId;
        }
        return $this;
    }