Ejemplo n.º 1
0
        public IResponseMessageBase GetResponseMessage(IRequestMessageBase requestMessage)
        {
            var request = requestMessage as RequestMessageImage;
            WeixinDbContext db = new WeixinDbContext();

            //WeixinUser user = new WeixinUser();
            //user.OpenId = Guid.NewGuid().ToString();
            //Random r = new Random();
            //user.NickName = "测试A" + r.Next();
            //user.AvatarUrl = request.PicUrl;
            //db.WeixinUsers.Add(user);

            WeixinUser user = db.WeixinUsers.Where(u => u.OpenId == requestMessage.FromUserName).FirstOrDefault<WeixinUser>();
            RequestMessage message = new RequestMessage()
            {
                MessageType = Convert.ToString(requestMessage.MsgType),
                FromUserId = user.UserId,
                RequestTime = requestMessage.CreateTime,
                Content = request.PicUrl
            };
            db.RequestMessages.Add(message);
            db.SaveChanges();

            return null;
        }
Ejemplo n.º 2
0
        public IResponseMessageBase GetResponseMessage(IRequestMessageBase requestMessage)
        {
            var request = requestMessage as RequestMessageLink;

            WeixinDbContext db = new WeixinDbContext();
            WeixinUser user = db.WeixinUsers.Where(u => u.OpenId == requestMessage.FromUserName).FirstOrDefault<WeixinUser>();

            RequestMessage message = new RequestMessage()
            {
                MessageType = Convert.ToString(requestMessage.MsgType),
                FromUserId = user.UserId,
                RequestTime = requestMessage.CreateTime,
                LinkTitle=request.Title,
                LinkUrl=request.Url
            };
            db.RequestMessages.Add(message);
            db.SaveChanges();

            return null;
        }
Ejemplo n.º 3
0
        public IResponseMessageBase GetResponseMessage(IRequestMessageBase requestMessage)
        {
            IResponseMessageBase response = null;
            var request = requestMessage as RequestMessageText;
            WeixinDbContext db = new WeixinDbContext();
            WeixinUser user = db.WeixinUsers.Where(u => u.OpenId == requestMessage.FromUserName).FirstOrDefault<WeixinUser>();

            if (request.Content.Equals("帮我点赞"))
            {
                if (user == null)
                {
                    var responseText = ResponseMessageBase.CreateFromRequestMessage<ResponseMessageText>(requestMessage);

                    responseText.Content = "请先告诉我您的朋友圈昵称!";

                    return responseText;
                }
                else
                {
                    //每次点赞先清空之前的点赞记录
                    db.Entry(user).Collection(u => u.RequestMessages).Load();
                    user.RequestMessages.ToList().ForEach(entity => db.Entry(entity).State = System.Data.Entity.EntityState.Deleted);
                    db.RequestMessages.RemoveRange(user.RequestMessages);
                    db.SaveChanges();
                }

                var responseNews = ResponseMessageBase.CreateFromRequestMessage<ResponseMessageNews>(requestMessage);
                responseNews.Articles.Add(new Article()
                {
                    Title = "好嘞,点赞君收到!",
                    Description = "请发送您要点赞的图文或分享链接!不知道怎么操作?点进来看看,有详细步骤!",
                    PicUrl = "http://www.shisheng.wang/images/qr.jpg",
                    Url = "http://www.shisheng.wang/moment/help"
                });

                return responseNews;
            }
            else if (request.Content.Contains("点") && request.Content.Contains("个赞"))
            {
                var responseNew = ResponseMessageBase.CreateFromRequestMessage<ResponseMessageNews>(requestMessage);
                string numStr = string.Empty;
                if (request.Content.Contains("帮我点"))
                {
                    numStr = request.Content.Substring(3, request.Content.Length - 5);
                }
                else
                {
                    numStr = request.Content.Substring(1, request.Content.Length - 3);
                }
                int num = 36;
                Int32.TryParse(numStr, out num);
                responseNew.Articles.Add(new Article()
                {
                    Title = string.Format("报告掌柜的,你要的{0}个赞,已点赞完毕!!!", num),
                    Description = "最后一步啦,请打开网页截图即可!",
                    PicUrl = "http://www.shisheng.wang/images/qr.jpg",
                    Url = string.Format("http://www.shisheng.wang/moment/detail?username={0}&num={1}", requestMessage.FromUserName, num)
                });

                return responseNew;
            }
            else if(request.Content.Contains("修改昵称"))
            {
                var responseText = ResponseMessageBase.CreateFromRequestMessage<ResponseMessageText>(requestMessage);

                responseText.Content = "请告诉我您的新昵称!";

                return responseText;
            }
            else if (request.Content.Contains("修改头像"))
            {
                var responseText = ResponseMessageBase.CreateFromRequestMessage<ResponseMessageText>(requestMessage);

                responseText.Content = "请上传您的新头像!";

                return responseText;
            }
            else
            {
                RequestMessage message = new RequestMessage()
                {
                    MessageType = Convert.ToString(requestMessage.MsgType),
                    FromUserId = user.UserId,
                    RequestTime = requestMessage.CreateTime,
                    Content = request.Content
                };
                db.RequestMessages.Add(message);
                db.SaveChanges();
            }

            return response;
        }