VBS短信飞信发送类(VBSFetion)

标签: , , , , , ,

本来想把昨天《用VBS发送短信(飞信)》里的 VBS 程序改写成 PHP 的,不过为了不重复造轮子,事先 Google 了一下,发现已经有人实现了,详见PHP飞信发送类(PHPFetion)v1.2发布。好吧,既然已经有人把它封装成 PHP 类了,我就封装一个 VBS 类吧。

Class VBSFetion
    Private [$mobile], [$password], http

    'Author: Demon
    'Website: https://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
赞赏

微信赞赏支付宝赞赏

随机文章:

  1. C语言中NULL和NUL的区别
  2. PT作弊教程
  3. OpenWrt配置HTTPS访问LuCI
  4. VBSCript 之 GenerateSDDL 函数
  5. VBS的一个BUG

21 条评论 发表在“VBS短信飞信发送类(VBSFetion)”上

  1. hacker说道:

    噢 疙瘩,庆幸看到了你的博客。

  2. hacker说道:

    不会的,VBS写得飞信的类是你写的吧?

  3. […] 前一段时间正好对电脑发送短信比较感兴趣,因为自己那款老掉牙的手机慢慢的输入文字再群发确实很不方便,于是想移动有没有开放短信接口什么的,上网搜索了有关短信发送的相关知识,找到了Demon的这篇关于《VBS短信飞信发送类(VBSFetion)》,原来是利用了移动的WAP飞信,然后模拟POST,实现短信或者飞信的发送,优点是发送免费,唯一遗憾的是貌似只能发给自己或者飞信好友。不过发送给自己倒是个不错的功能,可以实现一些监控报警类的功能。其实139邮箱那个短信发送到是可以发给任何人,只不过是按正常短信收费标准进行收费,而且主显号码是在你原先的号码上附加了一串长号,这点有点不爽。鉴于Demon在这一方面已经先行一步,我就利用其算法,改造了自己的一个VBScript类实现。 […]

  4. DALEY说道:

    老大,飞信增加了安全验证,原先的系统在2012年6月份开始已经不能发送了。

    http://bolg.malu.me/html/2012/1858.html

    上面这个帖子的内容是修改过的,烦请将PHP的代码给予转换成VBA的类,感谢您啦!!

  5. jxl说道:

    老大,我也希望你能更新一下你的飞信类代码,谢谢!398157336

  6. zzb说道:

    此类从2012年8月份开始不能用了,不知何种原因?

  7. zzb说道:

    是否端口被封了?

  8. 吴迪军说道:

    请问 Demon 师傅:
    能否用VBA 编程将EXCEL表格中的内容通过飞信发短信给几个指定的手机,
    指定手机收到短信后可回复短信,将回复结果输入在EXCEL表格指定单元格内?
    我相信,一定可以实现改功能。
    请指教,可以有偿帮助!
    可随时联系我的手机号码:13912272011

  9. 风月诱人说道:

    请问添加,删除好友的代码VBS的该如何写?

Demon 留下回复