From bd7c85cf9c8be749815759416dcd59d303053cb8 Mon Sep 17 00:00:00 2001 From: Hex Date: Sat, 4 Mar 2023 15:32:50 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=BB=BB=E5=8A=A1=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smzdm_task.js | 1077 +++++++++++++++++++++++++------------------------ 1 file changed, 547 insertions(+), 530 deletions(-) diff --git a/smzdm_task.js b/smzdm_task.js index 08d00e5..2d4134e 100644 --- a/smzdm_task.js +++ b/smzdm_task.js @@ -10,6 +10,12 @@ const crypto = require('crypto'); const Env = require('./env'); const notify = require('./sendNotify'); +const SIGN_KEY = 'apr1$AwP!wRRT$gJ/q.X24poeBInlUJC'; +const APP_VERSION = '10.3.0'; +const DEFAULT_USER_AGENT = `smzdm_android_V${APP_VERSION} rv:121 (Redmi Note 3;Android10;zh)smzdmapp`; +const DEFAULT_WEB_USER_AGENT = `Mozilla/5.0 (Linux; Android 7.1.1;) AppleWebKit/537.36 (KHTML, like Gecko) Mobile/15E148/smzdm ${APP_VERSION} rv:121`; +const FOLLOW_USERS = [5874442461, 3050600933, 7466566467, 3028144837, 4573019331, 6375174216, 7987627594, 9730899715, 5034569705, 6470041157]; + const $ = new Env('什么值得买任务'); let cookiesArr = []; @@ -27,57 +33,30 @@ if (process.env.SMZDM_COOKIE) { } } -const SIGN_KEY = 'apr1$AwP!wRRT$gJ/q.X24poeBInlUJC'; -const APP_VERSION = '10.3.0'; -const DEFAULT_USER_AGENT = `smzdm_android_V${APP_VERSION} rv:121 (Redmi Note 3;Android10;zh)smzdmapp`; -const DEFAULT_WEB_USER_AGENT = `Mozilla/5.0 (Linux; Android 7.1.1;) AppleWebKit/537.36 (KHTML, like Gecko) Mobile/15E148/smzdm ${APP_VERSION} rv:121`; -const FOLLOW_USERS = [5874442461, 3050600933, 7466566467, 3028144837, 4573019331, 6375174216, 7987627594, 9730899715, 5034569705, 6470041157]; - -function randomStr(len = 18) { +const randomStr = (len = 18) => { const char = '0123456789'; let str = ''; + for (let i = 0; i < len; i++) { str += char.charAt(Math.floor(Math.random() * char.length)); } - return str; -} -function parseJSON(str) { + return str; +}; + +const parseJSON = (str) => { try { return JSON.parse(str); } catch (e) { return {}; } -} +}; -function getToken(cookie) { - const match = cookie.match(/sess=(.*?);/); - - return match ? match[1] : ''; -} - -function getHeaders(cookie, isWeb = false) { - const androidCookie = cookie.replace('iphone', 'android').replace('iPhone', 'Android').replace('apk_partner_name=appstore', 'apk_partner_name=android'); - - return isWeb ? { - Accept: '*/*', - 'Accept-Language': 'zh-CN,zh-Hans;q=0.9', - 'Accept-Encoding': 'gzip', - 'User-Agent': DEFAULT_WEB_USER_AGENT, - Cookie: androidCookie - } : { - Accept: '*/*', - 'Accept-Language': 'zh-Hans-CN;q=1', - 'Accept-Encoding': 'gzip', - 'request_key': randomStr(18), - 'User-Agent': process.env.SMZDM_USER_AGENT || DEFAULT_USER_AGENT, - Cookie: androidCookie - }; -} +const removeTags = (str) => str.replace(/<[^<]+?>/g, ''); // 添加公共参数并签名数据 -function signFormData(data) { +const signFormData = (data) => { const newData = { weixin: '1', f: 'android', @@ -95,14 +74,10 @@ function signFormData(data) { ...newData, sign }; -} - -function removeTags(str) { - return str.replace(/<[^<]+?>/g, ''); -} +}; // 公共请求函数 -async function requestApi(url, inputOptions = {}) { +const requestApi = async (url, inputOptions = {}) => { const options = { ...inputOptions }; if (!options.method) { @@ -126,7 +101,7 @@ async function requestApi(url, inputOptions = {}) { return { isSuccess: options.parseJSON === false ? true : (data.error_code == '0'), - response: JSON.stringify(data), + response: options.parseJSON === false ? response.body : JSON.stringify(data), data }; }).catch((error) => { @@ -136,561 +111,602 @@ async function requestApi(url, inputOptions = {}) { data: error }; }) -} +}; -// 获取任务列表 -async function getTaskList(cookie) { - const { isSuccess, data } = await requestApi('https://user-api.smzdm.com/task/list_new', { - method: 'post', - headers: getHeaders(cookie), - data: { - get_total: '1', - limit: '100', - offset: '0', - point_type: '0', - token: getToken(cookie) - } - }); +// ------------------------------------ - if (isSuccess) { - return { - tasks: data.data.rows[0].cell_data.activity_task.accumulate_list.task_list, - detail: data.data.rows[0] - }; +class SmzdmBot { + constructor(cookie) { + this.cookie = cookie; } - else { - return { - tasks: [], - detail: {} - }; - } -} -// 领取奖励 -async function receiveReward(taskId, cookie) { - const { isSuccess, data, response } = await requestApi('https://user-api.smzdm.com/task/activity_task_receive', { - method: 'post', - headers: getHeaders(cookie), - data: { - task_id: taskId, - token: getToken(cookie) - } - }); + // 主函数 + async run() { + const { tasks } = await this.getTaskList(); - if (isSuccess) { - const msg = removeTags(data.data.reward_msg); + let count = 0; - $.log(msg); + for (let i = 0; i < tasks.length; i++) { + const task = tasks[i]; - return { - isSuccess, - msg - }; - } - else { - $.log(`领取任务奖励失败!${response}`); + // 待领取任务 + if (task.task_status == '3') { + const { isSuccess } = await this.receiveReward(task.task_id); - return { - isSuccess, - msg: '领取任务奖励失败!' - }; - } -} - -// 获取 Web 文章列表 -async function getArticleList(cookie) { - const { isSuccess, data, response } = await requestApi('https://post.smzdm.com/json_more/?tab_id=tuijian&filterUrl=tuijian', { - sign: false, - headers: { - ...getHeaders(cookie, true), - Referer: 'https://post.smzdm.com/' - } - }); - - if (isSuccess) { - // 目前只取前两个做任务 - return data.data.slice(0, 2); - } - else { - $.log(`获取文章列表失败: ${response}`); - return []; - } -} - -// 分享的每日奖励 -async function shareDailyReward(channelId, cookie) { - const { isSuccess, data, response } = await requestApi('https://user-api.smzdm.com/share/daily_reward', { - method: 'post', - headers: getHeaders(cookie), - data: { - channel_id: channelId, - token: getToken(cookie) - } - }); - - if (isSuccess) { - $.log(data.data.reward_desc); - - return { - isSuccess, - msg: data.data.reward_desc - }; - } - else { - if (data) { - $.log(data.error_msg); - - return { - isSuccess, - msg: data.error_msg - }; - } - else { - $.log(`分享每日奖励请求失败!${response}`); - - return { - isSuccess, - msg: '分享每日奖励请求失败!' - }; - } - } -} - -// 分享完成后回调接口 -async function shareCallback(articleId, channelId, cookie) { - const { isSuccess, response } = await requestApi('https://user-api.smzdm.com/share/callback', { - method: 'post', - headers: getHeaders(cookie), - data: { - article_id: articleId, - channel_id: channelId, - token: getToken(cookie) - } - }); - - if (isSuccess) { - $.log('分享回调完成。'); - - return { - isSuccess, - msg: '' - }; - } - else { - $.log(`分享回调失败!${response}`); - - return { - isSuccess, - msg: '分享回调失败!' - }; - } -} - -// 分享完成,可以领取奖励了 -async function shareArticleDone(articleId, channelId, cookie) { - const { isSuccess, response } = await requestApi('https://user-api.smzdm.com/share/article_reward', { - method: 'post', - headers: getHeaders(cookie), - data: { - article_id: articleId, - channel_id: channelId, - token: getToken(cookie) - } - }); - - if (isSuccess) { - $.log('完成分享成功。'); - - return { - isSuccess, - msg: '完成分享成功。' - }; - } - else { - $.log(`完成分享失败!${response}`); - - return { - isSuccess: false, - msg: '完成分享失败!' - }; - } -} - -// 获取免费抽奖信息 -async function getFreeCrowd(cookie) { - const { isSuccess, data } = await requestApi('https://zhiyou.smzdm.com/user/crowd/', { - sign: false, - parseJSON: false, - headers: getHeaders(cookie, true) - }); - - if (isSuccess) { - const match = data.match(/]+?)>\s+?]+?>\s*免费抽奖\s*<\/div>\s+-0<\/span>[\s\S]+?<\/button>/i); - - if (match) { - const matchCrowd = match[1].match(/data-crowd_id="(\d+)"/i); - - if (matchCrowd) { - $.log(`免费抽奖ID: ${matchCrowd[1]}`); - return { - isSuccess: true, - data: matchCrowd[1] + if (isSuccess) { + count++; } + + $.log('等候 5 秒'); + await $.wait(5000); } - else { - $.log(`未找到免费抽奖ID`); - return { - isSuccess: false + // 未完成任务 + else if (task.task_status == '2') { + if (task.task_event_type == 'interactive.view.article') { + const result = await this.doViewTask(task); + + if (result.isSuccess) { + count++; + } + + $.log('等候 5 秒'); + await $.wait(5000); + } + else if (task.task_event_type == 'interactive.share') { + let result; + + if (task.article_id == '0') { + result = await this.doShareTaskMulti(task); + } + else { + result = await this.doShareTaskSingle(task); + } + + if (result.isSuccess) { + count++; + } + + $.log('等候 5 秒'); + await $.wait(5000); + } + else if (task.task_event_type == 'guide.crowd') { + const result = await this.doCrowdTask(task); + + if (result.isSuccess) { + count++; + } + + $.log('等候 5 秒'); + await $.wait(5000); + } + else if (task.task_event_type == 'interactive.follow.user') { + const result = await this.doFollowTask(task); + + if (result.isSuccess) { + count++; + } + + $.log('等候 5 秒'); + await $.wait(5000); } } } - else { - $.log(`未找到免费抽奖`); - return { - isSuccess: false + + $.log('等候 5 秒查看是否有活动奖励'); + await $.wait(5000); + + // 领取活动奖励 + const { detail } = await this.getTaskList(); + + if (detail.cell_data && detail.cell_data.activity_reward_status == '1') { + $.log('等候 3 秒领取活动奖励'); + await $.wait(5000); + + await this.receiveActivity(detail.cell_data); + } + + return `成功完成任务数: ${count}`; + } + + // 领取活动奖励 + async receiveActivity(activity) { + $.log(`领取活动奖励: ${activity.activity_name}`); + + const { isSuccess, data, response } = await requestApi('https://user-api.smzdm.com/task/activity_receive', { + method: 'post', + headers: this.getHeaders(), + data: { + token: this.getToken(), + activity_id: activity.activity_id } + }); + + if (isSuccess) { + $.log(removeTags(data.data.reward_msg)); + + return { + isSuccess + }; + } + else { + $.log(`领取活动奖励失败!${response}`); + + return { + isSuccess + }; } } - else { - $.log(`获取免费抽奖失败: ${data}`); - return []; - } -} -// 参加抽奖 -async function joinCrowd(id, cookie) { - const { isSuccess, data, response } = await requestApi('https://zhiyou.m.smzdm.com/user/crowd/ajax_participate', { - method: 'post', - sign: false, - headers: { - ...getHeaders(cookie, true), - Origin: 'https://zhiyou.m.smzdm.com', - Referer: `https://zhiyou.m.smzdm.com/user/crowd/p/${id}/`, - }, - data: { - crowd_id: id, - sourcePage: `https://zhiyou.m.smzdm.com/user/crowd/p/${id}/`, - client_type: 'android', - sourceRoot: '个人中心', - sourceMode: '幸运屋抽奖', - price_id: '1' - } - }); + // 执行关注任务(先取关,再关注,执行三次,最后取关) + async doFollowTask(task) { + $.log(`开始任务: ${task.task_name}`); - if (isSuccess) { - $.log(removeTags(data.data.msg)); - } - else { - $.log(`参加免费抽奖失败: ${response}`); - } + // 随机选一个用户操作 + const userId = FOLLOW_USERS[Math.floor(Math.random() * FOLLOW_USERS.length)]; - return { - isSuccess, - response - }; -} - -// 关注用户 -async function followUser(id, isFollow = true, cookie) { - const { isSuccess, response } = await requestApi('https://zhiyou.smzdm.com/guanzhu/ajax_follow', { - method: 'post', - sign: false, - headers: { - ...getHeaders(cookie, true), - Origin: 'https://post.smzdm.com', - Referer: `https://post.smzdm.com/`, - }, - data: { - follow: isFollow ? 1 : 0, - type: 'user', - keyword: id, - source: '无', - operationalpositionID: '无', - aid: '无', - cid: '无', - atp: '无', - tagID: '无', - p: '1', - is_detail: '0', - sourcePage: 'https://post.smzdm.com/', - sourceMode: '无', - client_type: 'android' - } - }); - - if (isSuccess) { - $.log(`${isFollow ? '关注' : '取关'}成功: ${id}`); - } - else { - $.log(`${isFollow ? '关注' : '取关'}失败!${response}`); - } - - return { - isSuccess, - response - }; -} - -// 执行浏览任务 -async function doViewTask(task, cookie) { - $.log(`开始任务: ${task.task_name}`); - - $.log('延迟 11 秒模拟阅读文章'); - await $.wait(11000); - - const { isSuccess, response } = await requestApi('https://user-api.smzdm.com/task/event_view_article', { - method: 'post', - headers: getHeaders(cookie), - data: { - article_id: task.article_id, - channel_id: task.channel_id, - token: getToken(cookie) - } - }); - - if (isSuccess) { - $.log('延迟 3 秒领取奖励'); - await $.wait(3000); - - return await receiveReward(task.task_id, cookie); - } - else { - $.log(`任务异常!${response}`); - - return { - isSuccess - }; - } -} - -// 执行多篇文章的分享任务 -async function doShareTaskMulti(task, cookie) { - $.log(`开始任务: ${task.task_name}`); - - const articles = await getArticleList(cookie); - - for (let i = 0; i < articles.length; i++) { - $.log(`开始分享第 ${i + 1} 篇文章...`); - - const article = articles[i]; - - $.log('等候 5 秒'); - await $.wait(3000); - - await shareDailyReward(article.channel_id, cookie); - await shareCallback(article.article_id, article.channel_id, cookie); + $.log('先尝试取关用户,如果出错表示尚未关注此用户,忽略这个错误即可。'); + await this.followUser(userId, false); $.log('等候 3 秒'); await $.wait(3000); - await shareArticleDone(article.article_id, article.channel_id, cookie); + for (let i = 0; i < 3; i++) { + await this.followUser(userId, true); + + $.log('等候 3 秒'); + await $.wait(3000); + + await this.followUser(userId, false); + + $.log('等候 5 秒'); + await $.wait(3000); + } + + $.log('延迟 5 秒领取奖励'); + await $.wait(5000); + + return await this.receiveReward(task.task_id); + } + + // 执行抽奖任务 + async doCrowdTask(task) { + $.log(`开始任务: ${task.task_name}`); + + const { isSuccess, data } = await this.getFreeCrowd(); + + if (!isSuccess) { + return { + isSuccess + }; + } $.log('等候 5 秒'); await $.wait(5000); + + const result = await this.joinCrowd(data); + + if (!result.isSuccess) { + return { + isSuccess: result.isSuccess + }; + } + + $.log('延迟 5 秒领取奖励'); + await $.wait(5000); + + return await this.receiveReward(task.task_id); } - $.log('延迟 3 秒领取奖励'); - await $.wait(3000); + // 执行一篇文章的分享任务 + async doShareTaskSingle(task) { + $.log(`开始任务: ${task.task_name}`); - return await receiveReward(task.task_id, cookie); -} + $.log(`开始分享文章...`); -// 执行一篇文章的分享任务 -async function doShareTaskSingle(task, cookie) { - $.log(`开始任务: ${task.task_name}`); + $.log('等候 5 秒'); + await $.wait(5000); - $.log(`开始分享文章...`); - - $.log('等候 5 秒'); - await $.wait(5000); - - await shareDailyReward(task.channel_id, cookie); - await shareCallback(task.article_id, task.channel_id, cookie); - - $.log('等候 3 秒'); - await $.wait(3000); - - await shareArticleDone(task.article_id, task.channel_id, cookie); - - $.log('延迟 5 秒领取奖励'); - await $.wait(5000); - - return await receiveReward(task.task_id, cookie); -} - -// 执行抽奖任务 -async function doCrowdTask(task, cookie) { - $.log(`开始任务: ${task.task_name}`); - - const { isSuccess, data } = await getFreeCrowd(cookie); - - if (!isSuccess) { - return { - isSuccess - }; - } - - $.log('等候 5 秒'); - await $.wait(5000); - - const result = await joinCrowd(data, cookie); - - if (!result.isSuccess) { - return { - isSuccess: result.isSuccess - }; - } - - $.log('延迟 5 秒领取奖励'); - await $.wait(5000); - - return await receiveReward(task.task_id, cookie); -} - -// 执行关注任务(先取关,再关注,执行三次,最后取关) -async function doFollowTask(task, cookie) { - $.log(`开始任务: ${task.task_name}`); - - // 随机选一个用户操作 - const userId = FOLLOW_USERS[Math.floor(Math.random() * FOLLOW_USERS.length)]; - - $.log('先尝试取关用户,如果出错表示尚未关注此用户,忽略这个错误即可。'); - await followUser(userId, false, cookie); - - $.log('等候 3 秒'); - await $.wait(3000); - - for (let i = 0; i < 3; i++) { - await followUser(userId, true, cookie); + await this.shareDailyReward(task.channel_id); + await this.shareCallback(task.article_id, task.channel_id); $.log('等候 3 秒'); await $.wait(3000); - await followUser(userId, false, cookie); + await this.shareArticleDone(task.article_id, task.channel_id); - $.log('等候 5 秒'); - await $.wait(3000); + $.log('延迟 5 秒领取奖励'); + await $.wait(5000); + + return await this.receiveReward(task.task_id); } - $.log('延迟 5 秒领取奖励'); - await $.wait(5000); + // 执行多篇文章的分享任务 + async doShareTaskMulti(task) { + $.log(`开始任务: ${task.task_name}`); - return await receiveReward(task.task_id, cookie); -} + const articles = await this.getArticleList(); -async function receiveActivity(activity, cookie) { - $.log(`领取活动奖励: ${activity.activity_name}`); + for (let i = 0; i < articles.length; i++) { + $.log(`开始分享第 ${i + 1} 篇文章...`); - const { isSuccess, data, response } = await requestApi('https://user-api.smzdm.com/task/activity_receive', { - method: 'post', - headers: getHeaders(cookie), - data: { - activity_id: activity.activity_id, - token: getToken(cookie) - } - }); + const article = articles[i]; - if (isSuccess) { - $.log(removeTags(data.data.reward_msg)); + $.log('等候 5 秒'); + await $.wait(3000); - return { - isSuccess - }; - } - else { - $.log(`领取活动奖励失败!${response}`); + await this.shareDailyReward(article.channel_id); + await this.shareCallback(article.article_id, article.channel_id); - return { - isSuccess - }; - } -} + $.log('等候 3 秒'); + await $.wait(3000); -async function run(cookie) { - const { tasks } = await getTaskList(cookie); - - let count = 0; - - for (let i = 0; i < tasks.length; i++) { - const task = tasks[i]; - - // 待领取任务 - if (task.task_status == '3') { - const { isSuccess } = await receiveReward(task.task_id, cookie); - - if (isSuccess) { - count++; - } + await this.shareArticleDone(article.article_id, article.channel_id); $.log('等候 5 秒'); await $.wait(5000); } - // 未完成任务 - else if (task.task_status == '2') { - if (task.task_event_type == 'interactive.view.article') { - const result = await doViewTask(task, cookie); - if (result.isSuccess) { - count++; - } + $.log('延迟 3 秒领取奖励'); + await $.wait(3000); - $.log('等候 5 秒'); - await $.wait(5000); + return await this.receiveReward(task.task_id); + } + + // 执行浏览任务 + async doViewTask(task) { + $.log(`开始任务: ${task.task_name}`); + + $.log('延迟 11 秒模拟阅读文章'); + await $.wait(11000); + + const { isSuccess, response } = await requestApi('https://user-api.smzdm.com/task/event_view_article', { + method: 'post', + headers: this.getHeaders(), + data: { + token: this.getToken(), + article_id: task.article_id, + channel_id: task.channel_id } - else if (task.task_event_type == 'interactive.share') { - let result; + }); - if (task.article_id == '0') { - result = await doShareTaskMulti(task, cookie); + if (isSuccess) { + $.log('延迟 3 秒领取奖励'); + await $.wait(3000); + + return await this.receiveReward(task.task_id); + } + else { + $.log(`任务异常!${response}`); + + return { + isSuccess + }; + } + } + + // 关注/取关用户 + async followUser(id, isFollow = true) { + const { isSuccess, response } = await requestApi('https://zhiyou.smzdm.com/guanzhu/ajax_follow', { + method: 'post', + sign: false, + headers: { + ...this.getHeaders(true), + Origin: 'https://post.smzdm.com', + Referer: `https://post.smzdm.com/` + }, + data: { + follow: isFollow ? 1 : 0, + type: 'user', + keyword: id, + source: '无', + operationalpositionID: '无', + aid: '无', + cid: '无', + atp: '无', + tagID: '无', + p: '1', + is_detail: '0', + sourcePage: 'https://post.smzdm.com/', + sourceMode: '无', + client_type: 'android' + } + }); + + if (isSuccess) { + $.log(`${isFollow ? '关注' : '取关'}成功: ${id}`); + } + else { + $.log(`${isFollow ? '关注' : '取关'}失败!${response}`); + } + + return { + isSuccess, + response + }; + } + + // 参加抽奖 + async joinCrowd(id) { + const { isSuccess, data, response } = await requestApi('https://zhiyou.m.smzdm.com/user/crowd/ajax_participate', { + method: 'post', + sign: false, + headers: { + ...this.getHeaders(true), + Origin: 'https://zhiyou.m.smzdm.com', + Referer: `https://zhiyou.m.smzdm.com/user/crowd/p/${id}/` + }, + data: { + crowd_id: id, + sourcePage: `https://zhiyou.m.smzdm.com/user/crowd/p/${id}/`, + client_type: 'android', + sourceRoot: '个人中心', + sourceMode: '幸运屋抽奖', + price_id: '1' + } + }); + + if (isSuccess) { + $.log(removeTags(data.data.msg)); + } + else { + $.log(`参加免费抽奖失败: ${response}`); + } + + return { + isSuccess, + response + }; + } + + // 获取免费抽奖信息 + async getFreeCrowd() { + const { isSuccess, data, response } = await requestApi('https://zhiyou.smzdm.com/user/crowd/', { + sign: false, + parseJSON: false, + headers: this.getHeaders(true) + }); + + if (isSuccess) { + const match = data.match(/]+?)>\s+?]+?>\s*免费抽奖\s*<\/div>\s+-0<\/span>[\s\S]+?<\/button>/i); + + if (match) { + const matchCrowd = match[1].match(/data-crowd_id="(\d+)"/i); + + if (matchCrowd) { + $.log(`免费抽奖ID: ${matchCrowd[1]}`); + + return { + isSuccess: true, + data: matchCrowd[1] + }; } else { - result = await doShareTaskSingle(task, cookie); - } + $.log(`未找到免费抽奖ID`); - if (result.isSuccess) { - count++; + return { + isSuccess: false + }; } - - $.log('等候 5 秒'); - await $.wait(5000); } - else if (task.task_event_type == 'guide.crowd') { - const result = await doCrowdTask(task, cookie); + else { + $.log(`未找到免费抽奖`); - if (result.isSuccess) { - count++; - } - - $.log('等候 5 秒'); - await $.wait(5000); + return { + isSuccess: false + }; } - else if (task.task_event_type == 'interactive.follow.user') { - const result = await doFollowTask(task, cookie); + } + else { + $.log(`获取免费抽奖失败: ${response}`); - if (result.isSuccess) { - count++; - } + return { + isSuccess: false + }; + } + } - $.log('等候 5 秒'); - await $.wait(5000); + // 分享完成,可以领取奖励了 + async shareArticleDone(articleId, channelId) { + const { isSuccess, response } = await requestApi('https://user-api.smzdm.com/share/article_reward', { + method: 'post', + headers: this.getHeaders(), + data: { + token: this.getToken(), + article_id: articleId, + channel_id: channelId + } + }); + + if (isSuccess) { + $.log('完成分享成功。'); + + return { + isSuccess, + msg: '完成分享成功。' + }; + } + else { + $.log(`完成分享失败!${response}`); + + return { + isSuccess: false, + msg: '完成分享失败!' + }; + } + } + + // 分享完成后回调接口 + async shareCallback(articleId, channelId) { + const { isSuccess, response } = await requestApi('https://user-api.smzdm.com/share/callback', { + method: 'post', + headers: this.getHeaders(), + data: { + token: this.getToken(), + article_id: articleId, + channel_id: channelId + } + }); + + if (isSuccess) { + $.log('分享回调完成。'); + + return { + isSuccess, + msg: '' + }; + } + else { + $.log(`分享回调失败!${response}`); + + return { + isSuccess, + msg: '分享回调失败!' + }; + } + } + + // 分享的每日奖励(貌似没啥用) + async shareDailyReward(channelId) { + const { isSuccess, data, response } = await requestApi('https://user-api.smzdm.com/share/daily_reward', { + method: 'post', + headers: this.getHeaders(), + data: { + token: this.getToken(), + channel_id: channelId + } + }); + + if (isSuccess) { + $.log(data.data.reward_desc); + + return { + isSuccess, + msg: data.data.reward_desc + }; + } + else { + if (data) { + $.log(data.error_msg); + + return { + isSuccess, + msg: data.error_msg + }; + } + else { + $.log(`分享每日奖励请求失败!${response}`); + + return { + isSuccess, + msg: '分享每日奖励请求失败!' + }; } } } - $.log('等候 5 秒'); - await $.wait(5000); + // 获取 Web 文章列表 + async getArticleList() { + const { isSuccess, data, response } = await requestApi('https://post.smzdm.com/json_more/?tab_id=tuijian&filterUrl=tuijian', { + sign: false, + headers: { + ...this.getHeaders(true), + Referer: 'https://post.smzdm.com/' + } + }); - // 领取活动奖励 - const { detail } = await getTaskList(cookie); - - if (detail.cell_data && detail.cell_data.activity_reward_status == '1') { - $.log('等候 3 秒'); - await $.wait(5000); - - await receiveActivity(detail.cell_data, cookie); + if (isSuccess) { + // 目前只取前两个做任务 + return data.data.slice(0, 2); + } + else { + $.log(`获取文章列表失败: ${response}`); + return []; + } } - return `成功完成任务数: ${count}`; + // 领取任务奖励 + async receiveReward(taskId) { + const { isSuccess, data, response } = await requestApi('https://user-api.smzdm.com/task/activity_task_receive', { + method: 'post', + headers: this.getHeaders(), + data: { + token: this.getToken(), + task_id: taskId + } + }); + + if (isSuccess) { + const msg = removeTags(data.data.reward_msg); + + $.log(msg); + + return { + isSuccess, + msg + }; + } + else { + $.log(`领取任务奖励失败!${response}`); + + return { + isSuccess, + msg: '领取任务奖励失败!' + }; + } + } + + // 获取任务列表 + async getTaskList() { + const { isSuccess, data } = await requestApi('https://user-api.smzdm.com/task/list_new', { + method: 'post', + headers: this.getHeaders(), + data: { + token: this.getToken(), + get_total: '1', + limit: '100', + offset: '0', + point_type: '0' + } + }); + + if (isSuccess) { + return { + tasks: data.data.rows[0].cell_data.activity_task.accumulate_list.task_list, + detail: data.data.rows[0] + }; + } + else { + return { + tasks: [], + detail: {} + }; + } + } + + getToken() { + const match = this.cookie.match(/sess=(.*?);/); + + return match ? match[1] : ''; + } + + getHeaders(isWeb = false) { + const androidCookie = this.cookie.replace('iphone', 'android').replace('iPhone', 'Android').replace('apk_partner_name=appstore', 'apk_partner_name=android'); + + return isWeb ? { + Accept: '*/*', + 'Accept-Language': 'zh-CN,zh-Hans;q=0.9', + 'Accept-Encoding': 'gzip', + 'User-Agent': DEFAULT_WEB_USER_AGENT, + Cookie: androidCookie + } : { + Accept: '*/*', + 'Accept-Language': 'zh-Hans-CN;q=1', + 'Accept-Encoding': 'gzip', + 'request_key': randomStr(18), + 'User-Agent': process.env.SMZDM_USER_AGENT || DEFAULT_USER_AGENT, + Cookie: androidCookie + }; + } } !(async () => { @@ -713,7 +729,8 @@ async function run(cookie) { $.log(sep); - const msg = await run(cookie); + const bot = new SmzdmBot(cookie); + const msg = await bot.run(); $.log(msg + '\n');