国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > VBScript > 正文

利用VBS發送短信的實現代碼(通過飛信)

2020-06-26 18:27:59
字體:
來源:轉載
供稿:網友
無意中看到百度 VBS 貼吧里一個標題為《無私的奉獻出我的用飛信免費發短信接口》的帖子。
 
光看標題就已經覺得很牛逼了,聽說過可以用 PHP 發送短信(飛信),也使用過 Python 實現的 PyFetion 發送過短信(飛信)。我也看過對應的 PHP 和 Python 源碼,實現起來還是比較復雜的,難道可以用 VBS 來實現? 

看到代碼后更覺得牛逼,竟然是使用 10086.cn (移動官網)上面的接口來實現的,飛信官方難道已經公布飛信接口了?若不是,難道是代碼的作者自己發現的接口?那也太強大了!Google 了一下才發現,哦,都不是,而是 WAP 飛信。像我這種還在用著 2005 年生產的只能打電話發短信的手機的生活在石器時代的人,當然不知道 WAP 飛信的存在。我現在連短信都很少發,更不用說飛信了,我已經不記得上一次登陸飛信是什么時候。 
復制代碼代碼如下:

m = "xxxyyyyzzzz" '手機號碼 
pass = "12345678" '登陸密碼 
msg = "Hello world" '飛信內容 
Const online = 1 '在線 
Const busy = 2 '忙碌 
Const away = 3 '離開 
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, "密碼輸入錯誤") Then 
WScript.Echo "對不起,密碼輸入錯誤,請重新輸入!" 
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 '給自己的手機發短信 
wml = http.responseText 
If InStr(wml, "發送成功") Then WScript.Echo "發送成功" 
http.open "GET", "http://f.10086.cn/im/index/logoutsubmit.action", False 
http.send '注銷登陸 

這里只是一個示例,至于怎么給別人發短信和飛信,自己琢磨吧。本來想寫一個像 PyFetion 那樣的 VbsFetion 的,但是想想沒什么意義,這樣還不如直接裝個飛信 PC 客戶端,于是就不折騰的,喜歡折騰的同學可以繼續。 
上面的程序可以很輕松地改寫成其他語言,C、C++、C#、Java、JavaScript、Python、Perl、Ruby、Lua、PHP……用這個接口可以做很多有趣的事情,不是嗎? 

VBS短信飛信發送類(VBSFetion) 

本來想把昨天《用VBS發送短信(飛信)》里的 VBS 程序改寫成 PHP 的,不過為了不重復造輪子,事先 Google 了一下,發現已經有人實現了,詳見PHP飛信發送類(PHPFetion)v1.2發布。好吧,既然已經有人把它封裝成 PHP 類了,我就封裝一個 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 
'結束事件 
Private Sub Class_Terminate 
Call Logout() 
Set http = Nothing 
End Sub 
'初始化函數 
'mobile 手機號 
'password 登陸密碼 
Public Function Init(mobile, password) 
[$mobile] = mobile 
[$password] = password 
str = Login() 
If InStr(str, "密碼輸入錯誤") Then 
Init = False 
Else 
Init = True 
End If 
End Function 
'發送飛信 
'mobile 對方手機號 
'message 發送內容 
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 
'發送短信 
'mobile 對方手機號 
' 'message 發送內容 
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 
'給自己發飛信 
Private Function ToMyself(message) 
url = "/im/user/sendMsgToMyselfs.action" 
message = "msg=" & message 
ToMyself = Post(url, message) 
End Function 
'給好友發送飛信(短信) 
'uid 飛信ID 
'message 飛信(短信)內容 
'isshort True為短信,False為飛信 
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 手機號 
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 
'發送HTTP POST請求 
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 
示例程序: 
'初始對象 
Set fetion = New VBSFetion 
'登陸飛信 
If fetion.Init("11122223333", "123456") Then 
'發送飛信 
fetion.SendMsg "44455556666", "Hello world" 
'發送短信 
fetion.SendShortMsg "77788889999", "Hello world" 
End If 

來源: http://demon.tw/my-work/vbsfetion.html

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新建县| 承德市| 志丹县| 锡林郭勒盟| 习水县| 台山市| 鸡东县| 桃园市| 绍兴县| 措美县| 黄骅市| 三原县| 罗甸县| 黑龙江省| 电白县| 玉门市| 从化市| 潍坊市| 孝义市| 沈丘县| 龙南县| 邵武市| 宣汉县| 崇州市| 阿图什市| 长武县| 西城区| 大安市| 永顺县| 肃北| 当涂县| 岳普湖县| 包头市| 调兵山市| 天长市| 嘉黎县| 肇州县| 安吉县| 饶平县| 贵港市| 雷波县|