当前位置: 移动技术网 > IT编程>脚本编程>VBScript > 利用VBS发送短信的实现代码(通过飞信)

利用VBS发送短信的实现代码(通过飞信)

2017年12月08日  | 移动技术网IT编程  | 我要评论
光看标题就已经觉得很牛逼了,听说过可以用 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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网