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