代码及范例:
import inet.whttp;
fetion = class {
ctor (mobile, password) {
if (!mobile || !password)
return null, "手机号或密码为空!";
this.http = ..inet.whttp();
}
login = function () {
this.http.post(
"http://f.10086.cn/im5/login/loginHtml5.action",
..string.concat(
"m=", mobile,
"&pass=", ..inet.url.encode(password, true),
"&codekey=NjU1MQ%3D%3D&checkCode=6551"
)
);
var result = this.http.get("http://f.10086.cn/im/login/cklogin.action");
result = ..string.fromto(result);
if (..string.match(result, "你可能认识的人")) {
this.logged = true;
return true;
}
else {
return false;
}
}
logout = function () {
if (!this.logged)
return false;
this.http.get("http://f.10086.cn/im/index/logoutsubmit.action");
this.logged = false;
return true;
}
textMe = function (message) {
if (!this.logged)
return false;
this.http.post(
"http://f.10086.cn/im/user/sendMsgToMyselfs.action",
"msg=" + ..inet.url.encode(message, true)
);
return true;
}
}
io.open();
io.stdout.write("手机号: ");
var mobile = io.stdin.read();
io.stdout.write("密码: ");
var password = io.stdin.read();
var myFetion = fetion(mobile, password);
if (myFetion.login()) {
io.print("登录成功,正在发信...");
myFetion.textMe('测试短信\nFrom aardioFans');
io.print("发信完毕,正在登出...");
myFetion.logout();
}
else {
io.print("登录失败,请检查手机号、密码是否有误.");
}
|