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