通过Windows应用程序发送短信

通过Windows应用程序发送短信

我想通过Windows应用程序发送短信。我运行了代码,但出现错误。这是

AT

OK AT+CMGF=1

OK AT+CSCA="+9460921985"

OK AT+CMGS="+9660775564"

    this is new message

+CMS ERROR: 500

我正在使用此代码。
Public Class Form2
  Dim number As String = "+9660775564"
  ''# Dim message As String = TextBox1.Text
  Dim serialport As New IO.Ports.SerialPort

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Try With serialport
      .PortName = "COM5" ''# "COM24"
      .BaudRate = "9600"
      .Parity = IO.Ports.Parity.None
      .DataBits = 8
      .StopBits = IO.Ports.StopBits.One
      .Handshake = IO.Ports.Handshake.RequestToSend
      .DtrEnable = True .RtsEnable = True
    End With

    serialport.Open()
    ''# checks phone status
    serialport.WriteLine("AT" & vbCrLf)
    ''# Configures message as SMS
    serialport.WriteLine("AT+CMGF=1" & vbCrLf)
    ''# Sets message center number
    ''# serialport.WriteLine("AT+CSCA=""+447785016005""" & vbCrLf)
    serialport.WriteLine("AT+CSCA=""+9460921985""" & vbCrLf)
    ''# Sets destination number
    serialport.WriteLine("AT+CMGS=""" & number & """" & vbCrLf)
    ''# Specifies message and sends Ctrl+z
    serialport.WriteLine(TextBox1.Text & Chr(26))
    ''# Displays buffer containing output messages
    System.Threading.Thread.Sleep(2000) ''# CurrentThread.Sleep(2000)
    MsgBox(serialport.ReadExisting)
    serialport.Close()
    MessageBox.Show("OK")

  Catch ex As Exception
    MessageBox.Show(ex.Message)
  End Try
End Sub

在此先感谢您的帮助。

最佳答案

我完全没有编写SMS的经验,但是您似乎正在调用serialPort.WriteLine以及在行尾追加vbCrLf。

其次,您确定要的是vbCrLf吗?我所看到的一些内容仅指“回车”​​,即vbCr。

关于.net - 如何通过Windows应用程序发送短信,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/920407/

10-09 02:00