private void PduReceivedEventHander(object sender, PduReceivedEventArgs e) { //This handler is interested in SingleDestinationPDU only SingleDestinationPdu pdu = e.Request as SingleDestinationPdu; if (pdu == null) { return; } //If we have just a normal message if (((byte)pdu.EsmClass | 0xc3) == 0xc3) { ShortMessage message; try { message = MessageFactory.CreateMessage(pdu); } catch (SmppException smppEx) { if (VTraceSwitch.TraceError) { Trace.WriteLine(string.Format( "200019:SMPP message decoding failure - {0} - {1} {2};", smppEx.ErrorCode, new ByteBuffer(pdu.GetBytes()).DumpString(), smppEx.Message)); } //Notify the SMSC that we encountered an error while processing the message e.Response = pdu.CreateDefaultResponce(); e.Response.Header.ErrorCode = smppEx.ErrorCode; return; } catch (Exception ex) { if (VTraceSwitch.TraceError) { Trace.WriteLine(string.Format( "200019:SMPP message decoding failure - {0} {1};", new ByteBuffer(pdu.GetBytes()).DumpString(), ex.Message)); } //Let the receiver know that this message was rejected e.Response = pdu.CreateDefaultResponce(); e.Response.Header.ErrorCode = SmppErrorCode.EsmeRxPAppn; //ESME Receiver Reject Message return; } RaiseMessageReceivedEvent(message); } //Or if we have received a delivery receipt else if ((pdu.EsmClass & EsmClass.DeliveryReceipt) == EsmClass.DeliveryReceipt) { // Extract receipted message id var receiptedMessageIdTlv = pdu.Tlv.GetTlvByTag(Tag.ReceiptedMessageId); string receiptedMessageId = null; if (receiptedMessageIdTlv != null) { receiptedMessageId = SmppEncodingUtil.GetCStringFromBytes(receiptedMessageIdTlv.RawValue); } RaiseMessageDeliveredEvent(receiptedMessageId); } }
private void PduReceivedEventHander(object sender, PduReceivedEventArgs e) { MessageBox.Show("Сработало событие received"); SingleDestinationPDU pdu = e.Request as SingleDestinationPDU; if (pdu == null) { return; } Udh udh = null; //We need to test if the UDH field is present string message = null; //This will hold the message text pdu.GetMessageText(out message, out udh); //Get message text and UDH from the PDU MessageBox.Show("Пришедшее на номер: " + message + " , " + pdu.Header.ErrorCode.ToString()); }
private void PduReceivedEventHander(object sender, PduReceivedEventArgs e) { //This handler is interested in SingleDestinationPDU only SingleDestinationPDU pdu = e.Request as SingleDestinationPDU; if (pdu == null) { return; } if (_Log.IsDebugEnabled) { _Log.DebugFormat("Received PDU: {0}", LoggingExtensions.DumpStrig(pdu, vSmppEncodingService)); } if (vTraceSwitch.TraceVerbose) { Trace.WriteLine(string.Format("PduReceived: RequestType: {0}", e.Request?.GetType()?.Name)); } ShortMessage message = null; try { message = MessageFactory.CreateMessage(pdu); } catch (SmppException smppEx) { _Log.ErrorFormat("200019:SMPP message decoding failure - {0} - {1} {2}", smppEx, smppEx.ErrorCode, new ByteBuffer(pdu.GetBytes()).DumpString(), smppEx.Message); if (vTraceSwitch.TraceError) { Trace.WriteLine(string.Format( "200019:SMPP message decoding failure - {0} - {1} {2};", smppEx.ErrorCode, new ByteBuffer(pdu.GetBytes()).DumpString(), smppEx.Message)); } //Notify the SMSC that we encountered an error while processing the message e.Response = pdu.CreateDefaultResponce(); e.Response.Header.ErrorCode = smppEx.ErrorCode; return; } catch (Exception ex) { _Log.ErrorFormat("200019:SMPP message decoding failure - {0}", ex, new ByteBuffer(pdu.GetBytes()).DumpString()); if (vTraceSwitch.TraceError) { Trace.WriteLine(string.Format( "200019:SMPP message decoding failure - {0} {1};", new ByteBuffer(pdu.GetBytes()).DumpString(), ex.Message)); } //Let the receiver know that this message was rejected e.Response = pdu.CreateDefaultResponce(); e.Response.Header.ErrorCode = SmppErrorCode.ESME_RX_P_APPN; //ESME Receiver Reject Message return; } if (message != null && _Log.IsDebugEnabled) { _Log.DebugFormat("PduReceived: message: {0}", LoggingExtensions.DumpStrig(message, vSmppEncodingService)); } if (vTraceSwitch.TraceVerbose) { #if DEBUG Console.WriteLine(string.Format("PduReceived: pdu: Header:{0}, EsmClass:{1}, ServiceType:{2}, DataCoding:{3}", pdu.Header, pdu.EsmClass, pdu.ServiceType, pdu.DataCoding)); #endif Trace.WriteLine(string.Format("PduReceived: pdu: Header:{0}, EsmClass:{1}, ServiceType:{2}, DataCoding:{3}", pdu.Header, pdu.EsmClass, pdu.ServiceType, pdu.DataCoding)); if (message != null) { Trace.WriteLine(string.Format("PduReceived: message: DestinationAddress:{0}, MessageCount:{1}, ReceiptedMessageId:{2}, RegisterDeliveryNotification:{3}, SegmentID:{4}, SequenceNumber:{5}, SourceAddress:{6}, UserMessageReference:{7}", message.DestinationAddress, message.MessageCount, message.ReceiptedMessageId, message.RegisterDeliveryNotification, message.SegmentID, message.SequenceNumber, message.SourceAddress, message.UserMessageReference)); } } //If we have just a normal message if ((((byte)pdu.EsmClass) | 0xc3) == 0xc3) { RaiseMessageReceivedEvent(message); } //Or if we have received a delivery receipt else if ((pdu.EsmClass & EsmClass.DeliveryReceipt) == EsmClass.DeliveryReceipt) { // Extract receipted message id message.ReceiptedMessageId = pdu.GetOptionalParamString(Tag.receipted_message_id); // Extract user message reference message.UserMessageReference = pdu.GetOptionalParamString(Tag.user_message_reference); RaiseMessageDeliveredEvent(message); } }