打印本文 打印本文 关闭窗口 关闭窗口
通过短信猫发送短信
作者:佚名  文章来源:本站原创  点击数2005  更新时间:2012/12/12 20:42:45  文章录入:mintao  责任编辑:mintao

通过短信猫发送短信

界面一些程序

Option Explicit
Dim index(500) As String
Dim Tel(500) As String
Dim Max As Integer

Private Sub Command_send_Click()
    'On Error Resume Next
     Dim index As Long
     Dim i As Integer
     For i = 1 To List1.ListCount
        If Me.List1.Selected(i - 1) = True Then
            If Me.Text_send.Text <> "" Then
                index = SMSSendMessage(Me.Text_send.Text, Tel(i - 1))
            End If
        End If
    Next i
   
End Sub

Private Sub Command_start_Click()
   Dim com As Integer
   Dim baud As Long
   Dim suc As Long
   Dim err As String
   com = Int(Mid(Me.Combo_com.Text, 4))
   baud = CLng(Me.Combo_baud.Text)

   If Me.Text_csca.Text = "" Then
      suc = SMSDef.SMSStartService(com, baud, 2, 8, 0, 0, "card") '如果想用SIM卡内的短信中心号码,请把最后一个参数设为"card"(小写),建议使用这种方式
   Else
      suc = SMSDef.SMSStartService(com, baud, 2, 8, 0, 0, Me.Text_csca.Text)
   End If


   If suc = 1 Then
      Me.Command_start.Enabled = False
      Me.Command_stop.Enabled = True
      Me.Command_send.Enabled = True
      Me.Text_sd.SelText = "启动成功" & vbCrLf
      Me.Timer1.Enabled = True
   Else
      Me.Command_start.Enabled = True
      Me.Command_stop.Enabled = False
      Me.Command_send.Enabled = False
      Me.Text_sd.SelText = "启动失败" & vbCrLf
      err = "这里填一些字符,以免SMSGetLastError内操作此字符串时溢出,在SMSGetLastError该字符串定义为1024byte"
     
     
      SMSGetLastError err
     
      Me.Text_sd.SelText = err
      Me.Text_sd.SelText = vbCrLf
   End If

     
  
End Sub

Private Sub Command_stop_Click()
    Me.Timer1.Enabled = False
    SMSStopSerice
    Me.Command_start.Enabled = True
    Me.Command_stop.Enabled = False
    Me.Command_send.Enabled = False
    Me.Text_sd.SelText = "停止成功" & vbCrLf
  
End Sub

Private Sub Command1_Click()
   Me.Text_sd.Text = ""
   Me.Text_rec.Text = ""
End Sub

Private Sub Command2_Click()

        Dim InputData As String
        Dim i As Integer
        Dim s() As String
        i = 0
       
        On Error GoTo nofile
       
        CommonDialog1.InitDir = "..\..\..\"
       
        CommonDialog1.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*"
       
        CommonDialog1.CancelError = True
       
        CommonDialog1.Action = 1
       
        Open CommonDialog1.FileName For Input As #1
       
        Do While Not EOF(1)
       
            Line Input #1, InputData
           
            s = Split(InputData, ",")
           
            index(i) = s(0)
           
            Tel(i) = s(1)

'            Text1.Text = Text1.Text & inputdata & vbCrLf
           
            Me.List1.AddItem index(i) + " " + Tel(i)
           
            i = i + 1
           
            Max = i
             
        Loop
       
        Close #1
        Me.Command1.Enabled = False
       
        Exit Sub
       
nofile:
       
        If err.Number = 32755 Then Exit Sub
       
'        Text1.Locked = True

End Sub

Private Sub Command3_Click()
   
'    fno = FreeFile
    Dim InputData As String
    If Max = 0 Then
        MsgBox "请先导入通讯录", vbOKOnly
        Me.Command2.SetFocus
        Exit Sub
    Else
        Max = Max + 1
        InputData = InputBox("请输入序号和电话号码", "录入电话")
        Me.Text1.Text = Max & "," & InputData
    End If
    Me.List1.AddItem Max & " " & InputData
   
    Open "Tel.txt" For Append As #2
        Print #2, Me.Text1.Text
    Close #2
   
   
   
End Sub

Private Sub Command4_Click()

    Call Form_Unload

End Sub

Private Sub Form_Unload(Cancel As Integer)
   SMSStopSerice '关闭窗口前先关闭服务,否则在VB中有时会报错。
End Sub

Private Sub Timer1_Timer()
    Dim smg As SMSMessageStruct
    Dim srs As SMSReportStruct
    If SMSReport(srs) <> 0 Then
        If srs.Success = 1 Then
            Me.Text_sd.SelText = "发往" & StrConv(srs.PhoneNo, vbUnicode)
            Me.Text_sd.SelText = "的短信发送成功,内容:" & StrConv(srs.Msg, vbUnicode)
            Me.Text_sd.SelText = vbCrLf
           
           
        Else
            Me.Text_sd.SelText = "发往" & StrConv(srs.PhoneNo, vbUnicode)
            Me.Text_sd.SelText = "的短信发送失败,内容:" & StrConv(srs.Msg, vbUnicode)
            Me.Text_sd.SelText = vbCrLf
          
        End If
    End If
   
    If SMSGetNextMessage(smg) = 1 Then
        Me.Text_rec.SelText = "收到短信:<" & StrConv(smg.ReceTime, vbUnicode)
        Me.Text_rec.SelText = "> <" & StrConv(smg.PhoneNo, vbUnicode)
        Me.Text_rec.SelText = ">:" & vbCrLf & " " & StrConv(smg.Msg, vbUnicode)
        Me.Text_rec.SelText = vbCrLf
   
    End If

   
End Sub

模块程序

Option Explicit

Public Type SMSReportStruct
    index As Long   '//短消息编号:index,从0开始递增
    Msg(0 To 255) As Byte '//短信内容
    Success As Long '是否发送成功 0为失败,非0为成功
    PhoneNo(0 To 31) As Byte ' //目标手机号码
End Type


Public Type SMSMessageStruct
    Msg(0 To 255) As Byte '//短信内容
    PhoneNo(0 To 31) As Byte '//对方手机号码
    ReceTime(0 To 31) As Byte '//接收时间
End Type

'启动服务,打开串口,初始化Modem, 0为失败,非0为成功
'校验位, EvenParity :0,MarkParity:1,NoParity:2,OddParity:3,SpaceParity,4
'停止位 OneStopBit 0,OnePointFiveStopBits:1,TwoStopBits 2
'流控:NoFlowControl:0,    CtsRtsFlowControl:1,    CtsDtrFlowControl:2,    DsrRtsFlowControl:3,    DsrDtrFlowControl:4,    XonXoffFlowControl:5
'最后一个参数csca为短信中心号码,如果直接用卡内已存的短信中心号码则用"card"(小写)
Public Declare Function SMSStartService Lib "SMSDLL.dll" (ByVal nPort As Long, ByVal BaudRate As Long, ByVal Parity As Integer, ByVal DataBits As Integer, ByVal StopBits As Integer, ByVal FlowControl As Integer, ByVal csca As String) As Long


'//停止服务,并关闭串口,0为失败,非0为成功
Public Declare Function SMSStopSerice Lib "SMSDLL.dll" () As Long

'//发送短消息,返回短消息编号:index,从0开始递增,该函数不会阻塞,立既返回,请用函数SMSQuery(DWORD index)来查询是否发送成功
Public Declare Function SMSSendMessage Lib "SMSDLL.dll" (ByVal Msg As String, ByVal phone As String) As Integer


'//报告短信发送壮态(成功与否)0为有报告,非0为无
Public Declare Function SMSReport Lib "SMSDLL.dll" (ByRef srs As SMSReportStruct) As Long


'查询指定序号的短信是否发送成功(该序号由SMSSendMessage返回)
'返回 0 表示发送失败
'     1 表示发送成功
'    -1 表示没有查询到该序号的短信,可能仍在发送中。
Public Declare Function SMSQuery Lib "SMSDLL.dll" (ByVal index As Long) As Long


'//接收短信,0为有短信,非0为无
Public Declare Function SMSGetNextMessage Lib "SMSDLL.dll" (ByRef smg As SMSMessageStruct) As Long


'//返回错误内容的长度
Public Declare Function SMSGetLastError Lib "SMSDLL.dll" (ByVal err As String) As Long

如有需要SMSDLL.dll文件的请弹我一下Q:1229496407


打印本文 打印本文 关闭窗口 关闭窗口