


Using node.js to implement Douyin's automatic red envelope grabbing function
This article mainly introduces the use of adb shell and node.js to realize the automatic red envelope grabbing function of Douyin. It is very good and has reference value. Friends in need can refer to it.
The logic is very simple, in Douyin After the audio and video is played, if it is a red envelope video, a red envelope will pop up. Our simulation logic is as follows:
Click the center of the screen. If there is a red envelope, open the red envelope. If there is no red envelope, the video will be paused.
Click the return button. If there is a red envelope, close the red envelope interface. If there is no red envelope, press it again to exit (it does not actually exit).
Swipe up to enter the next video.
Click, return, and slide up, just three steps. It works regardless of whether there is a red envelope or not, as long as you calculate the time.
Code
The following is a piece of node.js code:
touch.js
var process = require('child_process'); function exec(shell) { process.exec(shell,function (error, stdout, stderr) { if (error !== null) { console.log('exec error: ' + error); } }); } function click() { console.log('click') exec(`adb shell input tap 400 600`) setTimeout(back, 1000) } function swipe() { console.log('swipe') exec(`adb shell input swipe 400 800 400 0 500`) setTimeout(click, 20000) } function back() { console.log('back') exec(`adb shell input keyevent 4`) setTimeout(swipe, 1000) } swipe()
Open In the developer mode of the phone, enable USB debugging. If it is Xiaomi, please also enable USB debugging (security settings). Connect your phone and open the main interface of Douyin. Save this js locally and execute it using node.
$ node touch.js
If you find that Douyin slides up every 20 seconds, it means it is successful~
Principle
Similar to using adb There are also articles about using shell to operate mobile phones, such as operating jumps and so on. The principle is explained below.
child_process.exec(command[, options][, callback])
The function of this method is to spawn a shell, then execute the command in the shell, and buffer any generated output. For details, please refer to the reference document. In fact, it is equivalent to executing scripts and shell commands. We use it to execute adb shell commands.
adb shell
adb is a development tool for connecting a computer to a mobile phone. All computer operations on the mobile phone are actually completed by adb, including various There is also a mobile phone assistant that helps you install APPs. PS: I have been working on mobile phones for so long, and I just discovered this interesting function today... Sigh...
adb shell can install apk, view mobile phone information, operate mobile phone files, simulate click behaviors and other functions, it is very powerful . Our main purpose here is to simulate the click behavior of adb shell input. The functions are listed below:
// 输入文本 content $ adb shell input text “hello” // 点击返回按钮 keynumber $ adb shell input keyevent 4 // 点击屏幕某个点 x y $ adb shell input tap 400 400 // 滑动 x1 y1 x2 y2 time $ adb shell input swipe 400 800 400 0 500 // 下面三个不太清楚,再研究 $ adb shell input press $ adb shell input roll $ adb shell input tmode
For more key corresponding values, you can see the corresponding values of Android keyevent. Through these commands, we can perform some simple operations on the mobile phone~
Finally
This is actually a very simple logic, but it gives me a lot of inspiration. If there are any simple operations in the future, I can use adb and node to repeat them~Finally, I will complain: Shake The red envelopes for Yin are really small. I spent 3 hours yesterday and only paid a few cents, which is not enough for the electricity bill. Just treat it as entertainment~
PS: The following introduces the values corresponding to Android keyevent
Each value in Android keyevent is used when using adb shell Used when input.
KEYCODE_UNKNOWN=0; KEYCODE_SOFT_LEFT=1; KEYCODE_SOFT_RIGHT=2; KEYCODE_HOME=3; KEYCODE_BACK=4; KEYCODE_CALL=5; KEYCODE_ENDCALL=6; KEYCODE_0=7; KEYCODE_1=8; KEYCODE_2=9; KEYCODE_3=10; KEYCODE_4=11; KEYCODE_5=12; KEYCODE_6=13; KEYCODE_7=14; KEYCODE_8=15; KEYCODE_9=16; KEYCODE_STAR=17; KEYCODE_POUND=18; KEYCODE_DPAD_UP=19; KEYCODE_DPAD_DOWN=20; KEYCODE_DPAD_LEFT=21; KEYCODE_DPAD_RIGHT=22; KEYCODE_DPAD_CENTER=23; KEYCODE_VOLUME_UP=24; KEYCODE_VOLUME_DOWN=25; KEYCODE_POWER=26; KEYCODE_CAMERA=27; KEYCODE_CLEAR=28; KEYCODE_A=29; KEYCODE_B=30; KEYCODE_C=31; KEYCODE_D=32; KEYCODE_E=33; KEYCODE_F=34; KEYCODE_G=35; KEYCODE_H=36; KEYCODE_I=37; KEYCODE_J=38; KEYCODE_K=39; KEYCODE_L=40; KEYCODE_M=41; KEYCODE_N=42; KEYCODE_O=43; KEYCODE_P=44; KEYCODE_Q=45; KEYCODE_R=46; KEYCODE_S=47; KEYCODE_T=48; KEYCODE_U=49; KEYCODE_V=50; KEYCODE_W=51; KEYCODE_X=52; KEYCODE_Y=53; KEYCODE_Z=54; KEYCODE_COMMA=55; KEYCODE_PERIOD=56; KEYCODE_ALT_LEFT=57; KEYCODE_ALT_RIGHT=58; KEYCODE_SHIFT_LEFT=59; KEYCODE_SHIFT_RIGHT=60; KEYCODE_TAB=61; KEYCODE_SPACE=62; KEYCODE_SYM=63; KEYCODE_EXPLORER=64; KEYCODE_ENVELOPE=65; KEYCODE_ENTER=66; KEYCODE_DEL=67; KEYCODE_GRAVE=68; KEYCODE_MINUS=69; KEYCODE_EQUALS=70; KEYCODE_LEFT_BRACKET=71; KEYCODE_RIGHT_BRACKET=72; KEYCODE_BACKSLASH=73; KEYCODE_SEMICOLON=74; KEYCODE_APOSTROPHE=75; KEYCODE_SLASH=76; KEYCODE_AT=77; KEYCODE_NUM=78; KEYCODE_HEADSETHOOK=79; KEYCODE_FOCUS=80;//*Camera*focus KEYCODE_PLUS=81; KEYCODE_MENU=82; KEYCODE_NOTIFICATION=83; KEYCODE_SEARCH=84; KEYCODE_MEDIA_PLAY_PAUSE=85; KEYCODE_MEDIA_STOP=86; KEYCODE_MEDIA_NEXT=87; KEYCODE_MEDIA_PREVIOUS=88; KEYCODE_MEDIA_REWIND=89; KEYCODE_MEDIA_FAST_FORWARD=90; KEYCODE_MUTE=91;
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
How to implement the undo and redo function in Immutable.js (detailed tutorial)
The above is the detailed content of Using node.js to implement Douyin's automatic red envelope grabbing function. For more information, please follow other related articles on the PHP Chinese website!

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version
God-level code editing software (SublimeText3)

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download
The most popular open source editor