Board logo

标题: [原创] VBS短信飞信发送类(VBSFetion) [打印本页]

作者: Demon    时间: 2011-6-12 22:33     标题: VBS短信飞信发送类(VBSFetion)

本帖最后由 Demon 于 2011-6-13 08:28 编辑

原文链接:http://demon.tw/my-work/vbsfetion.html


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

作者: Demon    时间: 2011-6-12 22:38

本帖最后由 Demon 于 2011-6-13 08:28 编辑

示例程序:


'初始化对象
Set fetion = New VBSFetion
'登陆飞信
If fetion.Init("11122223333", "123456") Then
    '发送飞信
    fetion.SendMsg "44455556666", "Hello world"
    '发送短信
    fetion.SendShortMsg "77788889999", "Hello world"
End If

作者: BillGates    时间: 2011-6-13 10:02

看不懂……这个可以结合在批处理中吗?
作者: dahual    时间: 2011-6-13 10:06

很好。
学习。
作者: Demon    时间: 2011-6-13 10:12

看不懂……这个可以结合在批处理中吗?
BillGates 发表于 2011-6-13 10:02

有了VBS还用批处理做什么?
作者: Batcher    时间: 2011-6-13 11:22

3# BillGates


批处理发送飞信到手机
http://bbs.bathome.net/thread-6820-1-1.html
作者: 523066680    时间: 2011-7-2 17:42

3# BillGates


批处理发送飞信到手机
http://bbs.bathome.net/thread-6820-1-1.html
Batcher 发表于 2011-6-13 11:22

哈哈 batcher太给力了!
作者: cjiabing    时间: 2012-5-19 02:20

本帖最后由 cjiabing 于 2012-5-19 13:57 编辑

非常感谢分享!!如果能收信则更加好了~!




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2