【发布时间】:2014-02-16 04:55:36
【问题描述】:
我使用 GSMComm API 从 sql 数据库向客户端发送短信。我已经阅读了来自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());
}
【问题讨论】:
-
希望有人能给出这个答案...