Beispiel #1
0
        public Msger(bool useApi = true, bool useGet = true, bool isBuffer = false, int numsBuffer = 100)
        {
            _IsBuffer   = isBuffer;
            _NumsBuffer = numsBuffer;

            _Tag     = "None";
            _TypeMsg = typeMsger.None;
            _useApi  = useApi;
            _useGet  = useGet;
        }
Beispiel #2
0
        /// <summary>返回消息
        /// </summary>
        /// <param name="text"></param>
        /// <param name="msgSrc"></param>
        /// <param name="typeMsg"></param>
        /// <returns></returns>
        public virtual Msg _ReturnMsg(string text, Msg msgSrc, typeMsg typeMsg, string msgTag = "")
        {
            string    userID_To = msgSrc.UserName_src;
            typeMsger typeMsger = msgSrc.usrPlat;

            //修正消息
            bool   isGroup  = msgSrc.IsUserGroup;
            string usrGroup = msgSrc.GetNameGroup();
            string usrName  = msgSrc.GetNameUser();

            if (_Permission.Check_Permission_SysUsr(usrName, msgSrc.usrPlat.ToString()) ||
                !this._Permission.Check_Permission_SingleSet(usrGroup, usrName, msgSrc.usrPlat.ToString()))
            {
                //查询用户信息--系统管理员屏蔽
                userID_To = "filehelper";       //非独立设置调整为发送Helper
                isGroup   = false;

                //修正消息内容,现实群组信息
                string strTag = string.IsNullOrEmpty(msgTag) ? _Title : msgTag;
                if (msgSrc.IsUserGroup)
                {
                    string strMsg_Group = string.Format("{0}:〖{1}〗\n", strTag, msgSrc.GetNameGroup());
                    text = strMsg_Group + text;
                }
                else
                {
                    string strMsg_Group = string.Format("{0}:『{1}』\n", strTag, msgSrc.GetNameUser());
                    text = strMsg_Group + text;
                }
            }
            else
            {
                //添加文件头
                if (_hasTitle)
                {
                    if (typeMsg == typeMsg.TEXT)
                    {
                        string strTag = string.IsNullOrEmpty(msgTag) ? _Title : msgTag;
                        if (!strTag.Contains(":"))
                        {
                            strTag += ":";
                        }
                        text = strTag + "\n" + text;
                    }
                }
            }

            //生成消息
            Msg pMsgR = this.getMsg(text, userID_To, isGroup, typeMsg, typeMsger, msgTag);

            return(pMsgR);
        }
Beispiel #3
0
        /// <summary>发送消息(指定消息类型)
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="typeMsgs"></param>
        /// <param name="useMsgServer"></param>
        /// <returns></returns>
        public virtual bool SendMsg(dynamic msg, typeMsger typeMsg, bool useMsgServer = false)
        {
            IMsger msger = null;

            _MsgersObj.TryGetValue(typeMsg.ToString().ToLower(), out msger);

            if (msger != null)
            {
                bool bRes = msger.SendMsg(msg, useMsgServer);
                if (bRes)
                {
                    this.CacheMsg(msg);
                }
                return(bRes);
            }
            return(false);
        }
Beispiel #4
0
 /// <summary>消息通知
 /// </summary>
 /// <param name="msg"></param>
 /// <param name="userID_To"></param>
 /// <returns></returns>
 public virtual bool NotifyMsg(dynamic msg, string userID_To = "@*测试群", typeMsg typeMsg = typeMsg.TEXT, typeMsger typeMsger = typeMsger.wx)
 {
     if (msg + "" != null)
     {
         var pMsg = this.getMsg(msg, userID_To, false, typeMsg, typeMsger);
         if (pMsg != null)
         {
             MsgerHelper.Msger.SendMsg(pMsg, typeMsger);
         }
     }
     return(false);
 }
Beispiel #5
0
        //提取返回消息
        protected internal virtual Msger.Msg getMsg(string msg, string userID_To = "@*测试群", bool isUsrGroup = false, typeMsg typeMsg = typeMsg.TEXT, typeMsger typeMsger = typeMsger.wx, string msgTag = "")
        {
            if (msg + "" == "")
            {
                return(null);
            }
            if (userID_To + "" == "")
            {
                return(null);
            }
            if (typeMsger == typeMsger.None)
            {
                return(null);
            }

            //组装消息
            if (!isUsrGroup)
            {
                isUsrGroup = userID_To.Length > 2 && userID_To.Substring(0, 2) == "@*" ? true : isUsrGroup;
            }
            Msger.Msg pMsg = new Msger.Msg()
            {
                msgID        = "",
                msg          = msg + "",
                msgType      = typeMsg == typeMsg.NOTE ? typeMsg.TEXT : typeMsg,
                msgLink      = "",
                groupID      = isUsrGroup ? userID_To : "",
                usrName      = userID_To,
                usrNameNick  = userID_To,
                usrPlat      = typeMsger,
                UserName_src = _tag,
                msgTime      = DateTime.Now,
                msgTag       = msgTag,
                IsUserGroup  = isUsrGroup,
                IsFromRobot  = true,
                IsSend       = true
            };
            return(pMsg);
        }
Beispiel #6
0
 /// <summary>查找消息对象(按类型)
 /// </summary>
 /// <param name="typeMsg"></param>
 /// <returns></returns>
 public virtual IMsger Find(typeMsger typeMsg)
 {
     return(Find(typeMsg.ToString()));
 }