发送超过160个字符的短信 [英] send sms with more than 160 characters

查看:132
本文介绍了发送超过160个字符的短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#开发SMS系统。我使用GSMCOMM

如何发送超过160个字符的短信,并让客户收到短信作为一个短信

我的代码是

I'm developing SMS system using C#. I use GSMCOMM
how to send sms with more than 160 characters and enable the customer to receive cut SMS as ONE SMS
My code is

  public ShortMessageCollection ReadSMS(SerialPort port, string p_strCommand)
        {

            // Set up the phone and read the messages
            ShortMessageCollection messages = null;
            try
            {

                #region Execute Command
                // Check connection
                ExecCommand(port, "AT", 5000, "No phone connected");
                // Use message format "Text mode"
                ExecCommand(port, "AT+CMGF=1", 5000, "Failed to set message format.");
                // Use character set "PCCP437"
                //ExecCommand(port,"AT+CSCS=\"PCCP437\"", 300, "Failed to set character set.");
                // Select SIM storage
                ExecCommand(port, "AT+CSCS=\"GSM\"", 5000, "Failed to set character set.");
                ExecCommand(port, "AT+CPMS=\"SM\"", 5000, "Failed to select message storage.");
                // Read the messages
                string input = ExecCommand(port, p_strCommand, 5000, "Failed to read the messages.");
                #endregion

                #region Parse messages
                messages = ParseMessages(input);
                #endregion

            }
            catch (Exception ex)
            {
                throw ex;
            }

            if (messages != null)
                return messages;
            else
                return null;

        }
public ShortMessageCollection ParseMessages(string input)
{
    var r = new Regex(@"\+CMGL: (\d+),""(.+)"",""(.+)"",(.*),""(.+)""",
        RegexOptions.Compiled);
    var messages = new ShortMessageCollection();
    using (var sw = new StringReader(input))
    {
        string currentLine = sw.ReadLine();
        while (currentLine != null)
        {
            var m = r.Match(currentLine);
            if (m.Success)
            {
                // read the first line of the message
                string message = string.Empty;
                currentLine = sw.ReadLine();

                // Append any extra lines to our message, unless it's a new record
                while (currentLine != null && !r.IsMatch(currentLine))
                {
                    message += Environment.NewLine;
                    message += currentLine;

                    currentLine = sw.ReadLine();
                }

                messages.Add(new ShortMessage
                {
                    Index = m.Groups[1].Value,
                    Status = m.Groups[2].Value,
                    Sender = m.Groups[3].Value,
                    Alphabet = m.Groups[4].Value,
                    Sent = m.Groups[5].Value,
                    Message = message,
                });
            }
            else
            {
                        
                currentLine = sw.ReadLine();
            }
        }
    }
    return messages;
}

推荐答案

你想要使用SmartMessageFactory [ ^ ]用于创建连接的消息,SmartMessageDecoder [ ^ ]将一组多部分消息组合回一个。



我认为有一个名为 ReadRawPduMessage 的方法或类似的东西,你可以使用它来获取消息的Pdu,然后我检查它是否是一个多部分消息,是否使用 SmartMessageDecoder 来构建连接结果。



希望这会有所帮助,

Fredrik
You'll want to use the SmartMessageFactory[^] for creating the concatenated messages, and SmartMessageDecoder[^] to assemble a set of multipart messages back to one.

I think there's a method called ReadRawPduMessage or something like that that you can use to get the Pdu of the message, then inspect that to see if it is a multipart message and if it is use SmartMessageDecoder to build op the concatenated result.

Hope this helps,
Fredrik


这篇关于发送超过160个字符的短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆