📄 form1.vb
字号:
'Timer1
'
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(528, 382)
Me.Controls.Add(Me.Button7)
Me.Controls.Add(Me.Label9)
Me.Controls.Add(Me.Label8)
Me.Controls.Add(Me.ComboBox2)
Me.Controls.Add(Me.Label7)
Me.Controls.Add(Me.GroupBox2)
Me.Controls.Add(Me.GroupBox1)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.MaximizeBox = False
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "短信群发工具V1.0.0"
Me.GroupBox1.ResumeLayout(False)
CType(Me.msComm1, System.ComponentModel.ISupportInitialize).EndInit()
Me.GroupBox2.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ComboBox1.SelectedText = "COM1"
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
ListBox1.Items.Clear()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If ComboBox1.Text.Length = 4 Then
msComm1.CommPort = ComboBox1.Text.Substring(3)
msComm1.Settings = "9600,n,8,1"
On Error Resume Next
msComm1.PortOpen = True
If Err.Number = 0 Then
msComm1.OutBufferCount = 0 '清空发送缓冲区
msComm1.InBufferCount = 0 '滑空接收缓冲区
msComm1.InputMode = MSCommLib.InputModeConstants.comInputModeText
msComm1.InputLen = 0
msComm1.RThreshold = 1
msComm1.Handshaking = MSCommLib.HandshakeConstants.comNone
msComm1.RTSEnable = True
msComm1.NullDiscard = True
msComm1.DTREnable = True
Dim csca As String = TextBox1.Text
msComm1.Output = "AT+CSCA=" & """ & " + " & csca & """ & Chr(13)
Do
Application.DoEvents()
If msComm1.OutBufferCount = 0 Then
buf = msComm1.Input
End If
Loop Until InStr(buf, "OK") > 0 Or InStr(buf, "ERROR") > 0
buf = ""
msComm1.Output = "AT+CMGF=0" & Chr(13)
Do
Application.DoEvents()
If msComm1.OutBufferCount = 0 Then
buf = msComm1.Input
End If
Loop Until InStr(buf, "OK") > 0 Or InStr(buf, "ERROR") > 0
buf = ""
msComm1.Output = "AT+CMEE=0" & Chr(13)
Do
Application.DoEvents()
If msComm1.OutBufferCount = 0 Then
buf = msComm1.Input
End If
Loop Until InStr(buf, "OK") > 0 Or InStr(buf, "ERROR") > 0
buf = ""
msComm1.Output = "AT+CSCS=" & Chr(&H22) & "GSM" & Chr(&H22) & Chr(13)
Do
Application.DoEvents()
If msComm1.OutBufferCount = 0 Then
buf = msComm1.Input
End If
Loop Until InStr(buf, "OK") > 0 Or InStr(buf, "ERROR") > 0
buf = ""
MsgBox("手机连接成功!", MsgBoxStyle.Information, "手机连接")
Button1.Enabled = False
Button2.Enabled = True
Button5.Enabled = True
Else
MsgBox("端口设置错误,请重新设置!", MsgBoxStyle.Critical, "错误")
End If
Else
MsgBox("端口设置错误,请重新设置!", MsgBoxStyle.Critical, "错误")
End If
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
End
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
OpenFileDialog1.ShowDialog()
Dim filename As String = OpenFileDialog1.FileName
Dim txtfile As StreamReader
If filename.Length > 0 Then
txtfile = File.OpenText(filename)
ListBox1.Items.Clear()
Dim msno As String
Do
msno = txtfile.ReadLine()
If msno <> "" Then
msno = Trim(msno)
ListBox1.Items.Add(msno)
End If
Loop Until msno = ""
txtfile.Close()
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
msComm1.PortOpen = False
Button2.Enabled = False
Button1.Enabled = True
Button5.Enabled = False
MsgBox("手机断开成功!", MsgBoxStyle.Information, "手机连接")
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
ms_count = ListBox1.Items.Count
sms = TextBox2.Text '短信内容
sms_center = TextBox1.Text '短信中心
sms_len = Hex(TextBox2.Text.Length * 2) '短信长度
If sms_len.Length = 1 Then sms_len = "0" & sms_len
sms_len_int = TextBox2.Text.Length * 2
sms_center = Telc(sms_center)
i = 0
Timer1.Interval = ComboBox2.Text * 1000
Timer1.Enabled = True
End Sub
Private Sub send_sms(ByVal total_sms As String, ByVal sms_len_int As Integer)
Timer1.Enabled = False
buf = ""
BUF1 = ""
BUF2 = ""
BUF3 = ""
msComm1.Output = "AT+CMGF=0" & Chr(13)
Do
Application.DoEvents()
If msComm1.InBufferCount > 0 Then
BUF1 = BUF1 & msComm1.Input
End If
Loop Until InStr(BUF1, "OK") > 0 Or InStr(BUF1, "ERROR") > 0
msComm1.Output = "AT+CMGS=" & Val(sms_len_int + 15) & Chr(13)
Do
Application.DoEvents()
If msComm1.InBufferCount > 0 Then
BUF2 = BUF2 & msComm1.Input
End If
Loop Until InStr(BUF2, ">") > 0 Or InStr(BUF2, "ERROR") > 0
msComm1.Output = total_sms & Chr(26)
Do
Application.DoEvents()
If msComm1.InBufferCount > 0 Then
BUF3 = BUF3 & msComm1.Input
End If
Loop Until InStr(BUF3, "OK") > 0 Or InStr(BUF3, "ERROR") > 0
If InStr(BUF1, "OK") > 0 And InStr(BUF2, ">") > 0 And InStr(BUF3, "OK") > 0 Then
TextBox3.Text = TextBox3.Text & ListBox1.SelectedItem & "发送成功!" & Microsoft.VisualBasic.vbCrLf
Else
TextBox3.Text = TextBox3.Text & ListBox1.SelectedItem & "发送失败!" & Microsoft.VisualBasic.vbCrLf
End If
Dim tmp As String = TextBox3.Text.Substring(TextBox3.TextLength - 1)
TextBox3.Text = TextBox3.Text.Substring(0, TextBox3.TextLength - 1)
TextBox3.SelectionStart = TextBox3.TextLength
TextBox3.SelectedText = tmp
Timer1.Enabled = True
End Sub
Public Function ascg(ByVal smsg As String) As String
Dim si, sb As Integer
Dim stmp As Integer
Dim stemp As String
sb = Len(smsg)
ascg = ""
For si = 1 To sb
stmp = AscW(Mid(smsg, si, 1))
If Math.Abs(stmp) < 127 Then
stemp = "00" & Hex(stmp)
Else
stemp = Hex(stmp)
End If
ascg = ascg & stemp
Next si
ascg = Trim(ascg)
End Function
Public Function Telc(ByVal num As String) As String
Dim tl As Integer
Dim ltem, rtem, ttem As String
Dim ti As Integer
ttem = ""
tl = Len(num)
If tl <> 11 And tl <> 13 Then
MsgBox("wrong number." & tl)
Exit Function
End If
If tl = 11 Then
tl = tl + 2
num = "86" & num
End If
For ti = 1 To tl Step 2
ltem = Mid(num, ti, 1)
rtem = Mid(num, ti + 1, 1)
If ti = tl Then rtem = "F"
ttem = ttem & rtem & ltem
Next ti
Telc = ttem
End Function
Public Function Telc_xlt(ByVal num As String) As String
Dim tl As Integer
Dim ltem, rtem, ttem As String
Dim ti As Integer
ttem = ""
tl = Len(num)
tl = tl + 3
num = "106" & num
For ti = 1 To tl Step 2
ltem = Mid(num, ti, 1)
rtem = Mid(num, ti + 1, 1)
If ti = tl Then rtem = "F"
ttem = ttem & rtem & ltem
Next ti
Telc_xlt = ttem
End Function
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If ms_count > 0 Then
If sms.Length > 0 Then
msg = ascg(sms)
If i <= ms_count - 1 Then
ListBox1.SelectedIndex = i
TextBox3.Text = TextBox3.Text & "正在发送" & ListBox1.SelectedItem & "......" & Microsoft.VisualBasic.vbCrLf
Dim tmp As String = TextBox3.Text.Substring(TextBox3.TextLength - 1)
TextBox3.Text = TextBox3.Text.Substring(0, TextBox3.TextLength - 1)
TextBox3.SelectionStart = TextBox3.TextLength
TextBox3.SelectedText = tmp
Dim ms As String = ListBox1.SelectedItem '目标号码
Dim ms_len As String '目标号码长度
If ms.Substring(0, 2) = "13" Then
'手机
ms = Telc(ms)
If InStr(ms, "F") > 0 Then
ms_len = Hex(ms.Length - 1)
Else
ms_len = Hex(ms.Length)
End If
If ms_len.Length = 1 Then
ms_len = "11000" & ms_len & "91"
Else
ms_len = "1100" & ms_len & "91"
End If
Else
'小灵通
ms = Telc_xlt(ms)
If InStr(ms, "F") > 0 Then
ms_len = Hex(ms.Length - 1)
Else
ms_len = Hex(ms.Length)
End If
If ms_len.Length = 1 Then
ms_len = "11000" & ms_len & "A1"
Else
ms_len = "1100" & ms_len & "A1"
End If
End If
total_sms = "0891" & sms_center & ms_len & ms & "000800" & sms_len & msg '完整的消息内容
send_sms(total_sms, sms_len_int)
i = i + 1
Else
'MsgBox("短消息发送完成!", MsgBoxStyle.Information, "提示")
TextBox3.Text = TextBox3.Text & "短消息发送完成!" & Microsoft.VisualBasic.vbCrLf
Dim tmp As String = TextBox3.Text.Substring(TextBox3.TextLength - 1)
TextBox3.Text = TextBox3.Text.Substring(0, TextBox3.TextLength - 1)
TextBox3.SelectionStart = TextBox3.TextLength
TextBox3.SelectedText = tmp
Timer1.Enabled = False
End If
Else
'MsgBox("请输入短信内容!", MsgBoxStyle.Information, "手机连接")
TextBox3.Text = TextBox3.Text & "请输入短信内容!" & Microsoft.VisualBasic.vbCrLf
Dim tmp As String = TextBox3.Text.Substring(TextBox3.TextLength - 1)
TextBox3.Text = TextBox3.Text.Substring(0, TextBox3.TextLength - 1)
TextBox3.SelectionStart = TextBox3.TextLength
TextBox3.SelectedText = tmp
Timer1.Enabled = False
End If
Else
'MsgBox("请先导入手机号码!", MsgBoxStyle.Information, "手机连接")
TextBox3.Text = TextBox3.Text & "请先导入手机号码!" & Microsoft.VisualBasic.vbCrLf
Dim tmp As String = TextBox3.Text.Substring(TextBox3.TextLength - 1)
TextBox3.Text = TextBox3.Text.Substring(0, TextBox3.TextLength - 1)
TextBox3.SelectionStart = TextBox3.TextLength
TextBox3.SelectedText = tmp
Timer1.Enabled = False
End If
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -