In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to use node scripts to achieve automatic check-in and lottery functions. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
I. Preface
Since the launch of the check-in activity, the Nuggets have been constantly improving this function, and now the ore can be raffled and exchanged for items (simply not too cool! ✧ *. The landlord himself has been using Nuggets a long time ago (before the Nuggets check-in function comes out), but I am lazy enough to lead to intermittent signing-in, so I can only watch others exchange prizes (envy and jealousy), and now the minerals have not been used (mainly try their luck) ✧. Just not long ago, bloggers who read some Nuggets posted articles related to automatic check-in, and felt that this was a good idea, so taking advantage of New Year's Day's good support, because he recently bought a cheap Tencent Cloud server and I am a front-end veteran cabbage, I decided to use CVM and node regular script to realize the automatic check-in lottery function. After deciding the direction, I started to check the article, so I searched the keywords of automatic check-in directly, started to read the articles one by one, and then started to realize it on my own. No more nonsense, and then let's see how to realize the automatic check-in lottery.
2. Preparation
Server
Read a lot of articles, basically using a request package and timing task trigger package to achieve, look at the useful oil monkey script, cloud function, node script, basically covered. But no matter what you use, the ideas and interfaces are the same, so this article is based on a CVM, which requires a CVM or a networked 24-hour computer without shutdown.
Node environment
There is no need to say much about this. The installation of the node environment is available on the Internet, but everyone must have installed it. Tidy up the environment and begin to build the project.
Third, script engineering construction
Create a folder and write down the project name (any name ("▽") /)
Then open the dos window (cmd) under the folder, or open the folder with VsCode
Type npm init in the window, then enter all the way to generate the package.json file.
Then prepare two packages here, one is axios, the other is node-schedule, and install them as follows:
Npm i axiosnpm i node-schedule
After the installation is completed, it is shown below.
Then create new index.js and config.js files in the root directory for code and parameter writing
At this point, the project file for the entire node script is built, and then the code is written.
IV. Code writing & running
First extract the parameters used into a file (config.js)
/ / config.js// query whether you have successfully checked in today's API https://api.juejin.cn/growth_api/v1/get_today_statusmodule.exports = {/ / Nuggets related parameters nuggets: {signInUrl: `https://api.juejin.cn/growth_api/v1/check_in`, / / check-in API freeCheckUrl: `https://api.juejin.cn/growth_api/v1/lottery_config/get`, / / query the number of free raffles drawUrl: `raffle / / API headers: {Referer: "https://juejin.cn/"," Upgrade-Insecure-Requests ": 1," User-Agent ":" Mozilla/5.0 (Windows NT 10.0) WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36 ", cookie: `fill in your own cookie here, log in to the Nuggets web page, open the console network, and find any request. Just check the cookie in the request header and copy it, / / use your own}, / / relevant request header}, / / parameters related to message push follow pushplus Wechat official account to obtain one-to-one push call parameters, instead of promoting pushPlus: {url: `http://www.pushplus.plus/send`, / / Wechat push URL token:` this is the token obtained in pushplus Follow the official account, then open the official website to find one-on-one push, and you can get token. / / there is no advertisement, this is free}}.
The contents that need to be modified in this file are mainly cookie and token, which are used for Nuggets API request and wx message push respectively. If you do not need to use wx message push, you can simply add a line of return; to the first line of the pushMsg function.
Here, cookie directly logs in to the PC Nuggets, press F12 to open the console, go to network, and then click some interactions on the page to capture the request, then find the cookie in it and copy it, as shown in the following figure.
The token acquisition method of wx message push directly searches the official account of pushplus on wx, then activates the message push after following, and then goes to the official website to get token and add it to the file (this is not an advertisement! Read the boss blog to learn from, or quite useful ─━ _ ─━✧).
Finally, the code is written (index.js)
Here is a brief excerpt of the part, the whole code is put on too much, mainly put on the part of check-in and timing tasks
/ / package file const axios = require ("axios"); const schedule = require ("node-schedule"); / / relevant parameters are saved in the file const {nuggets, pushPlus} = require (". / config"); / * * get the format time of the current time * @ param {String} key call js date function numeric string * @ returns current time formatted string * / const getNowTime = (key) = > {let nowTime = `` Try {nowTime = new Date () [key] ();} catch (e) {nowTime = `error getting time function! `; console.error (`Please pass in the date function-- ${e}`);} return nowTime;} / * * Nuggets automatic check-in request method * / const hacpaiSignRequest = async () = > {console.log (`\ n\ nLay ${getNowTime (`toLocaleDateString`)}-start check-in); const {headers, signInUrl} = nuggets / / check-in related parameters const res = await axios ({url: signInUrl, method: `post`, headers,}); if (res & & res.data) {let jsonMsg = JSON.stringify (res.data); console.log (`\ n ${jsonMsg}\ n-${getNowTime (`toLocaleTimeString`)} check in successfully -\ n`); pushMsg (`Nuggets check-in result`, res.data) / / push message after successful check-in / / after successful check-in, query the number of free raffles setTimeout (() = > {freeCheck ();}, Math.random () * 30 * 1000)} else {console.log (res); console.log (`\ n-${getNowTime (`toLocaleTimeString`)} check-in failed -\ n`) PushMsg (`check-in result `, {'check-in failed': res.data}); / / push message}} / / scheduled trigger task const signTask = () = > {/ / Random check-in to schedule.scheduleJob between 6:00 and 6:10 every day ("00 6 *", () = > {setTimeout (() = > {hacpaiSignRequest ()) / / check-in function}, Math.random () * 10 * 60 * 1000)} / / start task console.log (`start task-${getNowTime ('toLocaleString')} `); signTask ()
The code here can not be used directly, because some functions have not been put on it. The main logic here is to check in-"query the number of free lottery draws -". This process is triggered randomly at any time between 6:00 and 6:10 every day. The code is easy to write, mainly straighten out the requirements logic, and then find the relevant interface, and finally, no matter what request packet is used, as long as the http request can complete these functions.
Finally, type node index.js into the cmd window to execute the code, and then keep it running in a stable environment (I just throw the server "(" ❛ "❛)).
On "how to use node script to achieve automatic check-in and lottery function" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.