Ejemplo n.º 1
0
        /// <summary>
        /// 处理文本消息
        /// </summary>
        /// <param name="msg">消息对象</param>
        /// <param name="args">参数(用于具体业务传递参数用)</param>
        /// <returns>是否处理成功</returns>
        public bool ProcessTextMessage(TextReceiveMessage msg, params object[] args)
        {
            if (msg.Content.StartsWith("#ly#"))
            {
                var usermodel = WeiXin.GetUserInfo(msg.FromUserName);
                if (usermodel != null)
                {
                    new Eyousoft_yhq.BLL.BCustomMsg().Add(new Eyousoft_yhq.Model.CustomMsg()
                    {
                        OpenId      = msg.FromUserName,
                        NickName    = usermodel.NickName,
                        Sex         = usermodel.Sex,
                        CommendInfo = msg.Content,
                        IssueTime   = DateTime.Now
                    });
                    MessageHandler.SendTextReplyMessage(msg.ToUserName, msg.FromUserName, "留言成功!");
                }
                else
                {
                    MessageHandler.SendTextReplyMessage(msg.ToUserName, msg.FromUserName, "获取用户信息失败!" + msg.FromUserName);
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 产品码查询
        /// </summary>
        /// <param name="ToUserName">请求人</param>
        /// <param name="FromUserName">服务号OpenId</param>
        /// <returns></returns>
        private bool NewsList(TextReceiveMessage msg, params object[] args)
        {
            string msgWord = msg.Content.ToLower();

            if (msgWord.StartsWith("h"))
            {
                var usermodel = WeiXin.GetUserInfo(msg.FromUserName);
                if (usermodel != null)
                {
                    List <NewsReplyMessageItem> items = new List <NewsReplyMessageItem>();
                    int    rowsCount = 0;
                    string wxm       = msgWord.Substring(1);
                    var    list      = new Eyousoft_yhq.BLL.Product().GetList(1, 1, ref rowsCount, new Eyousoft_yhq.Model.SerProduct()
                    {
                        FavourCode = wxm
                    });
                    NewsReplyMessageItem NewsPicHeader = new NewsReplyMessageItem();
                    if (list != null && list.Count > 0)
                    {
                        NewsPicHeader.Description = EyouSoft.Common.Utils.GetText2(list[0].ProductDis, 50, true);
                        NewsPicHeader.Url         = "http://www.4008005216.com/AppPage/weixin/ProductInfo.aspx?id=" + list[0].ProductID;
                        NewsPicHeader.PicUrl      = (list[0].AttachList != null && list[0].AttachList.Count > 0) ? list[0].AttachList[0].FilePath : "";
                        NewsPicHeader.Title       = list[0].ProductName;
                    }
                    ;
                    items.Add(NewsPicHeader);

                    NewsReplyMessage replyMsg = new NewsReplyMessage()
                    {
                        CreateTime   = Tools.ConvertDateTimeInt(DateTime.Now),
                        FromUserName = msg.ToUserName,
                        ToUserName   = msg.FromUserName,
                        Articles     = items
                    };
                    if (list == null || list.Count == 0)
                    {
                        MessageHandler.SendTextReplyMessage(msg.ToUserName, msg.FromUserName, "查询产品不存在!");
                        return(true);
                    }
                    MessageHandler.SendReplyMessage(replyMsg);
                }
                else
                {
                    MessageHandler.SendTextReplyMessage(msg.ToUserName, msg.FromUserName, "获取用户信息失败!" + msg.FromUserName);
                }
            }
            else
            {
                MessageHandler.SendTextReplyMessage(msg.ToUserName, msg.FromUserName, "亲!您的问题我不明白,要不您换个问法再试试,我这里只要输入5位产品码就行了。或者您可以进入\"旅游超市\"按分类查询。!");
            }
            return(true);
        }