Code Monkey home page Code Monkey logo

Comments (5)

18059103437 avatar 18059103437 commented on August 22, 2024

if (
["邀请好友助力", "所在战队成员满5人", "所在战队成员满3人", "邀人助力得80-200金币","在战队PK中拉1人助力","累计赢得五场战队PK"].includes(
taskCollection.taskName
)
)

@执行任务: {taskName: "所在战队成员满3人", taskId: 13, taskType: 0, waitDuration: 0, itemId: "1"}
*京东盖楼:42 
调用结果: {bizCode: -15, bizMsg: "活动太火爆了,请稍后再试", success: false}

这边代码优化下就可以了

from sweater.

gutianyi avatar gutianyi commented on August 22, 2024

这一段在哪儿改啊

from sweater.

realeve avatar realeve commented on August 22, 2024

@gutianyi

var secretp = "";
var taskList = [];

// 恢复被覆盖的 alert 函数
(() => {
  var frame = document.createElement("iframe");
  frame.style.display = "none";
  document.body.appendChild(frame);
  window.alert = frame.contentWindow.alert;
})();

// 请求函数
var request = (functionId, body = {}) =>
  fetch("https://api.m.jd.com/client.action", {
    body: `functionId=${functionId}&body=${JSON.stringify(
      body
    )}&client=wh5&clientVersion=1.0.0`,
    headers: {
      "content-type": "application/x-www-form-urlencoded",
    },
    method: "POST",
    credentials: "include",
  });

// 模拟任务完成请求
var collector = (task, actionType) => {
  console.log(actionType ? "@领取任务:" : "@执行任务:", task);

  request("cakebaker_ckCollectScore", {
    taskId: task.taskId,
    itemId: task.itemId,
    actionType: actionType ? 1 : undefined,
    safeStr: JSON.stringify({ secretp }),
  })
    .then((res) => res.json())
    .then((res) => {
      console.log("调用结果:", res.data);

      // 如果是执行任务,即任务已经完成,则进行下一个任务
      if (!actionType) {
        start();
      }
    });
};

// 甄选优品任务处理
var superiorTask = (() => {
  // 是否有请求正在执行
  var isBusy = false;

  return (rawTaskCollection) => {
    var getFeedDetail = (copiedTaskCollection) => {
      request("cakebaker_getFeedDetail", {
        taskIds: copiedTaskCollection["productInfoVos"]
          .map((item) => item.itemId)
          .toString(),
      })
        .then((res) => res.json())
        .then((res) => {
          var result = res.data.result;

          // 确认任务集合所在键名
          var taskCollectionContentKeyName = Object.keys(result).find(
            (keyName) => /Vos?$/.test(keyName) && !["taskVos"].includes(keyName)
          );

          result[taskCollectionContentKeyName].forEach((taskCollection) => {
            Array(taskCollection.maxTimes - taskCollection.times)
              .fill(true)
              .forEach((_, index) => {
                taskList.unshift({
                  taskName: taskCollection.taskName,
                  taskId: taskCollection.taskId,
                  taskType: taskCollection.taskType,
                  waitDuration: taskCollection.waitDuration,
                  itemId: taskCollection.productInfoVos[index].itemId,
                });
              });
          });

          // 解除请求锁定
          isBusy = false;
        });
    };

    if (!isBusy) {
      isBusy = true;
      getFeedDetail(JSON.parse(JSON.stringify(rawTaskCollection)));
    } else {
      // 一秒后重试
      setTimeout(
        getFeedDetail,
        1000,
        JSON.parse(JSON.stringify(rawTaskCollection))
      );
    }
  };
})();

// 开始任务
var start = () => {
  var task = taskList.pop();

  if (task) {
    // 除了小精灵和连签外的任务要先领取
    if (!["小精灵", "连签得金币"].includes(task.taskName)) {
      setTimeout(collector, 0, task, true);
    }
    // 至少等 2 秒再执行任务
    setTimeout(collector, (2 + task.waitDuration) * 1000, task);
  } else {
    console.log("@任务已完成!");
    alert("任务完成!");
  }
};

(() => {
  // 获取基础信息
  Promise.all([
    request("cakebaker_getHomeData"),
    // 请求稍微慢点,避免提示【点太快啦!等下再来吧】
    new Promise((resolve) => {
      setTimeout(() => {
        request("cakebaker_getTaskDetail").then(resolve);
      }, 1000);
    }),
  ])
    .then(([homeData, taskData]) =>
      Promise.all([homeData.json(), taskData.json()])
    )
    .then(([homeData, taskData]) => {
      // 如果无法获取任务详情
      if (taskData.data.bizCode !== 0) {
        if (
          taskData.data.bizCode === -7 &&
          !~navigator.userAgent.indexOf("jdapp")
        ) {
          console.log("当前浏览器 UA:" + navigator.userAgent);
          throw "任务详情获取失败,请确保已设置正确的浏览器 User-Agent。";
        } else {
          throw `【错误信息:${JSON.stringify(taskData.data)}】`;
        }
      }

      // 获取签名 token
      secretp = homeData.data.result.cakeBakerInfo.secretp;

      // 生成任务队列
      taskData.data.result.taskVos.forEach(async (taskCollection) => {
        // 跳过部分邀请任务
        if (
          ["邀请好友助力", "所在战队成员满5人", "所在战队成员满3人", "邀人助力得80-200金币","在战队PK中拉1人助力","累计赢得五场战队PK"].includes(
            taskCollection.taskName
          )
        )
          return;

        // 针对甄选优品任务的处理
        if (taskCollection["productInfoVos"]) {
          superiorTask(taskCollection);
        }

        // 确认任务集合所在键名
        var taskCollectionContentKeyName = Object.keys(taskCollection).find(
          (keyName) =>
            /Vos?$/.test(keyName) &&
            !["productInfoVos", "scoreRuleVos"].includes(keyName)
        );

        // 某类任务下的任务集合内容
        taskCollectionContent = taskCollection[taskCollectionContentKeyName];

        if (!taskCollectionContent) return;

        Array(taskCollection.maxTimes - taskCollection.times)
          .fill(true)
          .forEach((_, index) => {
            taskList.push({
              taskName: taskCollection.taskName,
              taskId: taskCollection.taskId,
              taskType: taskCollection.taskType,
              waitDuration: taskCollection.waitDuration,
              itemId:
                taskCollectionContent instanceof Array
                  ? taskCollectionContent[index].itemId
                  : taskCollectionContent.itemId,
            });
          });
      });

      console.log(taskList);

      // 开始任务
      start();
    });
})();

from sweater.

gutianyi avatar gutianyi commented on August 22, 2024

@gutianyi

var secretp = "";
var taskList = [];

// 恢复被覆盖的 alert 函数
(() => {
  var frame = document.createElement("iframe");
  frame.style.display = "none";
  document.body.appendChild(frame);
  window.alert = frame.contentWindow.alert;
})();

// 请求函数
var request = (functionId, body = {}) =>
  fetch("https://api.m.jd.com/client.action", {
    body: `functionId=${functionId}&body=${JSON.stringify(
      body
    )}&client=wh5&clientVersion=1.0.0`,
    headers: {
      "content-type": "application/x-www-form-urlencoded",
    },
    method: "POST",
    credentials: "include",
  });

// 模拟任务完成请求
var collector = (task, actionType) => {
  console.log(actionType ? "@领取任务:" : "@执行任务:", task);

  request("cakebaker_ckCollectScore", {
    taskId: task.taskId,
    itemId: task.itemId,
    actionType: actionType ? 1 : undefined,
    safeStr: JSON.stringify({ secretp }),
  })
    .then((res) => res.json())
    .then((res) => {
      console.log("调用结果:", res.data);

      // 如果是执行任务,即任务已经完成,则进行下一个任务
      if (!actionType) {
        start();
      }
    });
};

// 甄选优品任务处理
var superiorTask = (() => {
  // 是否有请求正在执行
  var isBusy = false;

  return (rawTaskCollection) => {
    var getFeedDetail = (copiedTaskCollection) => {
      request("cakebaker_getFeedDetail", {
        taskIds: copiedTaskCollection["productInfoVos"]
          .map((item) => item.itemId)
          .toString(),
      })
        .then((res) => res.json())
        .then((res) => {
          var result = res.data.result;

          // 确认任务集合所在键名
          var taskCollectionContentKeyName = Object.keys(result).find(
            (keyName) => /Vos?$/.test(keyName) && !["taskVos"].includes(keyName)
          );

          result[taskCollectionContentKeyName].forEach((taskCollection) => {
            Array(taskCollection.maxTimes - taskCollection.times)
              .fill(true)
              .forEach((_, index) => {
                taskList.unshift({
                  taskName: taskCollection.taskName,
                  taskId: taskCollection.taskId,
                  taskType: taskCollection.taskType,
                  waitDuration: taskCollection.waitDuration,
                  itemId: taskCollection.productInfoVos[index].itemId,
                });
              });
          });

          // 解除请求锁定
          isBusy = false;
        });
    };

    if (!isBusy) {
      isBusy = true;
      getFeedDetail(JSON.parse(JSON.stringify(rawTaskCollection)));
    } else {
      // 一秒后重试
      setTimeout(
        getFeedDetail,
        1000,
        JSON.parse(JSON.stringify(rawTaskCollection))
      );
    }
  };
})();

// 开始任务
var start = () => {
  var task = taskList.pop();

  if (task) {
    // 除了小精灵和连签外的任务要先领取
    if (!["小精灵", "连签得金币"].includes(task.taskName)) {
      setTimeout(collector, 0, task, true);
    }
    // 至少等 2 秒再执行任务
    setTimeout(collector, (2 + task.waitDuration) * 1000, task);
  } else {
    console.log("@任务已完成!");
    alert("任务完成!");
  }
};

(() => {
  // 获取基础信息
  Promise.all([
    request("cakebaker_getHomeData"),
    // 请求稍微慢点,避免提示【点太快啦!等下再来吧】
    new Promise((resolve) => {
      setTimeout(() => {
        request("cakebaker_getTaskDetail").then(resolve);
      }, 1000);
    }),
  ])
    .then(([homeData, taskData]) =>
      Promise.all([homeData.json(), taskData.json()])
    )
    .then(([homeData, taskData]) => {
      // 如果无法获取任务详情
      if (taskData.data.bizCode !== 0) {
        if (
          taskData.data.bizCode === -7 &&
          !~navigator.userAgent.indexOf("jdapp")
        ) {
          console.log("当前浏览器 UA:" + navigator.userAgent);
          throw "任务详情获取失败,请确保已设置正确的浏览器 User-Agent。";
        } else {
          throw `【错误信息:${JSON.stringify(taskData.data)}】`;
        }
      }

      // 获取签名 token
      secretp = homeData.data.result.cakeBakerInfo.secretp;

      // 生成任务队列
      taskData.data.result.taskVos.forEach(async (taskCollection) => {
        // 跳过部分邀请任务
        if (
          ["邀请好友助力", "所在战队成员满5人", "所在战队成员满3人", "邀人助力得80-200金币","在战队PK中拉1人助力","累计赢得五场战队PK"].includes(
            taskCollection.taskName
          )
        )
          return;

        // 针对甄选优品任务的处理
        if (taskCollection["productInfoVos"]) {
          superiorTask(taskCollection);
        }

        // 确认任务集合所在键名
        var taskCollectionContentKeyName = Object.keys(taskCollection).find(
          (keyName) =>
            /Vos?$/.test(keyName) &&
            !["productInfoVos", "scoreRuleVos"].includes(keyName)
        );

        // 某类任务下的任务集合内容
        taskCollectionContent = taskCollection[taskCollectionContentKeyName];

        if (!taskCollectionContent) return;

        Array(taskCollection.maxTimes - taskCollection.times)
          .fill(true)
          .forEach((_, index) => {
            taskList.push({
              taskName: taskCollection.taskName,
              taskId: taskCollection.taskId,
              taskType: taskCollection.taskType,
              waitDuration: taskCollection.waitDuration,
              itemId:
                taskCollectionContent instanceof Array
                  ? taskCollectionContent[index].itemId
                  : taskCollectionContent.itemId,
            });
          });
      });

      console.log(taskList);

      // 开始任务
      start();
    });
})();

感谢 嘿嘿嘿

from sweater.

zarkin404 avatar zarkin404 commented on August 22, 2024

你们的代码不是最新的,其实在 这里 再加个正则分组就能改的。

from sweater.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.