“This is the first day of my participation in the First Challenge 2022. For details: First Challenge 2022”

As a front-end, I use JS a lot, but I have never written scripts, post bar automatic check-ins and mining automatic check-ins are fork someone else’s repository code, in the attitude of learning, I also want to write a manual about automatic mining, for what purpose to write this, I can only say I learned how to use nodeJs.

The complete code

The project address

Set up the environment

I previously wrote a post on how to unlock Seabed Mining by cracking my Love, about how mining requires two authentication parameters, token and UUID,

Then I changed it here to gold mining cookies and mining tokens

So in nodeJs, we need to configure environment variables, which rely on the package dotenv

"Dependencies" : {" axios ":" ^ 0.24.0 ", / / HTTP request need "dotenv" : "^" 10.0.0, / / environment variable configuration depends on "express" : "^ 4.17.2 jsonwebtoken", ""," ^ 8.5.1 "/ / x - game - the encryption method id},Copy the code

Create a project

npm init
Copy the code

Install dependencies

npm install

npm install axios dotenv express jsonwebtoken

Copy the code

Create folders and js

The file structure of the project is shown below

function

Sign-in and raffle

Analysis:

  1. Determines whether the cookie exists
  2. Sign in
  3. After successful sign-in, a free lucky draw
  4. Happy, no need to sign in, once a day

code

if(! COOKIE) {message(' Could not get COOKIE, Check Settings ')} else {async function junJin() {try {// checkIn, draw and await juejinapi.checkin (); Const drawResult = await juejinapi.drawapi (); const dipParams = { lottery_history_id: '7052109119238438925' }; const dipResult = await jueJinApi.dipLucky(dipParams); ${drawresult. lottery_name}; ${dipresult.total_value} '); } catch (e) {message(' there is an exception, please manually,${e.message} '); } } junJin().then(() => {}); }Copy the code

The reason for using a try catch is that we are asynchral with multiple await objects and need to catch exception handling information.

es6.ruanyifeng.com/#docs/async

Seafloor mining

Analysis of the

  • Obtain the UUID, required
  • The ore upper limit of the day and the actual ore acquired on the day
  • To start the game, choose Role 3
  • Initiate instructions, where there is a fixed JSON execution step
  • End the game and get the current position, the depth reached
  • If not more than 500 meters, change the map and proceed to the next step
  • If the actual ore obtained on the day of ore acquisition and the upper limit of ore on the day are not exceeded, repeat the above steps

Note: frequent calls to the interface will be limited by the server, and it will take about 10 minutes to call the interface again

So I added a sleep code

// Pause to avoid quick and frequent requests

async function sleep(delay) {

  return new Promise(((resolve) => setTimeout(resolve, delay)));
  
}
Copy the code

X – game – id access

This can be viewed on the seafloor mining page by breaking points

function getXGameId(id) {
  const time = +new Date().getTime();
  return jwt.sign(
    {
      gameId: id,
      time: time,
      // eslint-disable-next-line max-len
    },
    "-----BEGIN EC PARAMETERS-----\nBggqhkjOPQMBBw==\n-----END EC PARAMETERS-----\n-----BEGIN EC PRIVATE KEY-----\nMHcCAQEEIDB7KMVQd+eeKt7AwDMMUaT7DE3Sl0Mto3LEojnEkRiAoAoGCCqGSM49\nAwEHoUQDQgAEEkViJDU8lYJUenS6IxPlvFJtUCDNF0c/ F/cX07KCweC4Q/nOKsoU\nnYJsb4O8lMqNXaI1j16OmXk9CkcQQXbzfg==\n-----END EC PRIVATE KEY-----\n",
    {
      algorithm: "ES256".expiresIn: 2592e3.header: {
        alg: "ES256".typ: "JWT",}}); }Copy the code

WeChat notice

Here we use server sauce wechat push message

Making the Action deployment

1. Fork code

2. Fill in cookies and tokens. If you need to push messages, fill in the ID of the server sauce

3. Action runs

Operation of the

After a few days of testing, the situation is ok