利用VBS发送短信的实现代码(通过飞信)_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

时间: 2024-08-02 14:53:43

利用VBS发送短信的实现代码(通过飞信)_vbs的相关文章

Laravel框架实现发送短信验证功能代码_php实例

Laravel框架简介: Laravel是一套简洁.优雅的PHP Web开发框架(PHP Web Framework).它可以让你从面条一样杂乱的代码中解脱出来:它可以帮你构建一个完美的网络APP,而且每行代码都可以简洁.富于表达力. Laravel短信验证思路详解 今天在做到用户注册和个人中心的安全管理时,我实现借助第三方短信平台在Laravel框架中进行手机验证的设置; 由于我做的是一个为客户提供医疗咨询和保健品网站,所以我们对客户个人隐私的保护显得尤为重要,因而在客户登录后进入个人中心前,

javascript发送短信验证码实现代码_javascript技巧

本文首先分析手机发送验证码的原理,再对javascript发送短信验证码予以实现,具体思路如下: 实现点击"发送验证码"按钮后,按钮依次显示为"59秒后重试"."58秒后重试"-直至倒计时至0秒时再恢复显示为"发送验证码".在倒计时期间按钮为禁用状态 . 第一步.获取按钮.绑定事件.设置定时器变量和计时变量 第二步.添加定时器,每隔1秒钟计时减 1,直至当计时小于等于 0 时清除定时器,按钮恢复为"发送验证码&quo

Android接收和发送短信的实现代码_Android

Android收到短信时会广播android.provider.Telephony.SMS_RECEIVED消息,因此只要定义一个Receiver,收听该消息,就能接收短信. <receiver android:name=".smsReceiver" > <intent-filter> <action android:name="android.provider.Telephony.SMS_RECEIVED" /> </in

Android接收和发送短信的实现代码

Android收到短信时会广播android.provider.Telephony.SMS_RECEIVED消息,因此只要定义一个Receiver,收听该消息,就能接收短信. <receiver android:name=".smsReceiver" > <intent-filter> <action android:name="android.provider.Telephony.SMS_RECEIVED" /> </in

自己用C#做的用gsm-modem发送短信的核心代码

问题描述 此核心代码已成功的应用于一套商业广告短信群发系统和一个律师事务所的OA系统中,群发系统已经稳定运行半年多了,最高单日发送140w条短信(多发送端,每个发送端带几十个猫,每个猫用一个核心类的实例控制),因最近手头紧,打算把这个核心类卖几份换点零花钱,完整系统是不能卖了,还是原始项目,没有整理成自己的产品,但是可以承接相关项目的开发联系QQ:905779210需要联系电话QQ上谈,不公布MSN.电话主要是怕骚扰,^_^ 解决方案 解决方案二:想不明白这有什么技术够量,现在的gsm-mode

android中可以通过两种方式调用接口发送短信_Android

第一:调用系统短信接口直接发送短信:主要代码如下: 复制代码 代码如下: //直接调用短信接口发短信 SmsManager smsManager = SmsManager.getDefault(); List<String> divideContents = smsManager.divideMessage(content); for (String text : divideContents) { smsManager.sendTextMessage("150xxxxxxxx&qu

Android发送短信方法总结_Android

android API 中提供了SmsManager类处理短信.其中的sendTextMessage(num, null, content, pend, null)函数就是发送,具体介绍如下: SMS涉及的主要类SmsManager 实现SMS主要用到SmsManager类,该类继承自java.lang.Object类,下面我们介绍一下该类的主要成员.公有方法: 1.ArrayList<String> divideMessage(String text) 当短信超过SMS消息的最大长度时,将短

android中可以通过两种方式调用接口发送短信

第一:调用系统短信接口直接发送短信:主要代码如下: 复制代码 代码如下: //直接调用短信接口发短信 SmsManager smsManager = SmsManager.getDefault(); List<String> divideContents = smsManager.divideMessage(content); for (String text : divideContents) { smsManager.sendTextMessage("150xxxxxxxx&qu

Android发送短信方法总结

android API 中提供了SmsManager类处理短信.其中的sendTextMessage(num, null, content, pend, null)函数就是发送,具体介绍如下: SMS涉及的主要类SmsManager 实现SMS主要用到SmsManager类,该类继承自java.lang.Object类,下面我们介绍一下该类的主要成员. 公有方法: 1.ArrayList<String> divideMessage(String text) 当短信超过SMS消息的最大长度时,将