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;
        }
Exemplo n.º 2
0
        public ActionResult Detail(string userName, int num)
        {
            WeixinDbContext db = new WeixinDbContext();
            WeixinUser user = db.WeixinUsers.Where(u => u.OpenId == userName).FirstOrDefault<WeixinUser>();
            db.Entry(user).Collection(u => u.RequestMessages).Load();
            List<string> avatarUrls = db.WeixinUsers.Where(u => !string.IsNullOrEmpty(u.AvatarUrl)).Select(u => u.AvatarUrl).Distinct().Take(num).ToList<string>();

            //Dictionary<string, string> comments = new Dictionary<string, string>();

            //comments.Add(avatarUrls[2], "这个必须赞!");
            //comments.Add(avatarUrls[7], "嗯,狂赞!");
            //comments.Add(avatarUrls[9], "牛叉!");
            //comments.Add(avatarUrls[11], "是真的吗?!");

            MomentDetail moment = new MomentDetail()
            {
                NickName = user.NickName,
                AwesomeNumber = num,
                AvatarUrl = user.AvatarUrl,
                AwesomeAvatars = avatarUrls,
                //Comments = comments
            };
            foreach (var message in user.RequestMessages)
            {
                RequestMsgType msgType = (RequestMsgType)Enum.Parse(typeof(RequestMsgType), message.MessageType);
                //获取帮我点赞与帮我点()个赞之间用户发送的朋友圈信息
                switch (msgType)
                {
                    case RequestMsgType.Text:

                        if (string.IsNullOrEmpty(moment.Title))
                        {
                            moment.Title = message.Content;
                        }
                        break;
                    case RequestMsgType.Image:

                        moment.Pictures.Add(message.Content);
                        break;
                    case RequestMsgType.Link:
                        ShareDetail share = new ShareDetail()
                        {
                            Title = message.LinkTitle,
                            Url = message.LinkUrl,
                            SmallPic = GetSharePic(message.LinkUrl)
                        };
                        moment.Share = share;
                        break;
                    default:
                        break;
                }
            }
            return View(moment);
        }
Exemplo n.º 3
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;
        }
Exemplo n.º 4
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;
        }