/// <summary>
        /// 发送群组自定义消息
        /// 作者:郭明
        /// 日期:2016年8月20日
        /// </summary>
        /// <param name="GroupId"></param>
        /// <param name="From_Account"></param>
        /// <param name="Msg"></param>
        /// <returns></returns>
        public bool SendGroupCustomMsg <TMsgType>(string GroupId,
                                                  int From_Account,
                                                  IRequestIMCustomMsg <TMsgType> Msg
                                                  )
        {
            string Data = JsonHelper.ToJson(Msg.Data);

            dynamic obj = new
            {
                GroupId      = GroupId,
                From_Account = From_Account.ToString(), //指定消息发送者(选填)
                Random       = GlobalRandom,            //随机数(5分钟内不能重复)
                MsgBody      = new List <dynamic>()
                {
                    new
                    {
                        MsgType    = "TIMCustomElem",
                        MsgContent = new
                        {
                            Data = Data,
                            Desc = Msg.Desc,
                            Ext  = Msg.Ext
                        }
                    },
                }
            };

            return(Request(obj, "group_open_http_svc/send_group_msg"));
        }
        /// <summary>
        /// 发送自定义消息
        /// </summary>
        /// <param name="GroupId"></param>
        /// <returns></returns>
        public bool SendC2CCustomMsg <TMsgType>(string To_Account, IRequestIMCustomMsg <TMsgType> Msg)
        {
            string Data = JsonHelper.ToJson(Msg.Data);


            dynamic obj = new
            {
                SyncOtherMachine = 2,//消息不同步至发送方
                To_Account       = To_Account,
                MsgRandom        = GlobalRandom,
                MsgTimeStamp     = DateTime.Now.ToTimeStamp(),
                MsgBody          = new List <dynamic>
                {
                    new
                    {
                        MsgType    = "TIMCustomElem",
                        MsgContent = new
                        {
                            Data = Data,
                            Desc = Msg.Desc,
                            Ext  = Msg.Ext
                        }
                    }
                }
            };


            try
            {
                return(Request(obj, "openim/sendmsg"));
            }
            catch (InvalidToAccountException ex)
            {
                if (CreateMembers(new List <int>()
                {
                    To_Account.ToInt(0)
                }))
                {
                    return(Request(obj, "openim/sendmsg"));
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
        }
Exemple #3
0
        /// <summary>
        /// 批量发送自定义消息
        /// </summary>
        /// <param name="GroupId"></param>
        /// <returns></returns>
        public bool SendC2CBatchCustomMsg <TMsgType>(string[] To_Accounts, IRequestIMCustomMsg <TMsgType> Msg)
        {
            string Data = XuHos.Common.JsonHelper.ToJson(Msg.Data);

            dynamic obj = new
            {
                SyncOtherMachine = 2,//消息不同步至发送方
                To_Account       = To_Accounts,
                MsgRandom        = GlobalRandom,
                MsgTimeStamp     = DateTime.Now.ToTimeStamp(),
                MsgBody          = new List <dynamic>
                {
                    new
                    {
                        MsgType    = "TIMCustomElem",
                        MsgContent = new
                        {
                            Data = Data,
                            Desc = Msg.Desc,
                            Ext  = Msg.Ext
                        }
                    }
                }
            };

            try
            {
                return(Request(obj, "openim/batchsendmsg"));
            }
            catch (InvalidToAccountException ex)
            {
                if (CreateMembers(To_Accounts.Select(a => int.Parse(a)).ToList()))
                {
                    return(Request(obj, "openim/batchsendmsg"));
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
        }