首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用GSMComm的短信投递报告

使用GSMComm的短信投递报告
EN

Stack Overflow用户
提问于 2014-01-01 12:00:23
回答 1查看 2.3K关注 0票数 0

我使用sql从GSMComm数据库向客户端发送短信。我已经阅读了来自Send SMS with Delivery Report的给定答案,但它不起作用。我在发送短信时检查了RequestStatusReport是否为真,并通过comm_MessageReceived()事件得到了状态报告。但是从这个事件中,我只能得到状态报告的索引和存储。我需要此状态报告的来源或来源的编号(RecipientAddress)。但是当我使用代码来获取它时,它返回空值。如果有人能给出解决方案,我将非常感激。我正在使用3g调制解调器发送短信。

代码语言:javascript
复制
/*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());
 }
EN

回答 1

Stack Overflow用户

发布于 2014-02-16 04:55:36

难怪在第一种情况下会得到空值--您创建了一个空对象,而不是读取消息: SmsStatusReportPdu pdu = RecipientAddress SmsStatusReportPdu()

这应该适用于存储在SIM存储器中的交付报告:

代码语言:javascript
复制
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);
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20865424

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档