protected override void ChannelRead0(IChannelHandlerContext ctx, CmppMessageReceiveArgs <CmppHead, CmppActiveTest> msg) { logger.Info($"receive active request: {msg}", ctx.Channel.ToString()); SmsPacket activeResp = GetActiveRespPacket(msg.Header); CmppTools.SendAsync(ctx, activeResp); }
protected override void ChannelRead0(IChannelHandlerContext ctx, CmppMessageReceiveArgs <CmppHead, CmppDeliver> msg) { baseSmsHandler.CmppDeliver(msg); var resp = GetConnectRequestPacket(msg.Message.MsgId, msg.Header.SequenceId); CmppTools.SendAsync(ctx, resp); }
protected override void ChannelRead0(IChannelHandlerContext ctx, CmppMessageReceiveArgs <CmppHead, CmppConnectResp> msg) { var connectBody = msg.Message; byte connectSuccess = 0; var channel = ctx.Channel; if (connectBody.Status.Equals(connectSuccess) && connectBody.AuthenticatorISMG != null) { var authenticatorISMG = CmppTools.CreateAuthenticatorISMG(connectSuccess, authenticatorSource, config.Password); if (authenticatorISMG.SequenceEqual(authenticatorISMG)) { logger.Info($"login success, return:{msg.Message.Status.ToString()}", ctx.Channel.ToString()); var session = sessionMap.GetSessionOrDefault(ctx); if (session == null) { ctx.Channel.CloseAsync(); } session.Send = true; connectCallBack_OK?.Invoke(); return; } } logger.Warn($"login fail, return:{msg.Message.Status.ToString()}", ctx.Channel.ToString()); ctx.Channel.CloseAsync(); }
public virtual void Cmpp2LongSmsRespondAssembly(CmppMessageReceiveArgs <CmppHead, CmppSubmitResp, Item <MsgEx> > msgEx) { List <CmppMessageReceiveArgs <CmppHead, CmppSubmitResp, Item <MsgEx> > > listSubmitResp; var item = msgEx.Item; var cmppPacket = item.Request as SmsPacket; if (item.BusinessEx.IsLong) //长短信 { if (!Cmpp2LongSmsRespondAssemblyCache(msgEx)) //等批 { return; } listSubmitResp = cache .GetCacheItem <List <CmppMessageReceiveArgs <CmppHead, CmppSubmitResp, Item <MsgEx> > > >(msgEx.Item.BusinessEx.Id); } else { listSubmitResp = new List <CmppMessageReceiveArgs <CmppHead, CmppSubmitResp, Item <MsgEx> > >() { msgEx }; } this.Cmpp2SubmitResp(listSubmitResp); }
protected override void ChannelRead0(IChannelHandlerContext ctx, CmppMessageReceiveArgs <CmppHead, CmppSubmitResp> msg) { if (matchQueue.Match(ctx.Channel, msg.Header.SequenceId.ToString(), out Item <MsgEx> item)) //匹配流水号 { msg.Item = item; CmppMessageReceiveArgs <CmppHead, CmppSubmitResp, Item <MsgEx> > msgEx = new CmppMessageReceiveArgs <CmppHead, CmppSubmitResp, Item <MsgEx> >(msg.Header, msg.Message, item); smsHandler?.Cmpp2LongSmsRespondAssembly(msgEx); } else { logger.Warn($"sms is removed from match cache{msg}", ctx.Channel.ToString()); } }
private bool Cmpp2LongSmsRespondAssemblyCache(CmppMessageReceiveArgs <CmppHead, CmppSubmitResp, Item <MsgEx> > msgEx) { var listSubmitRespCache = cache .GetCacheItem <List <CmppMessageReceiveArgs <CmppHead, CmppSubmitResp, Item <MsgEx> > > >(msgEx.Item.BusinessEx.Id); var result = false; if (listSubmitRespCache == null) //不存在响应 { listSubmitRespCache = new List <CmppMessageReceiveArgs <CmppHead, CmppSubmitResp, Item <MsgEx> > >() { msgEx }; result = false; } else //存在响应 { listSubmitRespCache.AddRange(listSubmitRespCache); result = listSubmitRespCache.Count == msgEx.Item.BusinessEx.Count; } DateTime absoluteExpiration = DateTime.Now.AddSeconds(60); cache.GetOrAddCacheItem(msgEx.Item.BusinessEx.Id, listSubmitRespCache, null, absoluteExpiration); return(result); }
protected override object Decode(IChannelHandlerContext context, IByteBuffer input) { var obj = base.Decode(context, input); if (AcceptInboundMessage(obj)) { IByteBuffer msg = (IByteBuffer)obj; byte[] array = new byte[msg.ReadableBytes]; msg.GetBytes(0, array); var cmppHeader = new CmppHead().FromBytes0(array); if (cmppHeader.TotalLength == array.Length) { CmppMessageReceiveArgs <IMessage, IMessage> args = null; switch (cmppHeader.CommandId) { case CmppConstants.CommandCode.Connect: break; case CmppConstants.CommandCode.ConnectResp: var ConnectResp = new CmppConnectResp().FromBytes0(array); args = new CmppMessageReceiveArgs <IMessage, IMessage>(cmppHeader, ConnectResp); break; case CmppConstants.CommandCode.Terminate: //var Terminate = new CmppTerminate(); //Terminate.FromBytes(packet); break; case CmppConstants.CommandCode.TerminateResp: //var TerminateResp = new CmppTerminateResp(); //TerminateResp.FromBytes(packet); break; case CmppConstants.CommandCode.Submit: //var Submit = new Cmpp2.CmppSubmit(); //Submit.FromBytes(packet); break; case CmppConstants.CommandCode.SubmitResp: var SubmitResp = new CmppSubmitResp().FromBytes0(array); args = new CmppMessageReceiveArgs <IMessage, IMessage>(cmppHeader, SubmitResp); break; case CmppConstants.CommandCode.Deliver: var Deliver = new CmppDeliver().FromBytes0(array); args = new CmppMessageReceiveArgs <IMessage, IMessage>(cmppHeader, Deliver); break; case CmppConstants.CommandCode.DeliverResp: //var DeliverResp = new Cmpp2.CmppDeliverResp(); //DeliverResp.FromBytes(packet); break; case CmppConstants.CommandCode.ActiveTest: var ActiveTest = new CmppActiveTest().FromBytes0(array); args = new CmppMessageReceiveArgs <IMessage, IMessage>(cmppHeader, ActiveTest); break; case CmppConstants.CommandCode.ActiveTestResp: var ActiveTestResp = new CmppActiveTestResp().FromBytes0(array); args = new CmppMessageReceiveArgs <IMessage, IMessage>(cmppHeader, ActiveTestResp); break; default: throw new NotSupportedException(cmppHeader.CommandId.ToString()); } return(args); } else { throw new InvalidDataException("The received cmpp package is invalid"); } } return(obj); }
public override void CmppDeliver(CmppMessageReceiveArgs <CmppHead, CmppDeliver> msg) { logger.Info("CmppDeliver receive: " + msg); }
public override void CmppDeliver(CmppMessageReceiveArgs <CmppHead, CmppDeliver> msg) { Console.WriteLine("SmsHandler接收数据: " + msg); }
public abstract void CmppDeliver(CmppMessageReceiveArgs <CmppHead, CmppDeliver> msg);