protected override async Task DoNetworkMessageReceived(SmsServerSession session, NetworkMessage message) { if (this._isSimulated) { await base.DoNetworkMessageReceived(session, message); return; } if (message is CmppMessageConnect) { var m = message as CmppMessageConnect; var isAuthenticated = this.IsAuthenticated(m); if (isAuthenticated) { var r = new CmppMessageConnectResponse(); r.SequenceId = m.SequenceId; r.Version = 0x30; r.AuthenticatorISMG = new byte[16]; r.Status = 0; session.UserId = m.SourceAddress; await session.SendAsync(r); this.OnSessionConnected(session); } else { var tmp = session.StopAsync(); } } else if (message is CmppMessageSubmit) { var m = message as CmppMessageSubmit; var r = new CmppMessageSubmitResponse(); r.SequenceId = m.SequenceId; r.MessasgeId = this.GetMessageId(); r.Result = 0; this.SubmitQueue.Enqueue(new CmppSmsServerSubmitContext() { Submit = m, MessageId = r.MessasgeId, UserId = session.UserId }); await session.SendAsync(r); } else if (message is CmppMessageActiveTest) { var m = message as CmppMessageActiveTest; var r = new CmppMessageActiveTestResponse(); r.SequenceId = m.SequenceId; await session.SendAsync(r); } }
private async Task DoReceiveBind(SmsServerSession session, SgipMessageBind message) { var response = new SgipMessageBindResponse() { SequenceId1 = message.SequenceId1, SequenceId2 = message.SequenceId2, SequenceId3 = message.SequenceId3 }; var userName = this.Configurations.UserName; var password = this.Configurations.Password; var u = message.LoginName; var p = message.Password; //send the response if (userName == u && password == p) { response.Status = 0; //SUCCESS session.IsAuthenticated = true; } else { response.Status = 1; //FAILED; } await session.SendAsync(response); }
public static async Task <bool> SendCmppUplinkAsync(this SmsServerSession session, CmppMessageDeliver deliver) { if (session == null) { return(false); } deliver.SequenceId = session.SequenceId; return(await session.SendAsync(deliver)); }
private async Task DoReceiveDeliver(SmsServerSession session, SgipMessageDeliver deliver) { var response = new SgipMessageDeliverResponse() { SequenceId1 = deliver.SequenceId1, SequenceId2 = deliver.SequenceId2, SequenceId3 = deliver.SequenceId3 }; response.Result = 0; await session.SendAsync(response); }
private async Task DoReceiveUnbind(SmsServerSession session, SgipMessageUnbind message) { var response = new SgipMessageUnbindResponse() { SequenceId1 = message.SequenceId1, SequenceId2 = message.SequenceId2, SequenceId3 = message.SequenceId3 }; await session.SendAsync(response); session.Terminate(); }
public static async Task <bool> SendSmgpUplinkAsync(this SmsServerSession session, SmgpMessageDeliver deliver) { if (session == null) { return(false); } try { deliver.SequenceId = session.SequenceId; return(await session.SendAsync(deliver)); } catch (Exception) { return(false); } }
private async Task DoReceiveReport(SmsServerSession session, SgipMessageReport report) { //sending response var response = new SgipMessageReportResponse() { SequenceId1 = report.SequenceId1, SequenceId2 = report.SequenceId2, SequenceId3 = report.SequenceId3 }; response.Result = 0; var t = session.SendAsync(response); this.RaiseReportReceived(report); await t; }
public static async Task <bool> SendCmppReportAsync(this SmsServerSession session, CmppMessageReport report) { var cmppServer = session.Server as CmppSmsServer; var serviceId = cmppServer.Configurations.ServiceID; var d = new CmppMessageDeliver() { SequenceId = session.SequenceId, Id = report.Id, Format = (byte)CmppEncodings.ASCII, ReceiverId = report.ReceiverTerminalId, ServiceId = serviceId, DeliveryReportRequired = 1, ServiceTerminalId = serviceId, LinkId = string.Empty }; d.SetReport(report); return(await session.SendAsync(d)); }
protected override async Task DoNetworkMessageReceived(SmsServerSession session, NetworkMessage message) { if (message is CmppMessageConnect) { var m = message as CmppMessageConnect; var r = new CmppMessageConnectResponse(); r.SequenceId = m.SequenceId; r.Version = 0x30; r.AuthenticatorISMG = new byte[16]; r.Status = 0; await session.SendAsync(r); } else if (message is CmppMessageSubmit) { var m = message as CmppMessageSubmit; var r = new CmppMessageSubmitResponse(); r.SequenceId = m.SequenceId; r.MessasgeId = this.GetMessageId(); r.Result = 0; await session.SendAsync(r); var time = DateTime.Now; var report = new CmppMessageReport() { Id = r.MessasgeId, Stat = "DELIVRD", ReceiverTerminalId = m.ReceiverTerminalIds[0], CompleteTime = time.AddMinutes(20).ToString("yyMMddHHmm"), SubmitTime = time.ToString("yyMMddHHmm"), SmscSequence = 0, }; var d = new CmppMessageDeliver() { SequenceId = this.SequenceId, Id = r.MessasgeId, Format = (byte)CmppEncodings.ASCII, ReceiverId = m.ReceiverTerminalIds[0], ServiceId = _serviceId, DeliveryReportRequired = 1,//状态报告 ServiceTerminalId = _serviceId, LinkId = string.Empty }; d.SetReport(report); await session.SendAsync(d); lock (this) { _submitCount++; var stamp = DateTime.Now; if (_startStamp == DateTime.MinValue) { _startStamp = stamp; } _endStamp = stamp; var tick = (long)(_endStamp - _startStamp).TotalSeconds; if (tick != _reportTick) { _reportTick = tick; Console.WriteLine("{0}: {1}...", _submitCount, stamp.ToLongTimeString()); } } } else if (message is CmppMessageActiveTest) { var m = message as CmppMessageActiveTest; var r = new CmppMessageActiveTestResponse(); r.SequenceId = m.SequenceId; await session.SendAsync(r); } }
protected override async Task DoNetworkMessageReceived(SmsServerSession session, NetworkMessage message) { if (message is SmgpMessageLogin) { var m = message as SmgpMessageLogin; var r = new SmgpMessageLoginResponse(); r.SequenceId = m.SequenceId; r.Version = m.Version; r.Signature = new byte[16]; r.Status = 0; await session.SendAsync(r); } else if (message is SmgpMessageSubmit) { var m = message as SmgpMessageSubmit; var r = new SmgpMessageSubmitResponse(); r.SequenceId = m.SequenceId; r.Status = 0; r.Id = Guid.NewGuid().ToByteArray().Take(10).ToArray(); await session.SendAsync(r); var time = DateTime.UtcNow; var report = new SmgpMessageReport(); report.Id = r.Id; report.Status = "DELIVRD"; report.SubmitTime = time.ToString("yyMMddHHmm"); report.CompleteTime = time.ToString("yyMMddHHmm"); report.Text = Encoding.GetEncoding("gb2312").GetBytes(m.Content); report.Error = "001"; //err report.Submited = "001"; //sub report.Delivered = "001"; //dkvrd; var d = new SmgpMessageDeliver() { SequenceId = this.SequenceId, Id = r.Id, Format = (byte)SmgpEncodings.GBK, ReceiverId = m.ReceiverIds[0], ReportRequired = 1,//IsReport SenderId = m.SenderId, ReceiveTime = time.ToString("yyyyMMddHHmmss") }; d.SetReport(report); await session.SendAsync(d); lock (this) { _submitCount++; var stamp = DateTime.Now; if (_startStamp == DateTime.MinValue) { _startStamp = stamp; } _endStamp = stamp; var tick = (long)(_endStamp - _startStamp).TotalSeconds; if (tick != _reportTick) { _reportTick = tick; Console.WriteLine("{0}: {1}...", _submitCount, stamp.ToLongTimeString()); } } } else if (message is SmgpMessageActiveTest) { var m = message as SmgpMessageActiveTest; var r = new SmgpMessageActiveTestResponse(); r.SequenceId = m.SequenceId; await session.SendAsync(r); } }
protected override async Task DoNetworkMessageReceived(SmsServerSession session, NetworkMessage message) { if (message is SgipMessageBind) { var m = message as SgipMessageBind; var r = new SgipMessageBindResponse(); r.SequenceId1 = m.SequenceId1; r.SequenceId2 = m.SequenceId2; r.SequenceId3 = m.SequenceId3; r.Status = 0; await session.SendAsync(r); } else if (message is SgipMessageSubmit) { var m = message as SgipMessageSubmit; var r = new SgipMessageSubmitResponse(); r.SequenceId1 = m.SequenceId1; r.SequenceId2 = m.SequenceId2; r.SequenceId3 = m.SequenceId3; r.Result = 0; await session.SendAsync(r); var report = new SgipMessageReport(); var sids = this.SequenceId; report.SequenceId3 = sids[0]; report.SequenceId2 = sids[1]; report.SequenceId1 = sids[2]; report.SubmitSequenceId3 = m.SequenceId3; report.SubmitSequenceId2 = m.SequenceId2; report.SubmitSequenceId1 = m.SequenceId1; report.State = 0; report.ErrorCode = 0; report.ReceiverNumber = m.ReceiverNumbers[0]; report.ReportRequired = 1; await this.Client.SendReportAsync(report); lock (this) { _submitCount++; var stamp = DateTime.Now; if (_startStamp == DateTime.MinValue) { _startStamp = stamp; } _endStamp = stamp; var tick = (long)(_endStamp - _startStamp).TotalSeconds; if (tick != _reportTick) { _reportTick = tick; Console.WriteLine("{0}: {1}...", _submitCount, stamp.ToLongTimeString()); } } } await Task.Delay(0); }