2
头图

It has been more than 3 months since the last article on the year-end summary. In the year-end summary, I wrote about the topic of using scripts to automatically harvest wool. Many friends in the comments are more interested. So, today I will introduce to you in detail how to make technology create value (you have to raise the wool to a higher level). There is no technical difficulty in this article, even a technical novice can easily get started.

In order to retain users and increase daily and monthly activity, various APPs in mobile phones will basically launch activities such as sign-in and gift exchange. Next, I will take the Dingdong grocery shopping APP that I often used before as an example, and teach you step by step to walk towards the bright road of scouring wool.

initial preparation work

  1. Packet capture tool (such as charles)
  2. node environment
  3. Tencent cloud account

packet capture

How to realize the packet capture of the request on the mobile phone, I have introduced in this article charles packet capture , friends who don't know can read this article first, this article will not introduce too much. After configuring the proxy, the next step is the key link.

Analyze request url and parameters

First we need to find the actual request corresponding to an action url . Take the sign-in function of Dingdong grocery shopping as an example, click to sign-in, you will catch a lot of requests, you can see at a glance from the name which one we want url is.

image.png

From the figure above, you can see the requested url , header and the returned response. With these things in hand, we can start writing programs.

Writing specific code

node Send ajax There are many libraries requested, here we choose the familiar axios .

First let's construct header :

 const SIGN_IN_HEADER = {
    "Accept": "*/*",
    "Accept-Encoding": "gzip, deflate, br",
    "Accept-Language": "zh-cn",
    "Connection": "keep-alive",
    "Content-Type": "application/x-www-form-urlencoded",
    "ddmc-api-version": "9.7.3",
    "ddmc-build-version": "9.48.1",
    "ddmc-app-client-id": "13",
    "ddmc-station-id": "5f1378ce93e0310001d3609e",
    "origin": "https://activity.m.ddxq.mobi",
    "Referer": "https://activity.m.ddxq.mobi/",
    "Cookie": 'xxxxxxxxxxxxxx',
    "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 xzone/9.48.1 station_id/5f1378ce93e0310001d3609e'
}

Next is the form submitted data information:

 const POST_DATA = {
    "api_version": 9.1,
    "station_id": "5f1378ce93e0310001d3609e",
    "latitude": "40.050802",
    "longitude": "116.413449"
}

With header and data , the request can be sent.

 const SIGN_IN_URL = 'https://sunquan.api.ddxq.mobi/api/v2/user/signin/';

axios.post(SIGN_IN_URL, {
    data: POST_DATA
}, {
    headers: SIGN_IN_HEADER
}).then(res => {
    console.log(res.data, 'success');
}).catch(err => {
    console.log(err, 'error');
});

Running the above code prints the following information on the console:

image.png

It can be seen that it is consistent with the returned information in our packet capture screenshot above, and you are done.

After the above steps, it has been possible to use the program to solve the problem of sign-in. There are also some other tasks in Dingdong Shopping, such as a small game of raising fish. You can exchange grass carp by doing tasks and feeding every day. The specific task implementation steps are the same, so I won't introduce too much here.

The above program needs to be run manually every day and requires human participation. How can we be satisfied with this, the program has grown up, and we have to learn to run by ourselves. Next, Tencent Cloud Functions will debut.

Tencent Cloud functions are automatically executed

The official address of Tencent Cloud Function is here .

new function

After entering, select the function service -> you can manually select a region near you -> create a new one.

image.png

Then choose to start from scratch, you can give a name with a logo, for example, I called it here dingdong , and then select the operating environment node12.16 , the higher version node no I know if there is any bug, the asynchronous request does not seem to be sent, and the printed information cannot be seen in the log (it caused me to toss for a long time, obviously it can be done locally, but not deployed).

image.png

The function code submission method selects the local upload folder, and the execution method does not need to be modified. The execution method indicates which function in which file needs to be executed when calling the cloud function. Here index.main_handler in index represents a file entry for the executed index.js , main_handler represented entry function is executed main_handler . Therefore, you need to create a index.js file in the local root directory.

Entry index.js File:

 'use strict';
exports.main_handler = async (event, context) => {
    //需要加上这个,解决热启动问题
    delete require.cache[require.resolve('./src/sign.js')];
    require('./src/sign.js');
};

Then upload the entire folder.

image.png

Don't worry about the next advanced configuration and trigger configuration, just click Create to generate the cloud function.

deploy

Then go to Function Management -> Function Code, you can see all the contents of the folder we just uploaded (the content of the new version of cloud function above 10M only displays the entry file). Click Deploy, and our code is deployed to the cloud server.

image.png

Click Test, you can test and debug online, and you can see the printed information in the log query.

image.png

Timer configuration

Note down the configuration of the timer.
The entry is in trigger management in function management.

image.png

After entering, choose to create a trigger. The trigger period has several set values. If you don't like it, you can choose a custom trigger period. For the setting of Cron expression, please refer to here . There are a total of 7 fields, representing seconds, minutes, hours, days, months, weeks, and years. What the picture represents is that it will be automatically triggered once every day at 8:13:14.

image.png

If you are in a hurry to test, you can create a new trigger and choose to execute it every minute, so that you can see the effect without waiting much. But don't forget to turn off the timer after the test, my dollar is wasted like this.

Next, you don't need to worry about it anymore, the cloud function will be automatically executed at the set time. All we need to do is to come back and take a look occasionally. If today's task is not successfully executed, the probability is that cookie has expired, and then grab the packet and get it cookie Replace it.

Well, this is the end of the tutorial on shaving wool. You can take a look at your favorite apps and websites, and fiddle with it when you have nothing to do.

suggestion

Picking up wool is not easy, everyone pick it up and cherish it. Maybe one day the platform will change the rules or lock you in a small dark room, but it's not bad for me.


阳呀呀
2.2k 声望2.7k 粉丝