⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainform.vb

📁 短信猫C#例子,很不错的例子,不妨下载测试
💻 VB
📖 第 1 页 / 共 2 页
字号:
        Me.smshistory.Multiline = True
        Me.smshistory.Name = "smshistory"
        Me.smshistory.ScrollBars = System.Windows.Forms.ScrollBars.Both
        Me.smshistory.Size = New System.Drawing.Size(472, 136)
        Me.smshistory.TabIndex = 0
        Me.smshistory.Text = ""
        '
        'GroupBox3
        '
        Me.GroupBox3.Controls.Add(Me.sendCommand)
        Me.GroupBox3.Controls.Add(Me.smsText)
        Me.GroupBox3.Controls.Add(Me.mobile)
        Me.GroupBox3.Controls.Add(Me.Label4)
        Me.GroupBox3.Controls.Add(Me.Label3)
        Me.GroupBox3.Location = New System.Drawing.Point(8, 312)
        Me.GroupBox3.Name = "GroupBox3"
        Me.GroupBox3.Size = New System.Drawing.Size(488, 152)
        Me.GroupBox3.TabIndex = 2
        Me.GroupBox3.TabStop = False
        Me.GroupBox3.Text = "发送短信"
        '
        'sendCommand
        '
        Me.sendCommand.Location = New System.Drawing.Point(16, 112)
        Me.sendCommand.Name = "sendCommand"
        Me.sendCommand.Size = New System.Drawing.Size(64, 32)
        Me.sendCommand.TabIndex = 6
        Me.sendCommand.Text = "发送"
        '
        'smsText
        '
        Me.smsText.Location = New System.Drawing.Point(88, 64)
        Me.smsText.Multiline = True
        Me.smsText.Name = "smsText"
        Me.smsText.Size = New System.Drawing.Size(232, 80)
        Me.smsText.TabIndex = 5
        Me.smsText.Text = ""
        '
        'mobile
        '
        Me.mobile.Location = New System.Drawing.Point(88, 32)
        Me.mobile.Name = "mobile"
        Me.mobile.Size = New System.Drawing.Size(232, 21)
        Me.mobile.TabIndex = 4
        Me.mobile.Text = ""
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(16, 32)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(72, 16)
        Me.Label4.TabIndex = 3
        Me.Label4.Text = "手机号码"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(16, 56)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(72, 16)
        Me.Label3.TabIndex = 2
        Me.Label3.Text = "短信内容"
        '
        'mainform
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(504, 469)
        Me.Controls.Add(Me.GroupBox3)
        Me.Controls.Add(Me.GroupBox2)
        Me.Controls.Add(Me.GroupBox1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow
        Me.Name = "mainform"
        Me.Text = "sms"
        Me.GroupBox1.ResumeLayout(False)
        CType(Me.EdisonSmsGw1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.GroupBox2.ResumeLayout(False)
        Me.GroupBox3.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region
    Dim onetime As Date
    Dim id As Long '短消息标识号,可以用数据库里的id代替,标识发出去的短信,用于状态提示
    Private Sub mainform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim i As Integer
        onetime = Now()
        For i = 1 To 200
            If i < 10 Then
                Combo.Items.Add("com" & i)
            Else
                Combo.Items.Add("\\.\com" & i)
            End If
        Next
        conngsm()
    End Sub

    Private Sub cmdConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdConnect.Click
        conngsm()
    End Sub
    Sub conngsm()
        'On Error Resume Next
        Dim CommPort1, cmbBaud1 As String, n As Integer
        CommPort1 = Combo.Text
        cmbBaud1 = cmbBaud.Text
        If CommPort1 <> "" And cmbBaud1 <> "" Then
            If Not (IsNumeric(cmbBaud1)) Then
                Exit Sub
            End If
            EdisonSmsGw1.SetModemType("1")
            EdisonSmsGw1.SetRecvFlag(True)
            n = EdisonSmsGw1.ConnectModem(CommPort1, cmbBaud1, 1)
            If n = 1 Then
                conngsmstate.Text = "已打开串口,正在连接" & vbCrLf
            End If
            If n = -1 Then
                conngsmstate.Text = "打开串口失败,请换串口" & vbCrLf
            End If
        End If
    End Sub



    Private Sub connocxTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles connocxTimer.Tick
        If DateDiff("s", onetime, Now()) >= 30 * 60 Then '30分钟重新连接一次,防止设备重启,电源意外断开等情况
            onetime = Now()
        Else
            Exit Sub
        End If
        If EdisonSmsGw1.IsConnecting = 0 And EdisonSmsGw1.IsConnected = True And EdisonSmsGw1.IsFreeStatus = True Then
            EdisonSmsGw1.DisconnectModem()
            conngsm()
        Else
            conngsm()
        End If
    End Sub

    Private Sub sendCommand_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sendCommand.Click
        Dim n As Integer
        If EdisonSmsGw1.IsConnecting = 0 And EdisonSmsGw1.IsConnected = True Then
            If mobile.Text <> "" And smsText.Text <> "" Then
                id = id + 1
                n = EdisonSmsGw1.SendSms(mobile.Text, smsText.Text, id) '发送短信
                If n = 1 Then
                    smshistory.Text = smshistory.Text & "[smsid:" & id & "][正在发送][" & mobile.Text & "]" & "[" & smsText.Text & "]" & vbCrLf
                Else
                    smshistory.Text = smshistory.Text & "[smsid:" & id & "][提交失败][" & mobile.Text & "]" & "[" & smsText.Text & "]" & vbCrLf
                End If
            Else
                MsgBox("请输入信息")
            End If
        End If
    End Sub




    Sub dk() '断开操作
        EdisonSmsGw1.DisconnectModem()
        conngsmstate.Text = "gsm modem 断开成功"
    End Sub

    Private Overloads Sub cmdDisConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDisConnect.Click
        dk()
    End Sub

    Private Sub EdisonSmsGw1_ConnectStatus(ByVal sender As Object, ByVal e As AxEDISONSMSGWLib._DEdisonSmsGwEvents_ConnectStatusEvent) Handles EdisonSmsGw1.ConnectStatus
        If e.nStatus = 1 Then
            conngsmstate.Text = "连接成功"
        Else
            conngsmstate.Text = "连接失败"
        End If
    End Sub

    Private Sub EdisonSmsGw1_Recvsms(ByVal sender As Object, ByVal e As AxEDISONSMSGWLib._DEdisonSmsGwEvents_RecvsmsEvent) Handles EdisonSmsGw1.Recvsms
        Dim sj As String
        sj = CStr(e.nYear) & "-" & CStr(e.nMonth) & "-" & CStr(e.nDay) & " " & CStr(e.nHour) & ":" & CStr(e.nMinute) & ":" & CStr(e.nSecond)
        smshistory.Text = smshistory.Text & "[接受短信][" & e.strPhoneNumber & "]" & "[" & e.strSmsContent & "][" & sj & "]" & vbCrLf
    End Sub

    Private Sub EdisonSmsGw1_SendSmsResult(ByVal sender As Object, ByVal e As AxEDISONSMSGWLib._DEdisonSmsGwEvents_SendSmsResultEvent) Handles EdisonSmsGw1.SendSmsResult
        If e.nResult = 1 Then
            smshistory.Text = smshistory.Text & "[smsid:" & e.nIndex & "][发送成功][" & e.strPhoneNumber & "]" & "[" & e.strSmsContent & "]" & vbCrLf
        Else
            smshistory.Text = smshistory.Text & "[smsid:" & e.nIndex & "][发送失败][" & e.strPhoneNumber & "]" & "[" & e.strSmsContent & "]" & vbCrLf
        End If
    End Sub


End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -