Example #1
0
        public static async Task<bool> SaveOrNot(Message msg)
        {
            using(NoticeRepository noticeRepository = new NoticeRepository())
            {
                bool result = true;
                try
                {
                    if(msg.ID == 0)
                    {
                        switch(msg.MsgType)
                        {
                            case (int)NoticeType.Visitor_Add:
                            case (int)NoticeType.Favorite_Add:
                                result = !await noticeRepository.CheckNoticeExist(msg);
                                break;
                            default:
                                break;
                        }
                    }

                }
                catch(Exception ex)
                {
                    LogHelper.LogErrorAsync(typeof(NoticeHelper), ex);
                }
                return result;
            }
        }
Example #2
0
 public static async Task<long> SaveNoticeToSql(NoticeMQ notice)
 {
     Message msg = WeChatNoticeHelper.GetMessageType(notice);
     using(NoticeRepository noticeRepository = new NoticeRepository())
     {
         try
         {
             if(await SaveOrNot(msg))
                 return await noticeRepository.SaveNotice(msg);
             else
                 return 0;
         }
         catch(Exception ex)
         {
             LogHelper.LogErrorAsync(typeof(NoticeHelper), ex);
             return 0;
         }
     }
 }
Example #3
0
        public async Task<HttpResponseMessage> PostContactAgreeOrDiscard([FromBody]DualParameter postParameter)
        {
            string openid = postParameter.openID;
            string textMsg = postParameter.textMsg;
            long itemId= postParameter.itemId;

            if(string.IsNullOrEmpty(openid) || itemId==0 || !(textMsg == "Agree" || textMsg == "Discard"))
            {
                return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }

            using(UserRepository userRepository = new UserRepository())
            {
                using(NoticeRepository noticeRepository = new NoticeRepository())
                {
                    var msg = await noticeRepository.GetNotice(itemId);
                    string back = "";
                    bool result = false;
                    if(textMsg == "Agree")
                    {
                        //好友记录改为1
                        result = await userRepository.ActiveUserContact(msg.Receiver_uuid,msg.RelationID_uuid);
                        //该条要把状态变化成已同意
                        msg.Status = 1;
                        //需要发回的消息
                        back = "我已经同意加您为好友,打个招呼吧";
                    }
                    else if(textMsg == "Discard")
                    {
                        //好友记录删除
                        result = await userRepository.DeleteUserContact(msg.Receiver_uuid, msg.RelationID_uuid);
                        //该条要把状态变化成已拒绝
                        msg.Status = 2;
                        //需要发回的消息
                        back = "我拒绝了您的好友请求。";
                    }

                    //通过队列修改redis和sql中的状态
                    if(result)
                    {
                        await WeChatNoticeSendMQHelper.UpdateNoticeAddContact(msg);
                        await WeChatSendMQHelper.SendMessage(msg.Receiver_uuid.ToString().ToUpper(), msg.RelationID_uuid.ToString().ToUpper(), back);

                        return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.Success);
                    }
                    else
                    {
                        return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.Fail);
                    }
                }
            }
        }
Example #4
0
        public async Task<HttpResponseMessage> PostAddContact([FromBody]DualParameter postParameter)
        {
            string openid = postParameter.openID;
            long itemId = postParameter.itemId;

            using(NoticeRepository noticeRepository = new NoticeRepository())
            {
                Message m = await noticeRepository.GetNotice(itemId);

                NoticeMQ rawObject = new NoticeMQ();
                rawObject.Id = m.ID;
                rawObject.MsgType = NoticeType.Contact_Request;
                rawObject.Relation_Uuid = m.RelationID_uuid;
                rawObject.Receiver_Uuid = m.Receiver_uuid;
                rawObject.PayLoad = m.MessageInfo;
                //改了
                rawObject.status = 1;
                rawObject.TimeStamp = m.SendTime;

                var iso = new IsoDateTimeConverter();
                iso.DateTimeFormat = "yyyy-MM-dd HH:mm:ss.fff";

                RedisManager2<WeChatRedisConfig> _redis = new RedisManager2<WeChatRedisConfig>();
                WeChatNoticeRedis redisObject = new WeChatNoticeRedis();
                redisObject.Uuid = rawObject.Receiver_Uuid.ToString();
                redisObject.Message = JsonConvert.SerializeObject(rawObject, iso);
                //改回
                rawObject.status = 0;
                rawObject.TimeStamp = DateTime.Now;
                WeChatNoticeRedis originalRedisObject = new WeChatNoticeRedis();
                originalRedisObject.Uuid = rawObject.Receiver_Uuid.ToString();
                originalRedisObject.Message = JsonConvert.SerializeObject(rawObject, iso);

                await _redis.ReplaceObjectInListAsync(redisObject, originalRedisObject);
                return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.Fail);
            }
        }
Example #5
0
        /// <summary>
        /// 按照一定的步长去消息。
        /// </summary>
        /// <param name="fromUuid"></param>
        /// <param name="toUuid"></param>
        /// <param name="sectionNo"></param>
        /// <returns></returns>
        public static async Task<List<Message>> GetNotice(Guid uuid, int sectionNo, bool isNeedCleanUnred = true)
        {
            var config = Configuration.BK_ConfigurationManager.GetConfig<UserBehaviorConfig>();
            int pageSize = Convert.ToInt32(config.GetMessageCount);
            int fromIndex = pageSize * sectionNo;

            if (isNeedCleanUnred)
                await NoticeRedisOp.CleanUnreadScore(uuid);

            if (sectionNo == 0)
            {
                return await GetNoticeFromRedis(uuid);
            }

            using (NoticeRepository noticeRepository = new NoticeRepository())
            {
                var list = await noticeRepository.GetNotice(fromIndex, pageSize, uuid);
                if (list == null || list.Count == 0)
                    return null;
                else
                    return list;
            }
        }