Example #1
0
        /// <summary>
        /// 发送系统消息方法(一个用户向一个或多个用户发送系统消息,单条消息最大 128k,会话类型为 SYSTEM。每秒钟最多发送 100 条消息,每次最多同时向 100 人发送,如:一次发送 100 人时,示为 100 条消息。)
        /// </summary>
        /// <param name="fromUserId">发送人用户 Id。(必传)</param>
        /// <param name="toUserId">接收用户 Id,提供多个本参数可以实现向多人发送消息,上限为 1000 人。(必传)</param>
        /// <param name="message">发送消息内容(必传)</param>
        /// <param name="pushContent">如果为自定义消息,定义显示的 Push 内容,内容中定义标识通过 values 中设置的标识位内容进行替换.如消息类型为自定义不需要 Push 通知,则对应数组传空值即可。(可选)</param>
        /// <param name="pushData">针对 iOS 平台为 Push 通知时附加到 payload 中,Android 客户端收到推送消息时对应字段名为 pushData。如不需要 Push 功能对应数组传空值即可。(可选)</param>
        /// <param name="isPersisted">当前版本有新的自定义消息,而老版本没有该自定义消息时,老版本客户端收到消息后是否进行存储,0 表示为不存储、 1 表示为存储,默认为 1 存储消息。(可选)</param>
        /// <param name="isCounted">当前版本有新的自定义消息,而老版本没有该自定义消息时,老版本客户端收到消息后是否进行未读消息计数,0 表示为不计数、 1 表示为计数,默认为 1 计数,未读消息数增加 1。(可选)</param>
        public async Task <CodeSuccessReslut> PublishSystem(string fromUserId, string[] toUserId, TxtMessage message, String pushContent, String pushData, int isPersisted, int isCounted)
        {
            if (string.IsNullOrEmpty(fromUserId))
            {
                throw new ArgumentNullException(nameof(fromUserId));
            }
            if (toUserId == null)
            {
                throw new ArgumentNullException(nameof(toUserId));
            }

            string postStr = "";

            postStr += "fromUserId=" + WebUtility.UrlEncode(fromUserId == null ? "" : fromUserId) + "&";
            for (int i = 0; i < toUserId.Length; i++)
            {
                string child = toUserId[i];
                postStr += "toUserId=" + WebUtility.UrlEncode(child) + "&";
            }

            postStr += "objectName=" + WebUtility.UrlEncode(message.TYPE) + "&";
            postStr += "content=" + WebUtility.UrlEncode(message.ToString()) + "&";
            postStr += "pushContent=" + WebUtility.UrlEncode(pushContent == null ? "" : pushContent) + "&";
            postStr += "pushData=" + WebUtility.UrlEncode(pushData == null ? "" : pushData) + "&";
            postStr += "isPersisted=" + WebUtility.UrlEncode(Convert.ToString(isPersisted) == null ? "" : Convert.ToString(isPersisted)) + "&";
            postStr += "isCounted=" + WebUtility.UrlEncode(Convert.ToString(isCounted) == null ? "" : Convert.ToString(isCounted)) + "&";
            postStr  = postStr.Substring(0, postStr.LastIndexOf('&'));

            return(JsonConvert.DeserializeObject <CodeSuccessReslut>(await RongHttpClient.ExecutePost(appKey, appSecret, RongCloud.RONGCLOUDURI + "/message/system/publish.json", postStr, "application/x-www-form-urlencoded")));
        }
Example #2
0
        /// <summary>
        /// 发送广播消息方法(发送消息给一个应用下的所有注册用户,如用户未在线会对满足条件(绑定手机终端)的用户发送 Push 信息,单条消息最大 128k,会话类型为 SYSTEM。每小时只能发送 1 次,每天最多发送 3 次。)
        /// </summary>
        /// <param name="fromUserId">发送人用户 Id(必传)</param>
        /// <param name="message">文本消息</param>
        /// <param name="pushContent">定义显示的 Push 内容,如果 objectName 为融云内置消息类型时,则发送后用户一定会收到 Push 信息. 如果为自定义消息,则 pushContent 为自定义消息显示的 Push 内容,如果不传则用户不会收到 Push 通知.(可选)</param>
        /// <param name="pushData">针对 iOS 平台为 Push 通知时附加到 payload 中,Android 客户端收到推送消息时对应字段名为 pushData。(可选)</param>
        /// <param name="os">针对操作系统发送 Push,值为 iOS 表示对 iOS 手机用户发送 Push ,为 Android 时表示对 Android 手机用户发送 Push ,如对所有用户发送 Push 信息,则不需要传 os 参数。(可选)</param>
        public async Task <CodeSuccessReslut> Broadcast(string fromUserId, TxtMessage message, string pushContent, String pushData, String os)
        {
            if (fromUserId == null)
            {
                throw new ArgumentNullException(nameof(fromUserId));
            }

            string postStr = "";

            postStr += "fromUserId=" + WebUtility.UrlEncode(fromUserId == null ? "" : fromUserId) + "&";
            postStr += "objectName=" + WebUtility.UrlEncode(message.TYPE) + "&";
            postStr += "content=" + WebUtility.UrlEncode(message.ToString()) + "&";
            postStr += "pushContent=" + WebUtility.UrlEncode(pushContent == null ? "" : pushContent) + "&";
            postStr += "pushData=" + WebUtility.UrlEncode(pushData == null ? "" : pushData) + "&";
            postStr += "os=" + WebUtility.UrlEncode(os == null ? "" : os) + "&";
            postStr  = postStr.Substring(0, postStr.LastIndexOf('&'));

            return(JsonConvert.DeserializeObject <CodeSuccessReslut>(await RongHttpClient.ExecutePost(appKey, appSecret, RongCloud.RONGCLOUDURI + "/message/broadcast.json", postStr, "application/x-www-form-urlencoded")));
        }