Esempio n. 1
0
        public PushResponse Process(PushRequest pRequest)
        {
            PushResponse response = new PushResponse();

            response.ResultCode = 0;
            try
            {
                MessageChannelDAO channelDao = new MessageChannelDAO(new BasicUserInfo());
                MessageDAO        dao        = new MessageDAO(new BasicUserInfo());
                var entity = channelDao.GetByID(pRequest.ChannelID);
                if (entity == null)
                {
                    throw new Exception(string.Format("未找到相应的ChannelID为:{0}的Channel信息", pRequest.ChannelID));
                }
                MessageEntity mEntity = new MessageEntity();
                mEntity.MessageID = Guid.NewGuid();
                mEntity.ClientID  = pRequest.ClientID;
                mEntity.ChannelID = pRequest.ChannelID;
                mEntity.AppCode   = pRequest.AppCode;
                mEntity.UserID    = pRequest.UserID;
                var request     = pRequest.Request.DeserializeJSONTo <PushMsgRequest>();
                var messagetype = request.InnerDictionary["message_type"].ToString();
                //判断消息类型0-消息,1-通知
                switch (messagetype)
                {
                case "0":
                    mEntity.MessageContent = request.InnerDictionary["messages"].ToString();
                    break;

                case "1":
                    mEntity.MessageContent = request.InnerDictionary["messages"].ToJSON().DeserializeJSONTo <BaiduPushNotification>().Description;
                    break;
                }
                mEntity.MessageParameters = pRequest.GetJson();
                switch (pRequest.Type)
                {
                case 1:    //直接发送
                    var result = BaiduCloudPush.PushMessage(entity.GetBaiDuChannel(), pRequest.Request.DeserializeJSONTo <PushMsgRequest>());
                    if (result.IsSuccess)
                    {
                        mEntity.SendCount = 1;
                        mEntity.Status    = 2;
                        dao.Create(mEntity);
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = "【发送成功】:" + mEntity.MessageParameters
                        });
                    }
                    else
                    {
                        mEntity.Status      = 1;
                        mEntity.SendCount   = 1;
                        mEntity.FaultReason = result.ErrorMessage;
                        dao.Create(mEntity);
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = "【发送失败】:" + mEntity.MessageParameters + Environment.NewLine + result.ErrorMessage
                        });
                        throw new Exception("【发送失败】:" + result.ErrorMessage + Environment.NewLine + mEntity.MessageParameters);
                    }
                    break;

                case 2:    //存放到数据库
                    mEntity.SendCount = 0;
                    mEntity.Status    = 0;
                    dao.Create(mEntity);
                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = "【保存数据库成功】:" + mEntity.MessageParameters
                    });
                    break;

                default:
                    throw new Exception("未定义的请求类型:" + pRequest.Type);
                }
            }
            catch (Exception ex)
            {
                response.ResultCode = 100;
                response.Message    = ex.Message;
                Loggers.Exception(new ExceptionLogInfo(ex));
            }
            return(response);
        }
Esempio n. 2
0
        void bw_DoWork1(object sender, DoWorkEventArgs e)
        {
            while (true)
            {
                try
                {
                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = "审批订单-查询数据库"
                    });
                    MessageDAO        mdao       = new MessageDAO(new BasicUserInfo());
                    OrdersCheckingDAO dao        = new OrdersCheckingDAO(new BasicUserInfo());
                    ClientUserDAO     userDao    = new ClientUserDAO(new BasicUserInfo());
                    MessageChannelDAO channelDao = new MessageChannelDAO(new BasicUserInfo());
                    var entitys = dao.GetValidOrdersChecking();
                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = "审批订单-找到" + entitys.Count() + "条数据"
                    });
                    foreach (var item in entitys)
                    {
                        Dictionary <ClientUserEntity, string> messages;
                        var userEntitys = userDao.GetValidUserByStatus0(item, out messages);
                        foreach (var it in userEntitys)
                        {
                            if (!string.IsNullOrEmpty(it.PushChannel))
                            {
                                PushChannel   info     = it.PushChannel.DeserializeJSONTo <PushChannel>();
                                var           pRequest = PushMsgRequestBuilder.CreateUnicastNotificationRequest(info.BaiduUserID, info.BaiduChannelID, "订单审批通知", messages[it]);
                                MessageEntity mEntity  = new MessageEntity();
                                mEntity.MessageID = Guid.NewGuid();
                                mEntity.ChannelID = 1;
                                mEntity.ClientID  = it.ClientID.Value.ToString();
                                mEntity.UserID    = it.ClientUserID.Value.ToString();
                                var request     = pRequest;
                                var messagetype = request.InnerDictionary["message_type"].ToString();
                                //判断消息类型0-消息,1-通知
                                switch (messagetype)
                                {
                                case "0":
                                    mEntity.MessageContent = request.InnerDictionary["messages"].ToString();
                                    break;

                                case "1":
                                    mEntity.MessageContent = request.InnerDictionary["messages"].ToJSON().DeserializeJSONTo <BaiduPushNotification>().Description;
                                    break;
                                }
                                mEntity.MessageParameters = pRequest.InnerDictionary.ToJSON();
                                mEntity.SendCount         = 0;
                                mEntity.Status            = 0;
                                mdao.Create(mEntity);
                                Loggers.Debug(new DebugLogInfo()
                                {
                                    Message = "【保存数据库成功】:" + mEntity.MessageParameters
                                });
                                item.SendStatus = 1;
                                dao.Update(item);
                            }
                            else
                            {
                                Loggers.Debug(new DebugLogInfo()
                                {
                                    Message = string.Format("用户{0}-{1}的PushChanel为空", it.ClientUserID, it.Username)
                                });
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Loggers.Exception(new ExceptionLogInfo(ex));
                }
                Loggers.Debug(new DebugLogInfo()
                {
                    Message = string.Format("审批订单-轮循结束,等待{0}秒", Interval)
                });
                Thread.Sleep(TimeSpan.FromSeconds(Interval));
            }
        }
Esempio n. 3
0
        public PushResponse Process(PushRequest pRequest)
        {
            PushResponse response = new PushResponse();

            response.ResultCode = 0;
            try
            {
                MessageChannelDAO channelDao = new MessageChannelDAO(new BasicUserInfo());
                MessageDAO        dao        = new MessageDAO(new BasicUserInfo());
                var entity = channelDao.GetByID(pRequest.ChannelID);
                if (entity == null)
                {
                    throw new Exception(string.Format("未找到相应的ChannelID为:{0}的Channel信息", pRequest.ChannelID));
                }
                MessageEntity mEntity = new MessageEntity();
                mEntity.MessageID = Guid.NewGuid();
                mEntity.ClientID  = pRequest.ClientID;
                mEntity.ChannelID = pRequest.ChannelID;
                mEntity.AppCode   = pRequest.AppCode;
                mEntity.UserID    = pRequest.UserID;
                var notification = pRequest.Request.DeserializeJSONTo <JdSoft.Apple.Apns.Notifications.Notification>();
                mEntity.MessageParameters = pRequest.GetJson();
                switch (pRequest.Type)
                {
                case 1:    //直接发送
                    var IOSChannel = entity.GetIOSChannel();
                    var result     = IOSNotificationService.CreateInstance(IOSChannel.SandBox ?? true, IOSChannel.P12, IOSChannel.P12PWD).SendNotification(notification);
                    if (result)
                    {
                        mEntity.SendCount = 1;
                        mEntity.Status    = 2;
                        dao.Create(mEntity);
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = "【发送到推送服务器成功】:" + mEntity.MessageParameters
                        });
                    }
                    else
                    {
                        mEntity.Status      = 1;
                        mEntity.SendCount   = 1;
                        mEntity.FaultReason = "发送到推送服务器失败";
                        dao.Create(mEntity);
                        Loggers.Debug(new DebugLogInfo()
                        {
                            Message = "【发送到推送服务器失败】:" + mEntity.MessageParameters
                        });
                        throw new Exception("【发送到推送服务器失败】");
                    }
                    break;

                case 2:    //存放到数据库
                    mEntity.SendCount = 0;
                    mEntity.Status    = 0;
                    dao.Create(mEntity);
                    Loggers.Debug(new DebugLogInfo()
                    {
                        Message = "【保存数据库成功】:" + mEntity.MessageParameters
                    });
                    break;

                default:
                    throw new Exception("未定义的请求类型:" + pRequest.Type);
                }
            }
            catch (Exception ex)
            {
                response.ResultCode = 100;
                response.Message    = ex.Message;
                Loggers.Exception(new ExceptionLogInfo(ex));
            }
            return(response);
        }
Esempio n. 4
0
        void bw_DoWork1(object sender, DoWorkEventArgs e)
        {
            while (true)
            {
                try
                {
                    MessageDAO        dao        = new MessageDAO(new BasicUserInfo());
                    MessageChannelDAO channelDao = new MessageChannelDAO(new BasicUserInfo());
                    var entitys = dao.GetValidMessage();
                    foreach (var item in entitys)
                    {
                        try
                        {
                            var entity = channelDao.GetByID(item.ChannelID);
                            if (entity == null)
                            {
                                throw new Exception(string.Format("未找到相应的ChannelID为:{0}的Channel信息", item.ChannelID));
                            }
                            switch (entity.MobilePlatform)
                            {
                            case 1:
                                var request       = item.GetRequest();
                                var baiduResponse = BaiduCloudPush.PushMessage(entity.GetBaiDuChannel(), request);
                                if (baiduResponse.IsSuccess)
                                {
                                    item.SendCount = (item.SendCount ?? 0) + 1;
                                    item.Status    = 2;
                                    Loggers.Debug(new DebugLogInfo()
                                    {
                                        Message = "【发送成功】:" + item.MessageContent
                                    });
                                }
                                else
                                {
                                    item.SendCount   = (item.SendCount ?? 0) + 1;
                                    item.Status      = 1;
                                    item.FaultReason = baiduResponse.ErrorMessage;
                                    Loggers.Debug(new DebugLogInfo()
                                    {
                                        Message = "【发送失败】:" + item.MessageContent
                                    });
                                }
                                break;

                            case 2:
                                var IOSChannel   = entity.GetIOSChannel();
                                var notification = item.GetIOSNotification();
                                var IOSResponse  = IOSNotificationService.CreateInstance(IOSChannel.SandBox ?? true, IOSChannel.P12, IOSChannel.P12PWD).SendNotification(notification);
                                if (IOSResponse)
                                {
                                    item.SendCount = (item.SendCount ?? 0) + 1;
                                    item.Status    = 2;
                                    Loggers.Debug(new DebugLogInfo()
                                    {
                                        Message = "【发送到推送服务器成功】:" + item.MessageContent
                                    });
                                }
                                else
                                {
                                    item.SendCount   = (item.SendCount ?? 0) + 1;
                                    item.Status      = 1;
                                    item.FaultReason = "发送到推送服务器失败";
                                    Loggers.Debug(new DebugLogInfo()
                                    {
                                        Message = "【发送到推送服务器成功】:" + item.MessageContent
                                    });
                                }
                                break;

                            default:
                                throw new Exception("错误的平台类型");
                            }


                            dao.Update(item);
                        }
                        catch (Exception ee)
                        {
                            item.SendCount   = (item.SendCount ?? 0) + 1;
                            item.FaultReason = ee.Message;
                            item.Status      = 1;
                            dao.Update(item);
                            Loggers.Exception(new ExceptionLogInfo(ee));
                            throw ee;
                        }
                    }
                    Thread.Sleep(TimeSpan.FromSeconds(Interval));
                }
                catch (Exception ex)
                {
                    Loggers.Exception(new ExceptionLogInfo(ex));
                }
            }
        }