/// <summary>
        /// 
        /// </summary>
        /// <param name="appkey"></param>
        /// <param name="appSecret"></param>
        /// <param name="chatroomIdInfo">chatroomId=id1001</param>
        /// <returns></returns>
        public static String DestroyChatroom(String appkey, String appSecret, String[] chatroomIdInfo)
        {
            String postStr = null;

            postStr = buildParamStr(chatroomIdInfo);

            RongHttpClient client = new RongHttpClient(appkey, appSecret, InterfaceUrl.destroyChatroomUrl, postStr);

            return client.ExecutePost();
        }
        /// <summary>
        /// 广播消息暂时未开放
        /// </summary>
        /// <param name="appkey"></param>
        /// <param name="appSecret"></param>
        /// <param name="fromUserId"></param>
        /// <param name="objectName"></param>
        /// <param name="content">RC:TxtMsg消息格式{"content":"hello"}  RC:ImgMsg消息格式{"content":"ergaqreg", "imageKey":"http://www.demo.com/1.jpg"}  RC:VcMsg消息格式{"content":"ergaqreg","duration":3}</param>
        /// <returns></returns>
        public static String BroadcastMessage(String appkey, String appSecret, String fromUserId, String objectName, String content)
        {
            Dictionary<String, String> dicList = new Dictionary<String, String>();
            dicList.Add("content", content);
            dicList.Add("fromUserId", fromUserId);
            dicList.Add("objectName", objectName);
            dicList.Add("pushContent", "");
            dicList.Add("pushData", "");

            String postStr = buildQueryStr(dicList);
            RongHttpClient client = new RongHttpClient(appkey, appSecret, InterfaceUrl.broadcastUrl, postStr);

            return client.ExecutePost();
        }
        /// <summary>
        /// 获取Token
        /// </summary>
        /// <param name="appkey"></param>
        /// <param name="appSecret"></param>
        /// <param name="userId"></param>
        /// <param name="name"></param>
        /// <param name="portraitUri"></param>
        /// <returns></returns>
        public static async Task<string> GetTokenAsync(string appkey, string appSecret, string userId, string name, string portraitUri)
        {
            var dicList = new Dictionary<string, string>
            {
                {"userId", userId},
                {"name", name},
                {"portraitUri", portraitUri}
            };

            var postStr = BuildQueryStr(dicList);

            var client = new RongHttpClient(appkey, appSecret, InterfaceUrl.GetTokenUrl, postStr);

            return await client.ExecutePostAsync().ConfigureAwait(false);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="appkey"></param>
        /// <param name="appSecret"></param>
        /// <param name="chatroomInfo">chatroom[id10001]=name1001</param>
        /// <returns></returns>
        public static String CreateChatroom(String appkey, String appSecret, String[] chatroomId, String[] chatroomName)
        {
            String postStr = null;

            String id, name;

            for (int i = 0; i < chatroomId.Length; i++)
            {
                id = HttpUtility.UrlEncode(chatroomId[i], Encoding.UTF8);
                name = HttpUtility.UrlEncode(chatroomName[i], Encoding.UTF8);
                postStr += "chatroom[" + id + "]=" + name + "&";
            }

            postStr = postStr.Substring(0, postStr.LastIndexOf('&'));

            RongHttpClient client = new RongHttpClient(appkey, appSecret, InterfaceUrl.createChatroomUrl, postStr);

            return client.ExecutePost();
        }
        /**
         * 解散 群组
         */
        public static String DismissGroup(String appkey, String appSecret, String userId, String groupId)
        {
            Dictionary<String, String> dicList = new Dictionary<String, String>();
            dicList.Add("userId", userId);
            dicList.Add("groupId", groupId);

            String postStr = buildQueryStr(dicList);

            RongHttpClient client = new RongHttpClient(appkey, appSecret, InterfaceUrl.dismissUrl, postStr);

            return client.ExecutePost();
        }
        /**
         * 同步群组
         */
        public static String syncGroup(String appkey, String appSecret, String userId, String[] groupId, String[] groupName)
        {
            String postStr = "userId=" + userId + "&";
            String id, name;

            for (int i = 0; i < groupId.Length; i++)
            {
                id = HttpUtility.UrlEncode(groupId[i], Encoding.UTF8);
                name = HttpUtility.UrlEncode(groupName[i], Encoding.UTF8);
                postStr += "group[" + id + "]=" + name + "&";
            }

            postStr = postStr.Substring(0, postStr.LastIndexOf('&'));

            RongHttpClient client = new RongHttpClient(appkey, appSecret, InterfaceUrl.syncGroupUrl, postStr);

            return client.ExecutePost();
        }
        /**
         * 获取 token
         */
        public static String GetToken(String appkey,String appSecret,String userId, String name, String portraitUri)
        {
            Dictionary<String, String> dicList = new Dictionary<String, String>();
            dicList.Add("userId", userId);
            dicList.Add("name", name);
            dicList.Add("portraitUri", portraitUri);

            String postStr = buildQueryStr(dicList);

            RongHttpClient client = new RongHttpClient(appkey, appSecret, InterfaceUrl.getTokenUrl, postStr);

            return client.ExecutePost();
        }
        /// <summary>
        /// 加入群组
        /// </summary>
        /// <param name="appkey"></param>
        /// <param name="appSecret"></param>
        /// <param name="userId"></param>
        /// <param name="groupId"></param>
        /// <param name="groupName"></param>
        /// <returns></returns>
        public static async Task<string> JoinGroupAsync(string appkey, string appSecret, string userId, string groupId, string groupName)
        {
            var dicList = new Dictionary<string, string>
            {
                {"userId", userId},
                {"groupId", groupId},
                {"groupName", groupName}
            };

            var postStr = BuildQueryStr(dicList);

            var client = new RongHttpClient(appkey, appSecret, InterfaceUrl.JoinGroupUrl, postStr);

            return await client.ExecutePostAsync().ConfigureAwait(false);
        }
        /// <summary>
        /// 查询聊天室
        /// </summary>
        /// <param name="appkey"></param>
        /// <param name="appSecret"></param>
        /// <param name="chatroomId"></param>
        /// <returns></returns>
        public static async Task<string> QueryChatroomAsync(string appkey, string appSecret, string[] chatroomId)
        {
            var postStr = BuildParamStr(chatroomId);

            var client = new RongHttpClient(appkey, appSecret, InterfaceUrl.QueryChatroomUrl, postStr);

            return await client.ExecutePostAsync().ConfigureAwait(false);
        }
        /// <summary>
        /// 创建聊天室
        /// </summary>
        /// <param name="appkey"></param>
        /// <param name="appSecret"></param>
        /// <param name="chatroomId"></param>
        /// <param name="chatroomName"></param>
        /// <returns></returns>
        public static async Task<string> CreateChatroomAsync(string appkey, string appSecret, string[] chatroomId, string[] chatroomName)
        {
            string postStr = null;

            for (var i = 0; i < chatroomId.Length; i++)
            {
                var id = HttpUtility.UrlEncode(chatroomId[i], Encoding.UTF8);
                var name = HttpUtility.UrlEncode(chatroomName[i], Encoding.UTF8);
                postStr += "chatroom[" + id + "]=" + name + "&";
            }

            postStr = postStr.Substring(0, postStr.LastIndexOf('&'));

            var client = new RongHttpClient(appkey, appSecret, InterfaceUrl.CreateChatroomUrl, postStr);

            return await client.ExecutePostAsync().ConfigureAwait(false);
        }
        /// <summary>
        /// 广播消息暂时未开放
        /// </summary>
        /// <param name="appkey"></param>
        /// <param name="appSecret"></param>
        /// <param name="fromUserId"></param>
        /// <param name="objectName"></param>
        /// <param name="content">
        ///     RC:TxtMsg消息格式{"content":"hello"}  RC:ImgMsg消息格式{"content":"ergaqreg",
        ///     "imageKey":"http://www.demo.com/1.jpg"}  RC:VcMsg消息格式{"content":"ergaqreg","duration":3}
        /// </param>
        /// <returns></returns>
        public static async Task<string> BroadcastMessageAsync(string appkey, string appSecret, string fromUserId, string objectName,
            string content)
        {
            var dicList = new Dictionary<string, string>
            {
                {"content", content},
                {"fromUserId", fromUserId},
                {"objectName", objectName},
                {"pushContent", ""},
                {"pushData", ""}
            };

            var postStr = BuildQueryStr(dicList);
            var client = new RongHttpClient(appkey, appSecret, InterfaceUrl.BroadcastUrl, postStr);

            return await client.ExecutePostAsync().ConfigureAwait(false);
        }
        /// <summary>
        /// 同步群组
        /// </summary>
        /// <param name="appkey"></param>
        /// <param name="appSecret"></param>
        /// <param name="userId"></param>
        /// <param name="groupId"></param>
        /// <param name="groupName"></param>
        /// <returns></returns>
        public static async Task<string> SyncGroupAsync(string appkey, string appSecret, string userId, string[] groupId,
            string[] groupName)
        {
            var postStr = "userId=" + userId + "&";

            for (var i = 0; i < groupId.Length; i++)
            {
                var id = HttpUtility.UrlEncode(groupId[i], Encoding.UTF8);
                var name = HttpUtility.UrlEncode(groupName[i], Encoding.UTF8);
                postStr += "group[" + id + "]=" + name + "&";
            }

            postStr = postStr.Substring(0, postStr.LastIndexOf('&'));

            var client = new RongHttpClient(appkey, appSecret, InterfaceUrl.SyncGroupUrl, postStr);

            return await client.ExecutePostAsync().ConfigureAwait(false);
        }
Пример #13
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="appkey"></param>
        /// <param name="appSecret"></param>
        /// <param name="fromUserId"></param>
        /// <param name="toUserId"></param>
        /// <param name="objectName"></param>
        /// <param name="content">RC:TxtMsg消息格式{"content":"hello"}  RC:ImgMsg消息格式{"content":"ergaqreg", "imageKey":"http://www.demo.com/1.jpg"}  RC:VcMsg消息格式{"content":"ergaqreg","duration":3}</param>
        /// <returns></returns>
        public static String PublishMessage(String appkey, String appSecret, String fromUserId, String toUserId, String objectName, String content)
        {
            Dictionary<String, String> dicList = new Dictionary<String, String>();
            dicList.Add("fromUserId", fromUserId);
            dicList.Add("toUserId", toUserId);
            dicList.Add("objectName", objectName);
            dicList.Add("content", content);

            String postStr = buildQueryStr(dicList);

            RongHttpClient client = new RongHttpClient(appkey, appSecret, InterfaceUrl.sendMsgUrl, postStr);

            return client.ExecutePost();
        }