VB6怎样运行一个短信发布功能,采用HTTP方式?
某短信公司的短信接口文档如下:
短信发送
GET/POST操作格式:
http://223.4.xxx.xxx/ba/?user=用户账号&pass=密码&mobile=手机号码&content=内容
(提示:上面http网址粘贴到地址栏上,相当于发布短信,同时页面会有返回值)
短信发布成功,返回值 100;发布失败,返回值101
请问,如何用VB6实现上面的短信发布功能。
提示,在Form1窗体上,已有帐号、密码、手机号码、内容的Textbox控件,但不知道用什么方式实现短信发布,要求能判断返回值,求可行的代码方案。实现者得分。
[解决办法]
引用MSXML 6.0库
xmlhttp.Post 你的url
[解决办法]
Function GetByWinHttp$(ByVal GetUrl$)
On Error Resume Next
Dim XmlHttp As Object
'Dim PicBytes() As Byte '验证码字节数组
Set XmlHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
With XmlHttp
'.SetProxy 2, "IP:Port" '设置代理
If InStr(GetUrl, "&__K") <> 0 Then .Option(6) = False '禁止重定向
.Open "GET", GetUrl, True
.SetRequestHeader "Accept", "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/QVOD, application/QVOD, */*"
.SetRequestHeader "Accept-Language", "zh-cn"
.SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)"
'.SetRequestHeader "Accept-Encoding","gzip, deflate" 'gzip为压缩格式,一般可注释此行,如获取不到页面内容,或许就需要解压了.
'.SetRequestHeader "Host","bbs.9dufz.com" '一般可以省略。
.SetRequestHeader "Connection", "Keep-Alive"
.Send
.WaitForResponse
' PicBytes = .ResponseBody '下载后加载验证码
' Open App.Path & "\VerCode.jpg" For Binary As #1
' Put #1, , PicBytes
' Close #1
' frmMain.Picture1.Picture = LoadPicture(App.Path & "\VerCode.jpg")
' Kill App.Path & "\VerCode.jpg"
'========================================================'直接加载验证码[需加载ModLoadPngPic.Bas模块]
' Dim m_token As Long
' Dim StartupInput As GdiplusStartupInput
' StartupInput.GdiplusVersion = 1
' If GdiplusStartup(m_token, StartupInput, ByVal 0&) Then
' MsgBox "Error initializing GDI+"
' Exit Function
' End If
' Call PaintBytes(frmMain.Picture1, picBytes)
' Call GdiplusShutdown(m_token)
GetByWinHttp = .ResponseText
If InStr(GetByWinHttp, "var url=''") <> 0 Then
javaStr = GetMidStr(GetByWinHttp, "javascript"">", ";window.location=url;")
ElseIf InStr(GetUrl, "&__K") <> 0 Then
GetByWinHttp = "http://bbs.9dufz.com" & .GetResponseHeader("Location")
Debug.Print GetByWinHttp
Else
GetByWinHttp = GetMidStr(BytesToBstr(.ResponseBody, "gbk"), "xi1"">", "<")
End If
' = StrConv(.ResponseBody, vbUnicode) '转换成vbUnicode格式
' = BytesToBstr(.ResponseBody, "gbk") '按网页编码(CharSet)格式转码
' = .GetAllResponseHeaders '网页全部报文
' = .GetResponseHeader("Location") '网页Location(如果有)
' = ControlCookies(.GetAllResponseHeaders) '网页Cookie
End With
Set XmlHttp = Nothing
End Function
Private Function PostText(strURL As String) As String
Dim objMSXML As Object '用于获取网页源码的对象
Dim strRetVal As String
On Error GoTo E_Handle_GH
Set objMSXML = CreateObject("Microsoft.XMLHTTP")
objMSXML.Open "Get", strURL, 0&
objMSXML.Send
If (objMSXML.ReadyState = 4&) Then strRetVal = objMSXML.ResponseText
E_Handle_GH:
Set objMSXML = Nothing
PostText = strRetVal
End Function
Private Sub Command1_Click()
Dim strURLText As String
'在这儿,你自己把短信发送的“http网址”组合好
strURLText = "...."
MsgBox PostText(strURLText), vbInformation
End Sub