It has been more than 3 months since the last year-end summary. In the year-end summary, I wrote about the topic of using scripts to automatically collect wool. Many partners were interested in the comments. So, today will give you a detailed introduction to how to make technology create value (to a higher level of wool). There are no technical difficulties in this paper, even the technical white can easily start.

In order to retain users and increase daily and monthly live volume, various apps in mobile phones will basically launch activities such as check-in and gift exchange. Next, I will take the ding Dong shopping APP I often used before for example, teach you step by step to the bright road of collecting wool.

Preparatory work

  1. Package capture tools (such as Charles)
  2. The node environment
  3. Tencent Cloud Account

caught

How to realize the packet capture of the mobile terminal request, I have introduced in this article Charles packet capture. If you do not know this article, you can have a look at it first. This article will not introduce too much. With the proxy configured, it’s time to focus.

Analyze the request URL and parameters

First we need to find the actual request URL for an action. Take the check-in function of Ding Dong Maicai for example, click to check in, you will catch many requests, and you can see which URL we want at a glance from the name.

You can see the URL of the request, the header, and the returned response in the figure above. With these things, we can start writing programs.

Specific code writing

There are many libraries on the Node side that send Ajax requests, and we’ll use the familiar axios here.

Let’s first construct the 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 - the client - id" : "13", "DDMC - station - id" : "5f1378ce93e0310001d3609e", "origin": "https://activity.m.ddxq.mobi", "Referer": "Https://activity.m.ddxq.mobi/", "Cookie" : "XXXXXXXXXXXXXX", "the user-agent:" 'the Mozilla / 5.0 (iPhone; CPU iPhone OS 14_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, Like Gecko) Mobile / 15 e148 xzone / 9.48.1 station_id / 5 f1378ce93e0310001d3609e '}Copy the code

Here is the data for the form submission:

Const POST_DATA = {" API_version ": 9.1, "station_id": "5F1378CE93e0310001d3609e ", "latitude": "40.050802", "longitude": "116.413449"}Copy the code

With the header and data, you’re ready to send the request.

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');
});
Copy the code

Run the code above and print the following information on the console:

It can be seen that the return information is consistent with that in the packet capture screenshot above.

After the above steps, it is possible to use the program to solve the problem of check-in. Ding Dong buy vegetables and some other tasks, such as fish farming games, every day to do task feeding can change grass carp, so far has been white piao several. The specific task implementation steps are the same, I will not do too much introduction here.

The above procedure needs to be run manually every day, requires human participation. How can we be satisfied with this when we have aspirations? Programs have grown up and have to learn to run on their own. Next, let’s welcome Tencent cloud function.

Tencent cloud function automatically executed

Tencent cloud function official address here.

The new function

Enter the function service -> manually select a region near you -> New.

Node12.16, node12.16, node12.16, node12.16, node12.16, node12.16, node12.16, node12.16 Deployment just doesn’t work).

The local upload folder is selected for the submission of function code. The execution method does not need to be modified. The execution method indicates the function in which file to start the execution when calling the cloud function. In index.main_handler, index indicates that the entry file is index.js, and main_handler indicates that the entry function is main_handler. Therefore, you need to create an index.js file in the local root directory.

Entry index.js file:

'use strict'; Exports.main_handler = async (event, context) => {// need to add this, Delete require.cache[require.resolve('./ SRC /sign.js')]; delete require.cache[require.resolve('./ SRC /sign.js')]; require('./src/sign.js'); };Copy the code

Then upload the entire folder.

Forget about the advanced configuration and trigger configuration, just click Create to generate the cloud function.

The deployment of

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

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

Timer Configuration

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

After entering, select create trigger, trigger period has several set values, if you do not like to choose custom trigger period. See here to set up Cron expressions. There are seven fields representing seconds, minutes, hours, days, months, weeks, and years. This means that it will automatically trigger once every day at 8:13:14.

If you’re in a hurry to test, you can create a new trigger and execute it every minute so you don’t have to wait much. But be sure to turn the timer off after the test, because that’s how my dollar went down the drain.

Then you basically don’t have to worry about it, the cloud function will automatically execute at the set time. What we need to do is to take a look at it once in a while. If today’s task is not successfully executed, there is a high probability that the cookie has expired, and then we can capture the packet to obtain the cookie replacement.

Well, that’s the end of the wool pulling lesson. You can look at your favorite apps and websites and do a little tinkering when you don’t have a problem.

advice

It’s not easy to pull wool, and you can pull it and cherish it, and maybe the scales will change their rules or lock you up in a dark room, not for me.