利用VBS發(fā)送短信的實(shí)現(xiàn)代碼(通過(guò)飛信)
光看標(biāo)題就已經(jīng)覺(jué)得很牛逼了,聽(tīng)說(shuō)過(guò)可以用 PHP 發(fā)送短信(飛信),也使用過(guò) Python 實(shí)現(xiàn)的 PyFetion 發(fā)送過(guò)短信(飛信)。我也看過(guò)對(duì)應(yīng)的 PHP 和 Python 源碼,實(shí)現(xiàn)起來(lái)還是比較復(fù)雜的,難道可以用 VBS 來(lái)實(shí)現(xiàn)?
看到代碼后更覺(jué)得牛逼,竟然是使用 10086.cn (移動(dòng)官網(wǎng))上面的接口來(lái)實(shí)現(xiàn)的,飛信官方難道已經(jīng)公布飛信接口了?若不是,難道是代碼的作者自己發(fā)現(xiàn)的接口?那也太強(qiáng)大了!Google 了一下才發(fā)現(xiàn),哦,都不是,而是 WAP 飛信。像我這種還在用著 2005 年生產(chǎn)的只能打電話發(fā)短信的手機(jī)的生活在石器時(shí)代的人,當(dāng)然不知道 WAP 飛信的存在。我現(xiàn)在連短信都很少發(fā),更不用說(shuō)飛信了,我已經(jīng)不記得上一次登陸飛信是什么時(shí)候。
m = "xxxyyyyzzzz" '手機(jī)號(hào)碼
pass = "12345678" '登陸密碼
msg = "Hello world" '飛信內(nèi)容
Const online = 1 '在線
Const busy = 2 '忙碌
Const away = 3 '離開(kāi)
Const hidden = 4 '隱身
Dim http
Set http = CreateObject("Msxml2.XMLHTTP")
http.open "POST", "http://f.10086.cn/im/login/inputpasssubmit1.action", False
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.send "m=" & m & "&pass=" & pass & "&loginstatus=" & hidden '隱身登陸
wml = http.responseText
If InStr(wml, "密碼輸入錯(cuò)誤") Then
WScript.Echo "對(duì)不起,密碼輸入錯(cuò)誤,請(qǐng)重新輸入!"
WScript.Quit '登陸失敗,退出程序
End If
http.open "POST", "http://f.10086.cn/im/user/sendMsgToMyselfs.action", False
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.send "msg=" & msg '給自己的手機(jī)發(fā)短信
wml = http.responseText
If InStr(wml, "發(fā)送成功") Then WScript.Echo "發(fā)送成功"
http.open "GET", "http://f.10086.cn/im/index/logoutsubmit.action", False
http.send '注銷登陸
這里只是一個(gè)示例,至于怎么給別人發(fā)短信和飛信,自己琢磨吧。本來(lái)想寫一個(gè)像 PyFetion 那樣的 VbsFetion 的,但是想想沒(méi)什么意義,這樣還不如直接裝個(gè)飛信 PC 客戶端,于是就不折騰的,喜歡折騰的同學(xué)可以繼續(xù)。
上面的程序可以很輕松地改寫成其他語(yǔ)言,C、C++、C#、Java、JavaScript、Python、Perl、Ruby、Lua、PHP……用這個(gè)接口可以做很多有趣的事情,不是嗎?
VBS短信飛信發(fā)送類(VBSFetion)
本來(lái)想把昨天《用VBS發(fā)送短信(飛信)》里的 VBS 程序改寫成 PHP 的,不過(guò)為了不重復(fù)造輪子,事先 Google 了一下,發(fā)現(xiàn)已經(jīng)有人實(shí)現(xiàn)了,詳見(jiàn)PHP飛信發(fā)送類(PHPFetion)v1.2發(fā)布。好吧,既然已經(jīng)有人把它封裝成 PHP 類了,我就封裝一個(gè) VBS 類吧。
Class VBSFetion
Private [$mobile], [$password], http
'Author: Demon
'Website: http://demon.tw
'Date: 2011/6/11
'初始化事件
Private Sub Class_Initialize
Set http = CreateObject("Msxml2.XMLHTTP")
End Sub
'結(jié)束事件
Private Sub Class_Terminate
Call Logout()
Set http = Nothing
End Sub
'初始化函數(shù)
'mobile 手機(jī)號(hào)
'password 登陸密碼
Public Function Init(mobile, password)
[$mobile] = mobile
[$password] = password
str = Login()
If InStr(str, "密碼輸入錯(cuò)誤") Then
Init = False
Else
Init = True
End If
End Function
'發(fā)送飛信
'mobile 對(duì)方手機(jī)號(hào)
'message 發(fā)送內(nèi)容
Public Function SendMsg(mobile, message)
If message = "" Then Exit Function
If mobile = [$mobile] Then
Send = ToMyself(message)
Else
uid = GetUid(mobile)
If uid <> -1 Then Send = ToUid(uid, message, False)
End If
End Function
'發(fā)送短信
'mobile 對(duì)方手機(jī)號(hào)
' 'message 發(fā)送內(nèi)容
Public Function SendShortMsg(mobile, message)
If message = "" Then Exit Function
If mobile = [$mobile] Then
Send = ToMyself(message)
Else
uid = GetUid(mobile)
If uid <> -1 Then Send = ToUid(uid, message, True)
End If
End Function
'登陸
Private Function Login()
url = "/im/login/inputpasssubmit1.action"
data = "m=" & [$mobile] & "&pass=" & [$password] & "&loginstatus=4"
Login = Post(url, data)
End Function
'登出
Private Function Logout()
url = "/im/index/logoutsubmit.action"
Logout = Post(url, "")
End Function
'給自己發(fā)飛信
Private Function ToMyself(message)
url = "/im/user/sendMsgToMyselfs.action"
message = "msg=" & message
ToMyself = Post(url, message)
End Function
'給好友發(fā)送飛信(短信)
'uid 飛信ID
'message 飛信(短信)內(nèi)容
'isshort True為短信,F(xiàn)alse為飛信
Private Function ToUid(uid, message, isshort)
If isshort Then
url = "/im/chat/sendShortMsg.action?touserid=" & uid
data = "msg=" & message
Else
url = "/im/chat/sendMsg.action?touserid=" & uid
data = "msg=" & message
End If
ToUid = Post(url, data)
End Function
'獲取飛信ID
'mobile 手機(jī)號(hào)
Private Function GetUid(mobile)
url = "/im/index/searchOtherInfoList.action"
data = "searchText=" & mobile
str = Post(url, data)
Set re = New RegExp
re.Pattern = "/toinputMsg\.action\?touserid=(\d+)"
If re.Test(str) Then
Set ms = re.Execute(str)
GetUid = ms.Item(0).Submatches(0)
Else
GetUid = -1
End If
End Function
'發(fā)送HTTP POST請(qǐng)求
Private Function Post(url, data)
url = "http://f.10086.cn" & url
http.open "POST", url, False
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.send data
Post = http.responseText
End Function
End Class
示例程序:
'初始對(duì)象
Set fetion = New VBSFetion
'登陸飛信
If fetion.Init("11122223333", "123456") Then
'發(fā)送飛信
fetion.SendMsg "44455556666", "Hello world"
'發(fā)送短信
fetion.SendShortMsg "77788889999", "Hello world"
End If
來(lái)源: http://demon.tw/my-work/vbsfetion.html
上一篇:TXT轉(zhuǎn)HTM、HTML「TXT轉(zhuǎn)網(wǎng)頁(yè)」的vbs實(shí)現(xiàn)代碼
欄 目:vb
本文標(biāo)題:利用VBS發(fā)送短信的實(shí)現(xiàn)代碼(通過(guò)飛信)
本文地址:http://www.jygsgssxh.com/a1/vb/7413.html
您可能感興趣的文章
- 01-10下載文件到本地運(yùn)行的vbs
- 01-10VBS中的正則表達(dá)式的用法大全 <font color=red>原創(chuàng)&
- 01-10VBS中SendKeys的基本應(yīng)用
- 01-10VBScript教程 第十一課深入VBScript
- 01-10用VBSCRIPT控制ONSUBMIT事件
- 01-10VBScript語(yǔ)法速查及實(shí)例說(shuō)明
- 01-10VBS中Select CASE的其它用法
- 01-10VBScript教程 第七課使用條件語(yǔ)句
- 01-10vbscript 可以按引用傳遞參數(shù)嗎?
- 01-10VBScript教程 第二課在HTML頁(yè)面中添加VBscript代碼


閱讀排行
- 1C語(yǔ)言 while語(yǔ)句的用法詳解
- 2java 實(shí)現(xiàn)簡(jiǎn)單圣誕樹(shù)的示例代碼(圣誕
- 3利用C語(yǔ)言實(shí)現(xiàn)“百馬百擔(dān)”問(wèn)題方法
- 4C語(yǔ)言中計(jì)算正弦的相關(guān)函數(shù)總結(jié)
- 5c語(yǔ)言計(jì)算三角形面積代碼
- 6什么是 WSH(腳本宿主)的詳細(xì)解釋
- 7C++ 中隨機(jī)函數(shù)random函數(shù)的使用方法
- 8正則表達(dá)式匹配各種特殊字符
- 9C語(yǔ)言十進(jìn)制轉(zhuǎn)二進(jìn)制代碼實(shí)例
- 10C語(yǔ)言查找數(shù)組里數(shù)字重復(fù)次數(shù)的方法
本欄相關(guān)
- 01-10下載文件到本地運(yùn)行的vbs
- 01-10飄葉千夫指源代碼,又稱qq刷屏器
- 01-10SendKeys參考文檔
- 01-10什么是一個(gè)高效的軟件
- 01-10VBS中的正則表達(dá)式的用法大全 &l
- 01-10exe2swf 工具(Adodb.Stream版)
- 01-10VBS中SendKeys的基本應(yīng)用
- 01-10用VBSCRIPT控制ONSUBMIT事件
- 01-10VBScript教程 第十一課深入VBScript
- 01-10VBScript語(yǔ)法速查及實(shí)例說(shuō)明
隨機(jī)閱讀
- 08-05織夢(mèng)dedecms什么時(shí)候用欄目交叉功能?
- 01-10SublimeText編譯C開(kāi)發(fā)環(huán)境設(shè)置
- 01-10delphi制作wav文件的方法
- 01-10C#中split用法實(shí)例總結(jié)
- 04-02jquery與jsp,用jquery
- 08-05dedecms(織夢(mèng))副欄目數(shù)量限制代碼修改
- 08-05DEDE織夢(mèng)data目錄下的sessions文件夾有什
- 01-10使用C語(yǔ)言求解撲克牌的順子及n個(gè)骰子
- 01-11Mac OSX 打開(kāi)原生自帶讀寫NTFS功能(圖文
- 01-11ajax實(shí)現(xiàn)頁(yè)面的局部加載


