调整代码结构

This commit is contained in:
Hex
2023-11-17 16:40:15 +08:00
parent 931609dffd
commit 7c99607e66
3 changed files with 312 additions and 210 deletions

View File

@@ -19,6 +19,7 @@
* 关注栏目 * 关注栏目
* 关注品牌 * 关注品牌
* 限时累计活动 * 限时累计活动
* 全民众测能量值任务
## 使用方法 ## 使用方法
@@ -61,7 +62,6 @@ ql repo https://github.com/hex-ci/smzdm_script.git "" "env.js|bot.js|sendNotify.
* `SMZDM_COMMENT`: 如果要完成评论文章的任务请设置这个环境变量,环境变量的内容是评论的文案,文案要大于 10 个汉字,建议用比较个性化的文案,脚本发布评论后会删除这条评论,但是为防止删除失败的情况,请尽量用好一点的文案,防止被判定为恶意灌水。 * `SMZDM_COMMENT`: 如果要完成评论文章的任务请设置这个环境变量,环境变量的内容是评论的文案,文案要大于 10 个汉字,建议用比较个性化的文案,脚本发布评论后会删除这条评论,但是为防止删除失败的情况,请尽量用好一点的文案,防止被判定为恶意灌水。
* `SMZDM_CROWD_SILVER_5`: 每日抽奖任务默认只进行免费抽奖,如要进行 5 碎银子的抽奖,请设置这个环境变量的值为 `yes` * `SMZDM_CROWD_SILVER_5`: 每日抽奖任务默认只进行免费抽奖,如要进行 5 碎银子的抽奖,请设置这个环境变量的值为 `yes`
* `SMZDM_CROWD_KEYWORD`: 抽奖关键词,执行非免费抽奖时,会优先选择包含此关键词的抽奖,如果未找到包含此关键词的抽奖,则会随机选择一个。 * `SMZDM_CROWD_KEYWORD`: 抽奖关键词,执行非免费抽奖时,会优先选择包含此关键词的抽奖,如果未找到包含此关键词的抽奖,则会随机选择一个。
* `SMZDM_TESTIN_TASK`: 如需进行全民众测-能量值任务, 请设置这个环境变量的值为 `yes`
## 交流群 ## 交流群

View File

@@ -1,5 +1,5 @@
/* /*
smzdm 任务脚本 smzdm 每日任务脚本
项目地址: https://github.com/hex-ci/smzdm_script 项目地址: https://github.com/hex-ci/smzdm_script
cron: 20 14 * * * cron: 20 14 * * *
@@ -11,7 +11,7 @@ const notify = require('./sendNotify');
// ------------------------------------ // ------------------------------------
const $ = new Env('smzdm 任务'); const $ = new Env('smzdm 每日任务');
class SmzdmTaskBot extends SmzdmBot { class SmzdmTaskBot extends SmzdmBot {
constructor(cookie) { constructor(cookie) {
@@ -28,13 +28,7 @@ class SmzdmTaskBot extends SmzdmBot {
let notifyMsg = ''; let notifyMsg = '';
for (let i = 0; i < tasks.length; i++) { notifyMsg = await this.doTasks(tasks);
const task = tasks[i];
let tmpMsg =await this.doTask(task, this.receiveReward);
if(tmpMsg){
notifyMsg += tmpMsg;
}
}
$.log('查询是否有限时累计活动阶段奖励'); $.log('查询是否有限时累计活动阶段奖励');
await wait(5, 15); await wait(5, 15);
@@ -54,199 +48,119 @@ class SmzdmTaskBot extends SmzdmBot {
$.log('无奖励'); $.log('无奖励');
} }
notifyMsg += await this.runTestin();
return notifyMsg || '无可执行任务'; return notifyMsg || '无可执行任务';
} }
// 运行全民众测-能量值 任务 // 执行任务列表中的任务
async runTestin(){ async doTasks(tasks) {
// 从环境变量中读取, 是否开启能量值任务 let notifyMsg = '';
if(process.env.SMZDM_TESTIN_TASK != 'yes' && false){
$.log('🟡请设置 SMZDM_TESTIN_TASK 环境变量值为 yes 后才能进行全民众测-能量值任务!'); for (let i = 0; i < tasks.length; i++) {
return ''; const task = tasks[i];
// 待领取任务
if (task.task_status == '3') {
$.log(`领取[${task.task_name}]奖励:`);
const { isSuccess } = await this.receiveReward(task.task_id);
notifyMsg += `${isSuccess ? '🟢' : '❌'}领取[${task.task_name}]奖励${isSuccess ? '成功' : '失败!请查看日志'}\n`;
await wait(5, 15);
}
// 未完成任务
else if (task.task_status == '2') {
// 浏览文章任务
if (task.task_event_type == 'interactive.view.article') {
const { isSuccess } = await this.doViewTask(task);
notifyMsg += this.getTaskNotifyMessage(isSuccess, task);
await wait(5, 15);
}
// 分享任务
else if (task.task_event_type == 'interactive.share') {
const { isSuccess } = await this.doShareTask(task);
notifyMsg += this.getTaskNotifyMessage(isSuccess, task);
await wait(5, 15);
}
// 抽奖任务
else if (task.task_event_type == 'guide.crowd') {
const { isSuccess, code } = await this.doCrowdTask(task);
if (code !== 99) {
notifyMsg += this.getTaskNotifyMessage(isSuccess, task);
} }
$.log('开始进行全民众测-能量值任务'); await wait(5, 15);
await wait(5, 10);
const activityId = await this.getTestinActivityId();
if (!activityId) {
return '';
} }
// 关注用户任务
else if (task.task_event_type == 'interactive.follow.user') {
const { isSuccess } = await this.doFollowUserTask(task);
const activityInfo = await this.getTestinActivityInfo(activityId); notifyMsg += this.getTaskNotifyMessage(isSuccess, task);
if (!activityInfo) {
return '';
}
let notifyMsg = '\n===============全民众测-必中券-能量值\n';
// 开始做任务 await wait(5, 15);
for (let i = 0; i < activityInfo.activity_task.default_list.length; i++) {
let thisTask = activityInfo.activity_task.default_list[i];
$.log(`做任务: ${thisTask.task_name}`)
let tmpMsg = await this.doTask(thisTask, this.receiveTestin);
if (tmpMsg) {
notifyMsg += tmpMsg;
}
} }
// 关注栏目任务
else if (task.task_event_type == 'interactive.follow.tag') {
const { isSuccess } = await this.doFollowTagTask(task);
// 查询当前拥有的能量数量, 以及过期时间 notifyMsg += this.getTaskNotifyMessage(isSuccess, task);
let myTestinInfo = await this.getMyTestinInfo();
if(myTestinInfo){ await wait(5, 15);
notifyMsg += `当前拥有必中券: ${myTestinInfo.my_energy.my_energy_total}\n必中券过期时间: ${myTestinInfo.my_energy.energy_expired_time}\n`; }
// 关注品牌
else if (task.task_event_type == 'interactive.follow.brand') {
const { isSuccess } = await this.doFollowBrandTask(task);
notifyMsg += this.getTaskNotifyMessage(isSuccess, task);
await wait(5, 15);
}
// 收藏任务
else if (task.task_event_type == 'interactive.favorite') {
const { isSuccess } = await this.doFavoriteTask(task);
notifyMsg += this.getTaskNotifyMessage(isSuccess, task);
await wait(5, 15);
}
// 点赞任务
else if (task.task_event_type == 'interactive.rating') {
const { isSuccess } = await this.doRatingTask(task);
notifyMsg += this.getTaskNotifyMessage(isSuccess, task);
await wait(5, 15);
}
// 评论任务
else if (task.task_event_type == 'interactive.comment') {
if (process.env.SMZDM_COMMENT && String(process.env.SMZDM_COMMENT).length > 10) {
const { isSuccess } = await this.doCommentTask(task);
notifyMsg += this.getTaskNotifyMessage(isSuccess, task);
await wait(5, 15);
}
else {
$.log('🟡请设置 SMZDM_COMMENT 环境变量后才能做评论任务!');
}
}
}
} }
return notifyMsg; return notifyMsg;
} }
// 获取当前能量值任务的活动 ID
async getTestinActivityId() {
$.log('获取当前活动');
await wait(3, 5);
const {
isSuccess,
data,
response
} = await requestApi('https://zhiyou.m.smzdm.com/task/task/ajax_get_activity_id', {
method: 'get',
data: {
'from': 'zhongce',
},
headers: {
...this.getHeadersForWeb(),
Origin: 'https://test.m.smzdm.com',
Referer: `https://test.m.smzdm.com/`
}
});
if (isSuccess) {
return data.data.activity_id;
} else {
$.log(`任务列表失败!${response}`);
return false;
}
}
// 众测中心-必中券信息查询
async getMyTestinInfo() {
$.log('获取必中券信息');
await wait(3, 5);
const { isSuccess, data, response } = await requestApi('https://test.m.smzdm.com/win_coupon/user_data', {
method: 'get',
headers: this.getHeadersForWeb(),
});
if(!isSuccess){
$.log(`获取个人必中券信息失败. ${response}`)
return null;
}
return data.data;
}
// 获取活动下的所有任务
async getTestinActivityInfo(activityId) {
if (!activityId) {
$.log('获取活动详情失败, 没有活动');
return false;
}
await wait(5, 10);
const { isSuccess, data, response } = await requestApi('https://zhiyou.m.smzdm.com/task/task/ajax_get_activity_info', {
method: 'get',
data: {
'activity_id': activityId,
},
headers: this.getHeadersForWeb(),
});
if (isSuccess) {
return data.data;
} else {
$.log(`任务详情失败!${response}`);
return false;
}
}
// 领取奖励
async receiveTestin(task, self) {
await wait(5, 10);
const {
isSuccess,
data,
response
} = await requestApi('https://zhiyou.m.smzdm.com/task/task/ajax_activity_task_receive', {
method: 'post',
data: {
'task_id': task.task_id,
},
headers: self.getHeadersForWeb(),
});
if (!isSuccess) {
$.log(`领取奖励失败!${response}`);
}
return {
isSuccess,
};
}
async doTask(task, receiveCall) {
if(task.task_status == '4'){ // 已经领取的奖励
return this.getTaskNotifyMessage(true, task);
}
if (task.task_status == '3') { // 可领取的奖励
$.log(`领取[${task.task_name}]奖励:`);
await wait(5, 15);
const { isSuccess } = await receiveCall(task, this);
return this.getTaskNotifyMessage(isSuccess, task);
}
if (task.task_event_type == 'interactive.view.article') { // 浏览文章任务
await wait(5, 15);
const {isSuccess} = await this.doViewTask(task, receiveCall);
return this.getTaskNotifyMessage(isSuccess, task);
} else if (task.task_event_type == 'interactive.share') { // 分享任务
await wait(5, 15);
const {isSuccess} = await this.doShareTask(task, receiveCall);
return this.getTaskNotifyMessage(isSuccess, task);
} else if (task.task_event_type == 'guide.crowd') { // 抽奖任务
await wait(5, 15);
const {isSuccess, code} = await this.doCrowdTask(task, receiveCall);
if (code !== 99) {
return this.getTaskNotifyMessage(isSuccess, task);
}
} else if (task.task_event_type == 'interactive.follow.user') { // 关注用户任务
await wait(5, 15);
const {isSuccess} = await this.doFollowUserTask(task, receiveCall);
return this.getTaskNotifyMessage(isSuccess, task);
} else if (task.task_event_type == 'interactive.follow.tag') { // 关注栏目任务
await wait(5, 15);
const {isSuccess} = await this.doFollowTagTask(task, receiveCall);
return this.getTaskNotifyMessage(isSuccess, task);
} else if (task.task_event_type == 'interactive.follow.brand') { // 关注品牌
await wait(5, 15);
const {isSuccess} = await this.doFollowBrandTask(task, receiveCall);
return this.getTaskNotifyMessage(isSuccess, task);
} else if (task.task_event_type == 'interactive.favorite') { // 收藏任务
await wait(5, 15);
const {isSuccess} = await this.doFavoriteTask(task, receiveCall);
return this.getTaskNotifyMessage(isSuccess, task);
} else if (task.task_event_type == 'interactive.rating') { // 点赞任务
await wait(5, 15);
const {isSuccess} = await this.doRatingTask(task, receiveCall);
return this.getTaskNotifyMessage(isSuccess, task);
} else if (task.task_event_type == 'interactive.comment') { // 评论任务
if (process.env.SMZDM_COMMENT && String(process.env.SMZDM_COMMENT).length > 10) {
await wait(5, 15);
const {isSuccess} = await this.doCommentTask(task, receiveCall);
return this.getTaskNotifyMessage(isSuccess, task);
} else {
this.e.log('🟡请设置 SMZDM_COMMENT 环境变量后才能做评论任务!');
}
}
return '';
}
getTaskNotifyMessage(isSuccess, task) { getTaskNotifyMessage(isSuccess, task) {
return `${isSuccess ? '🟢' : '❌'}完成[${task.task_name}]任务${isSuccess ? '成功' : '失败!请查看日志'}\n`; return `${isSuccess ? '🟢' : '❌'}完成[${task.task_name}]任务${isSuccess ? '成功' : '失败!请查看日志'}\n`;
} }
// 执行评论任务 // 执行评论任务
async doCommentTask(task, receiveCall) { async doCommentTask(task) {
$.log(`开始任务: ${task.task_name}`); $.log(`开始任务: ${task.task_name}`);
const articles = await this.getArticleList(20); const articles = await this.getArticleList(20);
@@ -290,11 +204,11 @@ class SmzdmTaskBot extends SmzdmBot {
$.log('领取奖励'); $.log('领取奖励');
await wait(5, 15); await wait(5, 15);
return await receiveCall(task, this); return await this.receiveReward(task.task_id);
} }
// 执行点赞任务 // 执行点赞任务
async doRatingTask(task, receiveCall) { async doRatingTask(task) {
$.log(`开始任务: ${task.task_name}`); $.log(`开始任务: ${task.task_name}`);
let article; let article;
@@ -323,10 +237,6 @@ class SmzdmTaskBot extends SmzdmBot {
article = this.getOneByRandom(articles); article = this.getOneByRandom(articles);
} }
else if (task.task_redirect_url.link_type === 'article') {
// 获取文章信息
article = await this.getArticleDetail(task.task_redirect_url.link_val);
}
else { else {
$.log('尚未支持'); $.log('尚未支持');
@@ -392,11 +302,11 @@ class SmzdmTaskBot extends SmzdmBot {
$.log('领取奖励'); $.log('领取奖励');
await wait(5, 15); await wait(5, 15);
return await receiveCall(task, this); return await this.receiveReward(task.task_id);
} }
// 执行收藏任务 // 执行收藏任务
async doFavoriteTask(task, receiveCall) { async doFavoriteTask(task) {
$.log(`开始任务: ${task.task_name}`); $.log(`开始任务: ${task.task_name}`);
let articleId = ''; let articleId = '';
@@ -489,11 +399,11 @@ class SmzdmTaskBot extends SmzdmBot {
$.log('领取奖励'); $.log('领取奖励');
await wait(5, 15); await wait(5, 15);
return await receiveCall(task, this); return await this.receiveReward(task.task_id);
} }
// 执行关注用户任务 // 执行关注用户任务
async doFollowUserTask(task, receiveCall) { async doFollowUserTask(task) {
$.log(`开始任务: ${task.task_name}`); $.log(`开始任务: ${task.task_name}`);
// 随机选一个用户 // 随机选一个用户
@@ -540,11 +450,11 @@ class SmzdmTaskBot extends SmzdmBot {
$.log('领取奖励'); $.log('领取奖励');
await wait(5, 15); await wait(5, 15);
return await receiveCall(task, this); return await this.receiveReward(task.task_id);
} }
// 执行关注栏目任务(先取关,再关注,最后取关) // 执行关注栏目任务(先取关,再关注,最后取关)
async doFollowTagTask(task, receiveCall) { async doFollowTagTask(task) {
$.log(`开始任务: ${task.task_name}`); $.log(`开始任务: ${task.task_name}`);
let lanmuId = ''; let lanmuId = '';
@@ -607,11 +517,11 @@ class SmzdmTaskBot extends SmzdmBot {
$.log('领取奖励'); $.log('领取奖励');
await wait(5, 15); await wait(5, 15);
return await receiveCall(task, this); return await this.receiveReward(task.task_id);
} }
// 执行关注品牌任务(先取关,再关注,最后取关) // 执行关注品牌任务(先取关,再关注,最后取关)
async doFollowBrandTask(task, receiveCall) { async doFollowBrandTask(task) {
$.log(`开始任务: ${task.task_name}`); $.log(`开始任务: ${task.task_name}`);
// 获取品牌信息 // 获取品牌信息
@@ -650,11 +560,11 @@ class SmzdmTaskBot extends SmzdmBot {
$.log('领取奖励'); $.log('领取奖励');
await wait(5, 15); await wait(5, 15);
return await receiveCall(task, this); return await this.receiveReward(task.task_id);
} }
// 执行抽奖任务 // 执行抽奖任务
async doCrowdTask(task, receiveCall) { async doCrowdTask(task) {
$.log(`开始任务: ${task.task_name}`); $.log(`开始任务: ${task.task_name}`);
let { isSuccess, data } = await this.getCrowd('免费', 0); let { isSuccess, data } = await this.getCrowd('免费', 0);
@@ -693,11 +603,11 @@ class SmzdmTaskBot extends SmzdmBot {
$.log('领取奖励'); $.log('领取奖励');
await wait(5, 15); await wait(5, 15);
return await receiveCall(task, this); return await this.receiveReward(task.task_id);
} }
// 执行文章分享任务 // 执行文章分享任务
async doShareTask(task, receiveCall) { async doShareTask(task) {
$.log(`开始任务: ${task.task_name}`); $.log(`开始任务: ${task.task_name}`);
let articles = []; let articles = [];
@@ -741,11 +651,11 @@ class SmzdmTaskBot extends SmzdmBot {
$.log('领取奖励'); $.log('领取奖励');
await wait(3, 10); await wait(3, 10);
return await receiveCall(task, this); return await this.receiveReward(task.task_id);
} }
// 执行浏览任务 // 执行浏览任务
async doViewTask(task, receiveCall) { async doViewTask(task) {
$.log(`开始任务: ${task.task_name}`); $.log(`开始任务: ${task.task_name}`);
let articles = []; let articles = [];
@@ -809,7 +719,7 @@ class SmzdmTaskBot extends SmzdmBot {
$.log('领取奖励'); $.log('领取奖励');
await wait(3, 10); await wait(3, 10);
return await receiveCall(task, this); return await this.receiveReward(task.task_id);
} }
// 领取活动奖励 // 领取活动奖励
@@ -1179,8 +1089,8 @@ class SmzdmTaskBot extends SmzdmBot {
} }
// 领取任务奖励 // 领取任务奖励
async receiveReward(task, self) { async receiveReward(taskId) {
const robotToken = await self.getRobotToken(); const robotToken = await this.getRobotToken();
if (robotToken === false) { if (robotToken === false) {
return { return {
@@ -1191,14 +1101,14 @@ class SmzdmTaskBot extends SmzdmBot {
const { isSuccess, data, response } = await requestApi('https://user-api.smzdm.com/task/activity_task_receive', { const { isSuccess, data, response } = await requestApi('https://user-api.smzdm.com/task/activity_task_receive', {
method: 'post', method: 'post',
headers: self.getHeaders(), headers: this.getHeaders(),
data: { data: {
robot_token: robotToken, robot_token: robotToken,
geetest_seccode: '', geetest_seccode: '',
geetest_validate: '', geetest_validate: '',
geetest_challenge: '', geetest_challenge: '',
captcha: '', captcha: '',
task_id: task.task_id task_id: taskId
} }
}); });
@@ -1689,3 +1599,7 @@ class SmzdmTaskBot extends SmzdmBot {
}).finally(() => { }).finally(() => {
$.done(); $.done();
}); });
module.exports = {
SmzdmTaskBot,
};

188
smzdm_testing.js Normal file
View File

@@ -0,0 +1,188 @@
/*
smzdm 全民众测能量值任务脚本
项目地址: https://github.com/hex-ci/smzdm_script
cron: 20 15 * * *
*/
const Env = require('./env');
const { requestApi, getEnvCookies, wait } = require('./bot');
const notify = require('./sendNotify');
const { SmzdmTaskBot } = require('./smzdm_task');
// ------------------------------------
const $ = new Env('smzdm 全民众测能量值任务');
class SmzdmTestingTaskBot extends SmzdmTaskBot {
constructor(cookie) {
super(cookie);
}
// 主函数
async run() {
const activityId = await this.getTestingActivityId();
if (!activityId) {
return '';
}
await wait(5, 10);
const activityInfo = await this.getTestingActivityInfo(activityId);
if (!activityInfo) {
return '';
}
await wait(5, 10);
let notifyMsg = await this.doTasks(activityInfo.activity_task.default_list);
await wait(3, 5);
// 查询当前拥有的能量数量, 以及过期时间
let myTestingInfo = await this.getMyTestingInfo();
if (myTestingInfo) {
notifyMsg += `当前拥有必中券: ${myTestingInfo.my_energy.my_energy_total}\n必中券过期时间: ${myTestingInfo.my_energy.energy_expired_time}\n`;
}
return notifyMsg || '无可执行任务';
}
// 获取当前能量值任务的活动 ID
async getTestingActivityId() {
$.log('获取活动 ID');
const { isSuccess, data, response } = await requestApi('https://zhiyou.m.smzdm.com/task/task/ajax_get_activity_id', {
method: 'get',
data: {
'from': 'zhongce',
},
headers: {
...this.getHeadersForWeb(),
Origin: 'https://test.m.smzdm.com',
Referer: 'https://test.m.smzdm.com/',
}
});
if (isSuccess) {
return data.data.activity_id;
}
else {
$.log(`获取活动 ID 失败!${response}`);
return false;
}
}
// 获取活动下的所有任务
async getTestingActivityInfo(id) {
$.log('获取活动信息');
const { isSuccess, data, response } = await requestApi('https://zhiyou.m.smzdm.com/task/task/ajax_get_activity_info', {
method: 'get',
data: {
'activity_id': id,
},
headers: this.getHeadersForWeb(),
});
if (isSuccess) {
return data.data;
}
else {
$.log(`获取活动信息失败!${response}`);
return false;
}
}
// 众测中心-必中券信息查询
async getMyTestingInfo() {
$.log('获取必中券信息');
const { isSuccess, data, response } = await requestApi('https://test.m.smzdm.com/win_coupon/user_data', {
method: 'get',
headers: this.getHeadersForWeb(),
});
if (!isSuccess) {
$.log(`获取个人必中券信息失败!${response}`);
return null;
}
return data.data;
}
// 领取奖励
async receiveReward(taskId) {
const { isSuccess, data, response } = await requestApi('https://zhiyou.m.smzdm.com/task/task/ajax_activity_task_receive', {
method: 'post',
data: {
'task_id': taskId,
},
headers: this.getHeadersForWeb(),
});
if (isSuccess) {
return {
isSuccess,
msg
};
}
else {
$.log(`领取任务奖励失败!${response}`);
return {
isSuccess,
msg: '领取任务奖励失败!'
};
}
}
}
!(async () => {
const cookies = getEnvCookies();
if (cookies === false) {
$.log('\n请先设置 SMZDM_COOKIE 环境变量');
return;
}
let notifyContent = '';
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i];
if (!cookie) {
continue;
}
if (i > 0) {
$.log();
await wait(10, 30);
$.log();
}
const sep = `\n****** 账号${i + 1} ******\n`;
$.log(sep);
const bot = new SmzdmTestingTaskBot(cookie);
const msg = await bot.run();
notifyContent += `${sep}${msg}\n`;
}
$.log();
await notify.sendNotify($.name, notifyContent);
})().catch((e) => {
$.log('', `${$.name}, 失败! 原因: ${e}!`, '')
}).finally(() => {
$.done();
});