我已经使用GSMComm API从sql数据库向客户端发送短信。我已经阅读了Send SMS with Delivery Report给出的答案,但它没有奏效。我在发送短信时检查了RequestStatusReport为true,并使用comm_MessageReceived()事件获取状态报告。但是从这个事件中我只得到状态报告的索引和存储。我想要这个状态报告所来自的号码(RecipientAddress)。但是当我使用代码来获取它时,它返回null值。如果有人给出解决方案,我将非常感激。我使用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());
}
答案 0 :(得分:0)
难怪你在第一种情况下得到null RecipientAddress - 你创建了一个空对象而不是读取消息: SmsStatusReportPdu pdu = new 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);
}