阿里云:
服务器购买地址
https://t.aliyun.com/U/C6sVsb
若失效,可用地址
https://www.aliyun.com/activity/wuying/dj?source=5176.29345612&userCode=49hts92d
腾讯云:
https://curl.qcloud.com/wJpWmSfU
若失效,可用地址
https://cloud.tencent.com/act/cps/redirect?redirect=2446&cps_key=ad201ee2ef3b771157f72ee5464b1fea&from=console
华为云
https://activity.huaweicloud.com/cps.html?fromacct=64b5cf7cc11b4840bb4ed2ea0b2f4468&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905
2.部署教程
3.代码如下
// formhash获取(在浏览器F12控制台输入):document.querySelector('input[name="formhash"]').getAttribute('value')
const axios = require("axios");
let result = "【海贼王论坛】:"
class HZW {
constructor() {
this.host = 'https://bbs.talkop.com/plugin.php';
this.headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0",
"Content-Type": "application/x-www-form-urlencoded",
"Cookie": config.hzw.cookie,
};
this.body = `formhash=${config.hzw.formhash}&qdxq=kx&qdmode=2&todaysay=&fastreply=0`;
}
// 签到
async sign() {
const url = this.host + '?id=dsu_paulsign:sign&operation=qiandao&infloat=1&sign_as=1&inajax=1';
try {
const res = await axios.post(url, this.body, {headers: this.headers});
let matchResult = res.data.match(/(.+?)\r\n<\/div>/);
let response = matchResult ? matchResult[1] : '签到失败,原因未知';
console.log(`${response}`);
result += `${response} ||`
} catch (error) {
console.log(`签到失败,原因是:${error}`);
result += `签到失败,原因是:${error} ||`
}
}
async run() {
await this.sign();
console.log();
}
}
async function hzw() {
const hzwlt = new HZW();
await hzwlt.run();
if (result.endsWith('||')) {
result = result.substring(0, result.length - 2);
}
return result;
}
module.exports = hzw;
解析
这个脚本是一个模拟签到操作的自动化脚本,针对的是海贼王论坛(bbs.talkop.com)。它使用 axios
向论坛的签到接口发送请求,并获取签到的反馈信息。
- 模拟签到
:向海贼王论坛的签到接口发送请求,进行自动签到。 - 获取签到结果
:从接口响应中解析出签到的反馈信息(如签到成功或失败的提示信息)。 - 返回签到信息
:将签到结果返回,格式化为字符串。 HZW
类:host
:论坛的 API 地址( https://bbs.talkop.com/plugin.php
)。headers
:请求头,包含了 User-Agent
、Content-Type
和Cookie
(用于身份认证)。body
:请求体,包含了 formhash
(一个防止CSRF攻击的令牌)、签到模式(qdmode=2
)等参数。该类封装了签到的相关操作,包括请求 URL、请求头、请求体等。 - 构造函数
: sign
方法:向论坛的签到接口发送 POST 请求。 构造请求的 URL: https://bbs.talkop.com/plugin.php?id=dsu_paulsign:sign&operation=qiandao&infloat=1&sign_as=1&inajax=1
。在请求成功后,从返回的 HTML 数据中提取出签到结果(使用正则表达式 match(/(.+?)\r\n<\/div>/)
进行匹配)。如果匹配成功,提取并输出签到结果。如果没有匹配到,输出"签到失败,原因未知"。 run
方法:调用 sign
方法,执行签到操作。等待 sign
方法执行完成后输出结果。hzw
方法:创建 HZW
类的实例并调用run
方法执行签到。拼接最终的签到结果字符串,并去掉末尾的 ||
。
异常处理:
在请求失败时,会捕获异常并输出失败原因,确保脚本不会因为错误中断。
这个脚本的目的是自动化海贼王论坛的签到过程。通过构造 POST 请求,模拟登录并执行签到操作,返回签到结果信息。通过 axios
库发送请求,使用正则表达式从响应中提取签到的状态信息。
注意:
本文部分变量已做脱敏处理,仅用于测试和学习研究,禁止用于商业用途,不能保证其合法性,准确性,完整性和有效性,请根据情况自行判断。技术层面需要提供帮助,可以通过打赏的方式进行探讨。
没有评论:
发表评论