V2TIMGroupMemberFullInfo
,内含群成员 userID、自定义信息、角色、禁言等信息。getGroupMembersInfo
(Android / iOS & Mac / Windows) 获取群成员资料。该接口支持批量获取,您可以一次传入多个 userID
获取多个群成员的资料,从而提升网络传输效率。List<String> userIDList = new ArrayList<>();userIDList.add("userA");userIDList.add("userB");V2TIMManager.getGroupManager().getGroupMembersInfo("groupA", userIDList, new V2TIMValueCallback<List<V2TIMGroupMemberFullInfo>>() {@Overridepublic void onSuccess(List<V2TIMGroupMemberFullInfo> v2TIMGroupMemberFullInfos) {// 获取成功}@Overridepublic void onError(int code, String desc) {// 获取失败}});
[[V2TIMManager sharedInstance] getGroupMembersInfo:@"groupA" memberList:@[@"user1"] succ:^(NSArray<V2TIMGroupMemberFullInfo *> *memberList) {// 获取成功} fail:^(int code, NSString *desc) {// 获取失败}];
template <class T>class ValueCallback final : public V2TIMValueCallback<T> {public:using SuccessCallback = std::function<void(const T&)>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;ValueCallback() = default;~ValueCallback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess(const T& value) override {if (success_callback_) {success_callback_(value);}}void OnError(int error_code, const V2TIMString& error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;};V2TIMString groupID = "groupA";V2TIMStringVector memberList;memberList.PushBack("userA");memberList.PushBack("userB");auto callback = new ValueCallback<V2TIMGroupMemberFullInfoVector>{};callback->SetCallback([=](const V2TIMGroupMemberFullInfoVector& groupMemberFullInfoList) {// 获取成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 获取失败delete callback;});V2TIMManager::GetInstance()->GetGroupManager()->GetGroupMembersInfo(groupID, memberList, callback);
setGroupMemberInfo
(Android / iOS & Mac / Windows) 接口修改群成员的群名片(nameCard
)、自定义字段(customInfo
)等与群成员相关的资料。setGroupMemberInfo
设置自己的群名片(nameCard
)、自定义字段(customInfo
)等信息。V2TIMGroupMemberFullInfo memberFullInfo = new V2TIMGroupMemberFullInfo();// 指定修改的群成员memberFullInfo.setUserID("userA");// 设置修改的 nameCard 值memberFullInfo.setNameCard("userA_namecard");// 设置群成员自定义字段Map<String, byte[]> customMap = new HashMap<>();customMap.put("member_key1", "value1".getBytes());memberFullInfo.setCustomInfo(customMap);V2TIMManager.getGroupManager().setGroupMemberInfo("groupA", memberFullInfo, new V2TIMCallback() {@Overridepublic void onSuccess() {// 修改成功}@Overridepublic void onError(int code, String desc) {// 修改失败}});
V2TIMGroupMemberFullInfo *memberFullInfo = [[V2TIMGroupMemberFullInfo alloc] init];// 指定修改的群成员memberFullInfo.userID = @"user1";// 设置修改的 nameCard 值memberFullInfo.nameCard = @"user1_namecard";// 设置群成员自定义字段memberFullInfo.customInfo = @{@"member_key1" : [@"value1" dataUsingEncoding:NSUTF8StringEncoding]};[[V2TIMManager sharedInstance] setGroupMemberInfo:@"groupA" info:memberFullInfo succ:^{// 修改成功} fail:^(int code, NSString *desc) {// 修改失败}];
class Callback final : public V2TIMCallback {public:using SuccessCallback = std::function<void()>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;Callback() = default;~Callback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess() override {if (success_callback_) {success_callback_();}}void OnError(int error_code, const V2TIMString& error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;};// 指定修改的群成员V2TIMGroupMemberFullInfo info;info.userID = "userA";// 设置修改的 nameCard 值info.nameCard = "userA_namecard";info.modifyFlag = V2TIMGroupMemberInfoModifyFlag::V2TIM_GROUP_MEMBER_INFO_MODIFY_FLAG_NAME_CARD;// 设置群成员自定义字段V2TIMCustomInfo customInfo;std::string str{u8"value1"};customInfo.Insert("member_key1", {reinterpret_cast<const uint8_t*>(str.data()), str.size()});info.customInfo = customInfo;info.modifyFlag |= V2TIMGroupMemberInfoModifyFlag::V2TIM_GROUP_MEMBER_INFO_MODIFY_FLAG_CUSTOM_INFO;auto callback = new Callback;callback->SetCallback([=]() {// 修改成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 修改失败delete callback;});V2TIMManager::GetInstance()->GetGroupManager()->SetGroupMemberInfo("userA", info, callback);
本页内容是否解决了您的问题?