C#用短信猫发送短信和打电话(通用任何短信猫)
合集下载
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
strOut = "0011000D91" & Me.ReversalNumber(txtNum.Text) & "000801" & Me.ContentEncoding(txtMsg.Text) & Chr(26)
com.Output = strOut
End Sub
com.SThreshold = 0
com.InputMode = InputModeBinary
If com.PortOpen = False Then
Try
If Not (_phone.Substring(0, 2) = "86") Then
'检查手机号是否按标准格式书写,不是,就补上“”
_phone = [String].Format("86{0}", _phone)
End If
com.Output = "AT+CMGF=0" & vbCr '将短消息格式设置为PDU模式
System.Threading.Thread.Sleep(300)
com.Output = "AT+CSCA=" & "+86" & num & vbCr
For i As Integer = 0 To encodedBytes.Length - 1
s += BitConverter.ToString(encodedBytes, i, 1)
Next
s = [String].Format("{0:X2}{1}", s.Length \ 2, s)
Dim encodingUTF As Encoding = System.Text.Encoding.BigEndianUnicode
Dim s As String = String.Empty
Dim encodedBytes As Byte() = encodingUTF.GetBytes(_srvContent)
Return s
End Function
第二步:将手机号码转换为内存编码格式
'将手机号码转换为内存编码
Public Shared Function ReversalNumber(ByVal _phone As String) As String
Dim _strResult As String = String.Empty
com.Output = "ATD" & txtNum.Text & ";" & vbCr
End Sub
发送短信代码:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
最近在做一个项目,需要在接到报警信息后要将相关信息发送到110中心,买了短信猫,却没有开发包现功能。
首先:需要将汉字解码为16进制
'汉字解码为16进制
Public Shared Function ContentEncoding(ByVal _srvContent As String) As String
Dim j As Integer = 0
Dim s As String
For i As Integer = 0 To bytestr.GetLength(0) - 1
If i Mod 2 = 0 Then
j += 1
Dim _eachnumber As Char() = getchar(_phone)
For i As Integer = 0 To _eachnumber.Length - 2 Step 2
_strResult += (_eachnumber(i + 1).ToString() & _eachnumber(i).ToString())
com.PortOpen = True
Catch ex As Exception
MessageBox.Show("串口打开失败!", "提示", MessageBoxButtons.OK, rmation)
s = j.ToString()
Return s
End Function
第四步:从配置文件中读取端口号,服务中心号码等信息
Dim ports As Integer '端口号
Dim str As String '配置字符串
Dim num As String '服务中心号码
Environment.Exit(1)
End Try
End If
End Sub
拨打电话代码:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Next
Return _strResult
End Function
Public Shared Function getchar(ByVal phone As String) As Char()
If phone.Length Mod 2 = 0 Then
Input(1, str)
Input(1, num)
FileClose(1)
mPort = ports
com.Settings = str
com.InputLen = 0
com.RThreshold = 1
Return Convert.ToString(phone).ToCharArray()
Else
Return Convert.ToString(phone & "F").ToCharArray()
End If
End Function
第三步:获得短信内容的字节数
'获得短信内容的字节数
Public Function bytelenght(ByVal str As String) As String
Dim bytestr As Byte() = System.Text.Encoding.Unicode.GetBytes(str)
Else
If bytestr(i) > 0 Then
j += 1
End If
End If
Next
j = j + 15
System.Threading.Thread.Sleep(300)
com.Output = "AT+CMGS=0" & Me.bytelenght(txtMsg.Text) & vbCr
System.Threading.Thread.Sleep(500)
Dim strOut As String
Private Sub initcom(ห้องสมุดไป่ตู้
Dim temp As String
FileOpen(1, "com.dll", OpenMode.Input)
Input(1, temp)
Input(1, ports)
com.Output = strOut
End Sub
com.SThreshold = 0
com.InputMode = InputModeBinary
If com.PortOpen = False Then
Try
If Not (_phone.Substring(0, 2) = "86") Then
'检查手机号是否按标准格式书写,不是,就补上“”
_phone = [String].Format("86{0}", _phone)
End If
com.Output = "AT+CMGF=0" & vbCr '将短消息格式设置为PDU模式
System.Threading.Thread.Sleep(300)
com.Output = "AT+CSCA=" & "+86" & num & vbCr
For i As Integer = 0 To encodedBytes.Length - 1
s += BitConverter.ToString(encodedBytes, i, 1)
Next
s = [String].Format("{0:X2}{1}", s.Length \ 2, s)
Dim encodingUTF As Encoding = System.Text.Encoding.BigEndianUnicode
Dim s As String = String.Empty
Dim encodedBytes As Byte() = encodingUTF.GetBytes(_srvContent)
Return s
End Function
第二步:将手机号码转换为内存编码格式
'将手机号码转换为内存编码
Public Shared Function ReversalNumber(ByVal _phone As String) As String
Dim _strResult As String = String.Empty
com.Output = "ATD" & txtNum.Text & ";" & vbCr
End Sub
发送短信代码:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
最近在做一个项目,需要在接到报警信息后要将相关信息发送到110中心,买了短信猫,却没有开发包现功能。
首先:需要将汉字解码为16进制
'汉字解码为16进制
Public Shared Function ContentEncoding(ByVal _srvContent As String) As String
Dim j As Integer = 0
Dim s As String
For i As Integer = 0 To bytestr.GetLength(0) - 1
If i Mod 2 = 0 Then
j += 1
Dim _eachnumber As Char() = getchar(_phone)
For i As Integer = 0 To _eachnumber.Length - 2 Step 2
_strResult += (_eachnumber(i + 1).ToString() & _eachnumber(i).ToString())
com.PortOpen = True
Catch ex As Exception
MessageBox.Show("串口打开失败!", "提示", MessageBoxButtons.OK, rmation)
s = j.ToString()
Return s
End Function
第四步:从配置文件中读取端口号,服务中心号码等信息
Dim ports As Integer '端口号
Dim str As String '配置字符串
Dim num As String '服务中心号码
Environment.Exit(1)
End Try
End If
End Sub
拨打电话代码:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Next
Return _strResult
End Function
Public Shared Function getchar(ByVal phone As String) As Char()
If phone.Length Mod 2 = 0 Then
Input(1, str)
Input(1, num)
FileClose(1)
mPort = ports
com.Settings = str
com.InputLen = 0
com.RThreshold = 1
Return Convert.ToString(phone).ToCharArray()
Else
Return Convert.ToString(phone & "F").ToCharArray()
End If
End Function
第三步:获得短信内容的字节数
'获得短信内容的字节数
Public Function bytelenght(ByVal str As String) As String
Dim bytestr As Byte() = System.Text.Encoding.Unicode.GetBytes(str)
Else
If bytestr(i) > 0 Then
j += 1
End If
End If
Next
j = j + 15
System.Threading.Thread.Sleep(300)
com.Output = "AT+CMGS=0" & Me.bytelenght(txtMsg.Text) & vbCr
System.Threading.Thread.Sleep(500)
Dim strOut As String
Private Sub initcom(ห้องสมุดไป่ตู้
Dim temp As String
FileOpen(1, "com.dll", OpenMode.Input)
Input(1, temp)
Input(1, ports)