计算机网络 npm deployment webview variant null swift2 郑州网站开发 pmp视频教程下载 jquery解析json jquery删除子元素 rxjava线程切换 python程序界面 ubuntu更改文件夹权限 css选择器有几种 linuxmysql启动命令 kubernetes视频教程 kubernetes入门 python使用教程 javamysql java教学 java8函数式接口 java基础课程 java数组追加 java查看变量类型 微信签名一句话至自己 oxm 风火云 js小数点保留2位 万能播放器电脑版 js动态添加元素 流媒体下载 网页之家 小米开发者选项 摸摸头不哭表情包 谷歌浏览器升级 gif动画制作工具 win10工作组 怎么用打印机扫描文件 ofd文件阅读器
当前位置: 首页 > 学习教程  > 编程语言

springBoot 集成第三方融云设置群组

2020/12/5 10:55:25 文章标签:

我不写代码&#xff0c;我只是代码的搬运工。 1.首先引入maven <!-- 融云SDK --><dependency><groupId>cn.rongcloud.im</groupId><artifactId>server-sdk-java</artifactId><version>3.1.14</version></dependency>2.…

我不写代码,我只是代码的搬运工。

1.首先引入maven

		<!-- 融云SDK -->
		<dependency>
			<groupId>cn.rongcloud.im</groupId>
			<artifactId>server-sdk-java</artifactId>
			<version>3.1.14</version>
		</dependency>

2.设置群组操作

public class GroupUtil {
	// 此处替换成您的appKey
	private static final String appKey = RY_App_Key;
	// 此处替换成您的appSecret
	private static final String appSecret = RY_App_Secret;
	private static final RongCloud rongCloud = RongCloud.getInstance(appKey, appSecret);
	private static final Group Group = rongCloud.group;

	/**
	 * 创建群组方法
	 */
	public static String groupCreate(String userId, String username, String groupId, String groupTitle) {

		GroupMember[] members = { new GroupMember().setId(userId) };
		GroupModel group = new GroupModel().setId(groupId).setMembers(members).setName(groupTitle);
		Result groupCreateResult;
		try {
			groupCreateResult = (Result) Group.create(group);
			System.out.println("group create result:  " + groupCreateResult.toString());
			RyMessage.sendMessage(groupId, username + "创建群组");
			return groupCreateResult.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * 邀请用户加入群组
	 * 
	 * @param userId
	 * @param username
	 * @param groupId
	 * @param groupTitle
	 * @return
	 */
	public static String inviteMembersJoinGroup(String userId, String inviteUsername, String beInviteUsername,
			String groupId, String groupTitle) {
		GroupMember[] members = { new GroupMember().setId(userId) };
		GroupModel group = new GroupModel().setId(groupId).setMembers(members).setName(groupTitle);
		Result groupInviteResult;
		try {
			groupInviteResult = (Result) rongCloud.group.invite(group);
			System.out.println("invite:  " + groupInviteResult.toString());
			RyMessage.sendMessage(groupId, "\"" + inviteUsername + "\" 邀请 \"" + beInviteUsername + "\" 进入群组");
			return groupInviteResult.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * 用户加入指定群组
	 */
	public static String joinGroup(String userId, String username, String groupId, String groupTitle) {
		GroupMember[] members = { new GroupMember().setId(userId) };
		GroupModel group = new GroupModel().setId(groupId).setMembers(members).setName(groupTitle);
		Result groupJoinResult;
		try {
			groupJoinResult = (Result) Group.join(group);
			RyMessage.sendMessage(groupId, username + "加入群组");
			System.out.println("join:  " + groupJoinResult.toString());
			return groupJoinResult.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * 查询群成员方法
	 *
	 */
	public static String listGroupUser(String groupId) {
		GroupModel group = new GroupModel().setId(groupId);
		GroupUserQueryResult getMemberesult;
		try {
			getMemberesult = Group.get(group);
			System.out.println("group getMember:  " + getMemberesult.toString());
			return getMemberesult.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * 刷新群组信息方法
	 * 
	 * @param groupId
	 * @return
	 */
	public static String refreshGroup(String groupId, String groupName) {
		GroupModel group = new GroupModel().setId(groupId).setName(groupName);
		Result refreshResult;
		try {
			refreshResult = (Result) Group.update(group);
			System.out.println("refresh:  " + refreshResult.toString());
			return refreshResult.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * API 文档: http://www.rongcloud.cn/docs/server_sdk_api/group/group.html#quit
	 *
	 * 退出群组
	 *
	 */
	public static String quitGroupMembers(String userId, String username, String groupId, String groupName) {
		GroupMember[] members = { new GroupMember().setId(userId) };
		GroupModel group = new GroupModel().setId(groupId).setMembers(members).setName(groupName);
		Result groupQuitResult;
		try {
			groupQuitResult = (Result) Group.quit(group);
			RyMessage.sendMessage(groupId, username + " 退出群组");
			System.out.println("refresh:  " + groupQuitResult.toString());
			return groupQuitResult.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * 解散群组
	 * 
	 * @param userId
	 * @param groupId
	 * @return
	 */
	public static String dismissGroup(String userId, String groupId) {
		GroupMember[] members = new GroupMember[] { new GroupMember().setId(userId) };
		GroupModel group = new GroupModel().setId(groupId).setMembers(members);
		Result groupDismissResult;
		try {
			groupDismissResult = (Result) Group.dismiss(group);
			System.out.println("refresh:  " + groupDismissResult.toString());
			return groupDismissResult.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * 邀请用户加入群组
	 */

	public static String invitedJoinGroup(String userId, String username, String groupId, String groupName) {
		GroupMember[] members = new GroupMember[] { new GroupMember().setId(userId) };
		GroupModel group = new GroupModel().setId(groupId).setMembers(members).setName(groupName);
		Result groupInviteResult;
		try {
			groupInviteResult = (Result) rongCloud.group.invite(group);
			System.out.println("invite:  " + groupInviteResult.toString());
			RyMessage.sendMessage(groupId, username + "邀请用户加入群组");
			return groupInviteResult.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	}
}

本文链接: http://www.dtmao.cc/news_show_450351.shtml

附件下载

相关教程

    暂无相关的数据...

共有条评论 网友评论

验证码: 看不清楚?