我使用sql从GSMComm数据库向客户端发送短信。我已经阅读了来自Send SMS with Delivery Report的给定答案,但它不起作用。我在发送短信时检查了RequestStatusReport是否为真,并通过comm_MessageReceived()事件得到了状态报告。但是从这个事件中,我只能得到状态报告的索引和存储。我需要此状态报告的来源或来源的编号(RecipientAddress)。但是当我使用代码来获取它时,它返回空值。如果有人能给出解决方案,我将非常感激。我正在使用3g调制解调器发送短信。
/*Message Receive Event*/
private void comm_MessageReceived(object sender, MessageReceivedEventArgs e)
{
try
{
IMessageIndicationObject obj = e.IndicationObject;
if (obj is MemoryLocation) //Get status report for this condition
{
MemoryLocation loc = (MemoryLocation)obj;
Output(string.Format("New message received in storage \"{0}\", index {1}.",
loc.Storage, loc.Index));
Output("");
SmsStatusReportPdu pdu = new SmsStatusReportPdu();
ShowMessage(pdu);
return;
}
if (obj is ShortMessage)
{
ShortMessage msg = (ShortMessage)obj;
SmsPdu pdu = comm.DecodeReceivedMessage(msg);
Output("New message received:");
ShowMessage(pdu);
Output("");
return;
}
Output("Error: Unknown notification object!");
}
catch (Exception ex)
{
ShowException(ex);
}
}
private void ShowMessage(SmsPdu pdu)
{
if (pdu is SmsSubmitPdu)
{
// Stored (sent/unsent) message
SmsSubmitPdu data = (SmsSubmitPdu)pdu;
Output("SENT/UNSENT MESSAGE");
Output("Recipient: " + data.DestinationAddress);
Output("Message text: " + data.UserDataText);
Output("-------------------------------------------------------------------");
return;
}
if (pdu is SmsDeliverPdu)
{
// Received message
SmsDeliverPdu data = (SmsDeliverPdu)pdu;
Output("RECEIVED MESSAGE");
Output("Sender: " + data.OriginatingAddress);
Output("Sent: " + data.SCTimestamp.ToString());
Output("Message text: " + data.UserDataText);
Output("-------------------------------------------------------------------");
return;
}
if (pdu is SmsStatusReportPdu)
{
// Status report
SmsStatusReportPdu data = (SmsStatusReportPdu)pdu;
Output("STATUS REPORT");
Output("Recipient: " + data.RecipientAddress); //Null value
Output("Status: " + data.Status.ToString());
Output("Timestamp: " + data.DischargeTime.ToString());
Output("Message ref: " + data.MessageReference.ToString());
Output("-------------------------------------------------------------------");
return;
}
Output("Unknown message type: " + pdu.GetType().ToString());
}发布于 2014-02-16 04:55:36
难怪在第一种情况下会得到空值--您创建了一个空对象,而不是读取消息: SmsStatusReportPdu pdu = RecipientAddress SmsStatusReportPdu()
这应该适用于存储在SIM存储器中的交付报告:
DecodedShortMessage msg = _comm.ReadMessage(ind.Index, ind.Storage);
SmsStatusReportPdu spdu = pdu as PDU.SmsStatusReportPdu;
if (spdu != null)
{
//do something with the status report
Console.WriteLine(spdu.RecipientAddress);
}https://stackoverflow.com/questions/20865424
复制相似问题