Ejemplo n.º 1
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;
         }
     }
 }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
        //static ConcurrentDictionary<string, string> _userToSessionIdDIc = new ConcurrentDictionary<string, string>();
        /// <summary>
        /// 获取如果没有则创建一对uuid的session值。
        /// </summary>
        /// <param name="from">user uuid</param>
        /// <param name="to">user uuid</param>
        /// <returns></returns>
        //public static async Task<string> GetOrCreateSessionId(string from, string to)
        //{
        //    from = from.Trim().ToUpper();
        //    to = to.Trim().ToUpper();
        //    string key = from + "_" + to;

        //    //先看缓存中是否存在
        //    string ret = null;
        //    if (_userToSessionIdDIc.TryGetValue(key, out ret))
        //        return ret;

        //    //redis中是否存在
        //    var sessionObject = await _redis.GetObjectFromRedis<WeChatUserToSessionHash>(key);
        //    if (sessionObject != null && !String.IsNullOrEmpty(sessionObject.SessionId))
        //    {
        //        _userToSessionIdDIc[key] = sessionObject.SessionId;
        //        return sessionObject.SessionId;
        //    }

        //    //双向绑定到一个sessionid,
        //    //初始化user.message.user_to_session.hash这个redishash,
        //    //因为sessionid是在发送消息的时候才会第一次调用。
        //    string key2 = to + "_" + from;
        //    WeChatUserToSessionHash o1 = new WeChatUserToSessionHash();
        //    WeChatUserToSessionHash o2 = new WeChatUserToSessionHash();
        //    string uuid = Guid.NewGuid().ToString();
        //    o1.Key = key; o1.SessionId = uuid;
        //    o2.Key = key2; o2.SessionId = uuid;
        //    bool flag = await _redis.SaveObjectAsync(o1);
        //    flag = await _redis.SaveObjectAsync(o2);


        //    //然后反向初始化sessionid取user的redis hash
        //    //user.message.session_to_user.hash
        //    //users按照','分割。
        //    WeChatSessoinToUsersHash h = new WeChatSessoinToUsersHash();
        //    h.SessionId = uuid;
        //    h.Users = to + "," + from;
        //    flag = await _redis.SaveObjectAsync(h);

        //    if (!flag)
        //    {
        //        LogHelper.LogErrorAsync(typeof(WeChatSendMQHelper), new Exception("怎么回事?sessionid创建失败!"));
        //    }

        //    return uuid;
        //}

        public static async Task<bool> SendNotice(NoticeMQ obj)
        {
            //obj.TimeStamp = Util.CommonHelper.GetUnixTimeNow();
            obj.TimeStamp = DateTime.Now;
            return MQManager.SendMQ_TB<NoticeMQConfig>(obj);
        }
Ejemplo n.º 4
0
 public static Message GetMessageType(NoticeMQ notice)
 {
     Message msg = new Message();
     msg.ID = notice.Id;
     msg.Receiver_uuid = notice.Receiver_Uuid;
     //msg.SendTime = CommonHelper.FromUnixTime(Convert.ToDouble(notice.TimeStamp));
     msg.SendTime = notice.TimeStamp;
     msg.Status = notice.status;
     msg.MsgType = (int)notice.MsgType;
     msg.MessageInfo = notice.PayLoad as string;
     msg.RelationID_uuid = notice.Relation_Uuid;
     msg.RelationID = notice.Relation_Id;
     return msg;
 }
Ejemplo n.º 5
0
 public static async Task<bool> SendNoticeFavorite(Guid receiverUuid, Guid relationUuid)
 {
     NoticeMQ obj = new NoticeMQ();
     obj.MsgType = NoticeType.Favorite_Add;
     obj.Relation_Uuid = relationUuid;
     obj.Receiver_Uuid = receiverUuid;
     return await SendNotice(obj);
 }
Ejemplo n.º 6
0
 public static async Task<bool> UpdateNoticeAddContact(Message m)
 {
     NoticeMQ obj = new NoticeMQ();
     obj.Id = m.ID;
     obj.MsgType = NoticeType.Contact_Request;
     obj.Relation_Uuid = m.RelationID_uuid;
     obj.Receiver_Uuid = m.Receiver_uuid;
     obj.PayLoad = m.MessageInfo;
     obj.status = m.Status;
     //obj.TimeStamp = CommonHelper.ToUnixTime(m.SendTime);
     obj.TimeStamp = m.SendTime;
     return MQManager.SendMQ_TB<NoticeMQConfig>(obj);
 }
Ejemplo n.º 7
0
 public static async Task<bool> SendNoticeAddContact(Guid receiverUuid, Guid relationUuid, string msg = "")
 {
     NoticeMQ obj = new NoticeMQ();
     obj.MsgType = NoticeType.Contact_Request;
     obj.Relation_Uuid = relationUuid;
     obj.Receiver_Uuid = receiverUuid;
     obj.PayLoad = msg;
     return await SendNotice(obj);
 }