void SWSet(SlidingWindow send) { lock (_sendWindows) { for (int i = 0; i < _sendWindows.Length; i++) { if (_sendWindows[i].Status == WindowStatus.Idle) { _sendWindows[i] = send; _sendWindows[i].Status = WindowStatus.Fill; _sendsCount++; return; } } } }
private List <SlidingWindow> GetSend(SMS sms) { List <SlidingWindow> submits = new List <SlidingWindow>(); //拆分长消息 int pkSize; int pkNum = SMSSplit.GetSplitNumber(sms.Content, sms.Signature, out pkSize); if (pkNum > 1) { for (int j = 0; j < sms.Number.Count; j++) { string content = sms.Content; //发送号码 for (int i = 0; i < pkNum; i++) { SGIP_SUBMIT submit = new SGIP_SUBMIT(Sequence.Instance.CreateID()); submit.Pk_total = (byte)pkNum; submit.Pk_number = (byte)(i + 1); //SPID submit.SPNumber = _setting.SrcID + sms.SPNumber; //被计费用户号码 submit.ChargeNumber = Setting.ChargeNumber; submit.UserCount = 1; submit.CorpId = Setting.CorpId; submit.ServiceType = Setting.ServiceType; submit.FeeType = Setting.FeeType; submit.FeeValue = Setting.FeeValue; //赠送用户的话费 submit.GivenValue = "0"; //代收费标志 submit.AgentFlag = (uint)SubmitAgentFlag.RealIncome; submit.MorelatetoMTFlag = 2; //优先级 submit.Priority = 0; //sms.Level; submit.ExpireTime = ""; // Setting.ExpireTime; submit.ScheduleTime = ""; // sms.SendTime.ToString(); //状态报告 submit.ReportFlag = (byte)1; //sms.StatusReport == StatusReportType.Disable ? (byte)2 : (byte)1; submit.TP_pid = 0; submit.TP_udhi = 1; submit.MessageCoding = 8; submit.MessageType = 0; submit.LinkID = ""; submit.WapURL = sms.WapURL; submit.MessageContent = SMSSplit.GetSubString(content, pkSize); content = content.Substring(submit.MessageContent.Length); if (submit.Pk_number == pkNum) { submit.MessageContent = submit.MessageContent + sms.Signature; } submit.SetHeader(); submit.UserNumber = sms.Number[j]; if (submit.UserNumber.Length == 11) { submit.UserNumber = "86" + submit.UserNumber; } SlidingWindow _send = new SlidingWindow(); string serial = submit.Header.SrcNodeSequence.ToString() + submit.Header.DateSequence.ToString() + submit.Header.Sequence_Id.ToString(); SMS tsms = new SMS(); tsms.Account = sms.Account; tsms.Audit = sms.Audit; tsms.Channel = sms.Channel; tsms.Content = submit.MessageContent; tsms.Filter = sms.Filter; tsms.Level = sms.Level; tsms.Number = sms.Number; tsms.SendTime = sms.SendTime; tsms.SerialNumber = sms.SerialNumber; tsms.StatusReport = sms.StatusReport; tsms.Signature = sms.Signature; tsms.SPNumber = sms.SPNumber; tsms.WapURL = sms.WapURL; _send.Report = new SendEventArgs(tsms, serial, false, ((ushort)PlatformCode.SGIP + (ushort)SystemCode.SendReady), "", (ushort)submit.Pk_total, (ushort)submit.Pk_number); _send.MSG = submit; _send.SendCount = 0; _send.SendTime = DateTime.Now; _send.Status = WindowStatus.Fill; submits.Add(_send); } } } else { for (int j = 0; j < sms.Number.Count; j++) { //发送号码 SGIP_SUBMIT submit = new SGIP_SUBMIT(Sequence.Instance.CreateID()); submit.Pk_total = 1; submit.Pk_number = 1; //SPID submit.SPNumber = _setting.SrcID + sms.SPNumber; //被计费用户号码 submit.ChargeNumber = Setting.ChargeNumber; submit.UserCount = 1; submit.CorpId = Setting.CorpId; submit.ServiceType = Setting.ServiceType; submit.FeeType = Setting.FeeType; submit.FeeValue = Setting.FeeValue; //赠送用户的话费 submit.GivenValue = "0"; //代收费标志 submit.AgentFlag = (uint)SubmitAgentFlag.RealIncome; submit.MorelatetoMTFlag = 2; //优先级 submit.Priority = 0; //sms.Level; submit.ExpireTime = ""; //Setting.ExpireTime; submit.ScheduleTime = ""; //sms.SendTime.ToString(); //状态报告 submit.ReportFlag = sms.StatusReport == StatusReportType.Disable ? (byte)2 : (byte)1; submit.TP_pid = 0; submit.TP_udhi = 0; submit.MessageCoding = 15; submit.MessageType = 0; submit.LinkID = ""; submit.WapURL = sms.WapURL; submit.MessageContent = sms.Content + sms.Signature; submit.SetHeader(); submit.UserNumber = sms.Number[j]; if (submit.UserNumber.Length == 11) { submit.UserNumber = "86" + submit.UserNumber; } SlidingWindow _send = new SlidingWindow(); string serial = submit.Header.SrcNodeSequence.ToString() + submit.Header.DateSequence.ToString() + submit.Header.Sequence_Id.ToString(); SMS tsms = new SMS(); tsms.Account = sms.Account; tsms.Audit = sms.Audit; tsms.Channel = sms.Channel; tsms.Content = submit.MessageContent; tsms.Filter = sms.Filter; tsms.Level = sms.Level; tsms.Number = sms.Number; tsms.SendTime = sms.SendTime; tsms.SerialNumber = sms.SerialNumber; tsms.StatusReport = sms.StatusReport; tsms.Signature = sms.Signature; tsms.SPNumber = sms.SPNumber; tsms.WapURL = sms.WapURL; _send.Report = new SendEventArgs(tsms, serial, false, ((ushort)PlatformCode.SGIP + (ushort)SystemCode.SendReady), "", (ushort)submit.Pk_total, (ushort)submit.Pk_number); _send.MSG = submit; _send.SendCount = 0; _send.SendTime = DateTime.Now; _send.Status = WindowStatus.Fill; submits.Add(_send); } } return(submits); }
public void SendSubmit(SMS sms) { SGIPSUBMIT sb = sms.Extend as SGIPSUBMIT; if (sb == null) { return; } //发送号码 SGIP_SUBMIT submit = new SGIP_SUBMIT(Sequence.Instance.CreateID()); submit.Pk_total = sb.Pk_total; submit.Pk_number = sb.Pk_number; //SPID submit.SPNumber = sb.SPNumber; //被计费用户号码 submit.ChargeNumber = sb.ChargeNumber; submit.UserCount = sb.UserCount; submit.CorpId = sb.CorpId; submit.ServiceType = sb.ServiceType; submit.FeeType = sb.FeeType; submit.FeeValue = sb.FeeValue; //赠送用户的话费 submit.GivenValue = sb.GivenValue; //代收费标志 submit.AgentFlag = sb.AgentFlag; submit.MorelatetoMTFlag = sb.MorelatetoMTFlag; //优先级 submit.Priority = sb.Priority; submit.ExpireTime = sb.ExpireTime; submit.ScheduleTime = sb.ScheduleTime; //状态报告 submit.ReportFlag = sb.ReportFlag; submit.TP_pid = sb.TP_pid; submit.TP_udhi = sb.TP_udhi; submit.MessageCoding = sb.MessageCoding; submit.MessageType = sb.MessageType; submit.LinkID = sb.LinkID; submit.WapURL = sb.WapURL; submit.MessageContent = sb.MessageContent; submit.UserNumber = sb.UserNumber; SlidingWindow _send = new SlidingWindow(); string serial = submit.Header.SrcNodeSequence.ToString() + submit.Header.DateSequence.ToString() + submit.Header.Sequence_Id.ToString(); SMS tsms = new SMS(); tsms.Account = sms.Account; tsms.Audit = sms.Audit; tsms.Channel = sms.Channel; tsms.Content = submit.MessageContent; tsms.Filter = sms.Filter; tsms.Level = sms.Level; tsms.Number = sms.Number; tsms.SendTime = sms.SendTime; tsms.SerialNumber = sms.SerialNumber; tsms.StatusReport = sms.StatusReport; tsms.Signature = sms.Signature; tsms.SPNumber = sms.SPNumber; tsms.WapURL = sms.WapURL; _send.Report = new SendEventArgs(tsms, serial, false, ((ushort)PlatformCode.SGIP + (ushort)SystemCode.SendReady), "", (ushort)submit.Pk_total, (ushort)submit.Pk_number); _send.MSG = submit; _send.SendCount = 0; _send.SendTime = DateTime.Now; _send.Status = WindowStatus.Fill; while (true) { if (Ready == 0) { Thread.Sleep(10); continue; } SWSet(_send); ClientSend(_send.MSG); DebugLog.Instance.Write <SGIP_SUBMIT>("Client SendSubmit -> SGIP_SUBMIT", (SGIP_SUBMIT)_send.MSG); break; } }
void _client_DataReceived(byte[] data) { SGIP_MESSAGE header; try { header = new SGIP_MESSAGE(data); } catch (Exception ex) { OnClientNetworkError(ex); return; } switch (header.Command_Id) { case SGIP_COMMAND.SGIP_BIND_RESP: SGIP_BIND_RESP sgip_bind_resp; try { sgip_bind_resp = new SGIP_BIND_RESP(data); } catch (Exception ex) { OnClientNetworkError(ex); return; } DebugLog.Instance.Write <SGIP_BIND_RESP>("Client Received -> SGIP_BIND_RESP", sgip_bind_resp); switch (sgip_bind_resp.Result) { case 0: _connect = true; autoConnectEvent.Set(); OnSMSEvent(new SMSEventArgs(SMS_Event.SP_CONNECT, "登录成功")); break; default: OnSMSEvent(new SMSEventArgs(SMS_Event.SP_CONNECT_ERROR, StateDictionary.StateRespDictionary(sgip_bind_resp.Result))); break; } break; case SGIP_COMMAND.SGIP_SUBMIT_RESP: SGIP_SUBMIT_RESP submit_resp; try { submit_resp = new SGIP_SUBMIT_RESP(data); } catch (Exception ex) { OnClientNetworkError(ex); return; } DebugLog.Instance.Write <SGIP_SUBMIT_RESP>("Client Received -> SGIP_SUBMIT_RESP", submit_resp); string serial = header.SrcNodeSequence.ToString() + header.DateSequence.ToString() + header.Sequence_Id.ToString(); SlidingWindow send = SWGet(serial); if (send.Status == WindowStatus.Idle) { return; } SWClr(serial); if (SendEvent != null) { send.Report.Succeed = false; switch (submit_resp.Result) { case 0: send.Report.Succeed = true; break; default: send.Report.Describe = StateDictionary.StateRespDictionary(submit_resp.Result); break; } send.Report.Serial = serial; SendEvent(this, send.Report); } break; case SGIP_COMMAND.SGIP_UNBIND: SGIP_UNBIND_RESP unbindResp; try { unbindResp = new SGIP_UNBIND_RESP(header.SrcNodeSequence, header.DateSequence, header.Sequence_Id); } catch (Exception ex) { OnClientNetworkError(ex); return; } DebugLog.Instance.Write("Client Received -> SGIP_UNBIND"); ClientSend(unbindResp); DebugLog.Instance.Write <SGIP_UNBIND_RESP>("Client Send -> SGIP_UNBIND_RESP", unbindResp); Thread.Sleep(1000); _connect = false; break; } }