示例#1
0
 public static void SendPhotoToUser(int userid, string loginid, int uid, string img, int messagestypeid, string guid, object mock, bool isBART, int width, int height, dynamic flasedata, string thumbImg)
 {
     //发送成功,返回给所有目标用户
     CONNECT_TMP_POOL = new Dictionary <int, WebSocket>(CONNECT_POOL);
     try
     {
         WebSocket destSocket = CONNECT_TMP_POOL[uid]; //目的客户端
         if (destSocket != null && destSocket.State == WebSocketState.Open)
         {
             DateTime time   = DateTime.Now;
             UserBLL  ub     = new UserBLL();
             string   result = ub.GetUserHeadImg(userid);
             var      temp   = new
             {
                 userid           = userid,
                 time             = time,
                 img              = img,
                 loginid          = loginid,
                 uid              = uid,
                 guid             = guid,
                 userheadportrait = Constant.files + result,
                 messagestypeid   = messagestypeid,
                 mock             = mock,
                 isBART           = isBART,
                 width,
                 height,
                 thumbImg
             };
             string data  = JsonConvert.SerializeObject(temp);
             byte[] bytes = Encoding.UTF8.GetBytes(data);
             ArraySegment <byte> buffer = new ArraySegment <byte>(bytes);
             destSocket.SendAsync(buffer, WebSocketMessageType.Text, true, new CancellationToken());
         }
     }
     catch
     {
         UserBLL ub     = new UserBLL();
         Redis   redis  = new Redis();
         var     datas  = redis.StringGet(uid.ToString());
         string  token  = string.Empty;
         string  device = string.Empty;
         if (datas != null)
         {
             token  = datas["token"].ToString();
             device = datas["device"].ToString();
         }
         //if ("1".Equals(device))
         //{
         //    if (flasedata != null)
         //    {
         //        Push.PushMessageToSingle(flasedata.content, JsonConvert.SerializeObject(res), token);
         //    }
         //    else
         //    {
         //        Push.PushMessageToSingle(msgs, JsonConvert.SerializeObject(res), token);
         //    }
         //}
         if ("2".Equals(device))
         {
             var res = new
             {
                 userid = userid,
                 uid    = uid,
                 img    = img
             };
             if (flasedata != null)
             {
                 string title   = flasedata.title;
                 string content = flasedata.content;
                 Push.APNsPushToSingle(title, "这是一条回复[图片]吧", token, res);
             }
             else
             {
                 Push.APNsPushToSingle(loginid, "[图片]", token, res);
             }
         }
         DateTime time   = DateTime.Now;
         string   result = ub.GetUserHeadImg(userid);
         var      temp   = new
         {
             userid           = userid,
             time             = time,
             img              = img,
             loginid          = loginid,
             uid              = uid,
             guid             = guid,
             userheadportrait = Constant.files + result,
             messagestypeid   = messagestypeid,
             mock             = mock,
             isBART           = isBART,
             width,
             height,
             thumbImg
         };
         string data  = JsonConvert.SerializeObject(temp);
         byte[] bytes = Encoding.UTF8.GetBytes(data);
         ArraySegment <byte> buffer = new ArraySegment <byte>(bytes);
         try
         {
             MESSAGE_POOL.Add(uid, new List <MessageInfo>());
             MESSAGE_POOL[uid].Add(new MessageInfo(buffer));
         }
         catch
         {
             MESSAGE_POOL[uid].Add(new MessageInfo(buffer));//添加离线消息
         }
     }
 }
示例#2
0
 /// <summary>
 /// 发送图片个指定用户
 /// </summary>
 /// <param name="userid">当前登录用户id</param>
 /// <param name="loginid">当前用户用户名</param>
 /// <param name="uid">接收者用户id</param>
 /// <param name="img">图片链接</param>
 public static void SendPhotoToUsers(int userid, string loginid, int uid, string img, int messagestypeid, string guid, string ext, string width, string height, object imgURLs)
 {
     //发送成功,返回给所有目标用户
     CONNECT_TMP_POOL = new Dictionary <int, WebSocket>(CONNECT_POOL);
     try
     {
         WebSocket destSocket = CONNECT_TMP_POOL[uid]; //目的客户端
         if (destSocket != null && destSocket.State == WebSocketState.Open)
         {
             DateTime time   = DateTime.Now;
             UserBLL  ub     = new UserBLL();
             string   result = ub.GetUserHeadImg(userid);
             var      temp   = new
             {
                 userid           = userid,
                 time             = time,
                 img              = img,
                 loginid          = loginid,
                 uid              = uid,
                 guid             = guid,
                 ext              = ext,
                 width            = width,
                 height           = height,
                 messagestypeid   = messagestypeid,
                 userheadportrait = Constant.files + result,
                 imgURLs          = imgURLs
             };
             string data  = JsonConvert.SerializeObject(temp);
             byte[] bytes = Encoding.UTF8.GetBytes(data);
             ArraySegment <byte> buffer = new ArraySegment <byte>(bytes);
             destSocket.SendAsync(buffer, WebSocketMessageType.Text, true, new CancellationToken());
         }
     }
     catch {
         Redis  redis  = new Redis();
         var    datas  = redis.StringGet(uid.ToString());
         string token  = datas["token"].ToString();
         string device = datas["device"].ToString();
         string msg    = "图片";
         if ("1".Equals(device))
         {
         }
         ;
         if ("2".Equals(device))
         {
             Push.APNsPushToSingle("", msg, token, null);
         }
         DateTime time   = DateTime.Now;
         UserBLL  ub     = new UserBLL();
         string   result = ub.GetUserHeadImg(userid);
         var      temp   = new
         {
             userid           = userid,
             time             = time,
             img              = img,
             loginid          = loginid,
             uid              = uid,
             guid             = guid,
             ext              = ext,
             width            = width,
             height           = height,
             messagestypeid   = messagestypeid,
             userheadportrait = Constant.files + result,
             imgURLs          = imgURLs
         };
         string data  = JsonConvert.SerializeObject(temp);
         byte[] bytes = Encoding.UTF8.GetBytes(data);
         ArraySegment <byte> buffer = new ArraySegment <byte>(bytes);
         try
         {
             MESSAGE_POOL.Add(uid, new List <MessageInfo>());
             MESSAGE_POOL[uid].Add(new MessageInfo(buffer));
         }
         catch
         {
             MESSAGE_POOL[uid].Add(new MessageInfo(buffer));//添加离线消息
         }
     }
 }
示例#3
0
 /// <summary>
 /// 发送消息给指定用户
 /// </summary>
 /// <param name="uid">接收者id</param>
 /// <param name="msg">发送的消息</param>
 public static void SendMsgToUser(int userid, string loginid, int uid, string msg, string guid, int messagestypeid, bool isBART, object res, dynamic flasedata, bool flag)
 {
     //发送成功,返回给所有目标用户
     CONNECT_TMP_POOL = new Dictionary <int, WebSocket>(CONNECT_POOL);
     try
     {
         WebSocket destSocket = CONNECT_TMP_POOL[uid]; //目的客户端
         if (destSocket != null && destSocket.State == WebSocketState.Open)
         {
             DateTime time   = DateTime.Now;
             UserBLL  ub     = new UserBLL();
             string   result = ub.GetUserHeadImg(userid);
             var      temp   = new
             {
                 userid           = userid,
                 time             = time,
                 msg              = msg,
                 loginid          = loginid,
                 uid              = uid,
                 guid             = guid,
                 userheadportrait = Constant.files + result,
                 messagestypeid   = messagestypeid,
                 isBART           = isBART
             };
             string data  = JsonConvert.SerializeObject(temp);
             byte[] bytes = Encoding.UTF8.GetBytes(data);
             ArraySegment <byte> buffer = new ArraySegment <byte>(bytes);
             destSocket.SendAsync(buffer, WebSocketMessageType.Text, true, new CancellationToken());
         }
     }
     catch (Exception ex)
     {
         UserBLL ub = new UserBLL();
         //var users=ub.GetUserById(userid);
         string msgs   = string.Empty;
         Redis  redis  = new Redis();
         var    datas  = redis.StringGet(uid.ToString());
         string token  = string.Empty;
         string device = string.Empty;
         if (datas != null)
         {
             token  = datas["token"].ToString();
             device = datas["device"].ToString();
         }
         //if (Convert.ToBoolean(users.ChatSwitch))
         //{
         //    msgs = "私聊消息";
         //}
         //else
         //{
         //    msgs = DecodeBase64(msg);
         //}
         if ("1".Equals(device))
         {
             if (flasedata != null)
             {
                 string title   = flasedata.title;
                 string content = flasedata.content;
                 Push.PushMessageToSingle(title, content, JsonConvert.SerializeObject(res), token);
             }
             else
             {
                 if (flag)
                 {
                     Push.PushMessageToSingle(loginid, "阅后即焚", JsonConvert.SerializeObject(res), token);
                 }
                 else
                 {
                     msgs = DecodeBase64(msg);
                     Push.PushMessageToSingle(loginid, msgs, JsonConvert.SerializeObject(res), token);
                 }
             }
         }
         if ("2".Equals(device))
         {
             if (flasedata != null)
             {
                 string title   = flasedata.title;
                 string content = flasedata.content;
                 Push.APNsPushToSingle(title, content, token, res);
             }
             else
             {
                 if (flag)
                 {
                     Push.APNsPushToSingle(loginid, "阅后即焚", token, res);
                 }
                 else
                 {
                     msgs = DecodeBase64(msg);
                     Push.APNsPushToSingle(loginid, msgs, token, res);
                 }
             }
         }
         DateTime time   = DateTime.Now;
         string   result = ub.GetUserHeadImg(userid);
         var      temp   = new
         {
             userid           = userid,
             time             = time,
             msg              = msg,
             loginid          = loginid,
             uid              = uid,
             userheadportrait = Constant.files + result,
             guid             = guid,
             messagestypeid   = EnumHelper.Message.four,
             isBART           = isBART
         };
         string data  = JsonConvert.SerializeObject(temp);
         byte[] bytes = Encoding.UTF8.GetBytes(data);
         ArraySegment <byte> buffer = new ArraySegment <byte>(bytes);
         try
         {
             MESSAGE_POOL.Add(uid, new List <MessageInfo>());
             MESSAGE_POOL[uid].Add(new MessageInfo(buffer));
         }
         catch
         {
             MESSAGE_POOL[uid].Add(new MessageInfo(buffer));//添加离线消息
         }
     }
 }