following content is from the original article of "Playing with Tencent Cloud" and has been authorized.

<img src="https://z3.ax1x.com/2021/06/30/RDauGD.png" width="700"/>

Recently, I saw a lot of people running away, so I wanted to benefit myself, and I wanted to automatically greet HR in a certain recruitment software. Since it is really a waste to buy a server with a separate corntab, so I chose cloud functions. After all, cloud functions The free quota is enough.

WJqPMQ.md.png

So, let's get started!

01. Scripting

I use Node.js for writing, and there are three files in total:

  • common.js stores public head parameters, and public methods
  • request.js is used to request the interface
  • index.js is the file used for trigger configuration operation of cloud functions

The code is nothing, it is a request interface with parameters, public parameters, mainly the header of the configuration request;

const headers = {
  'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36 MicroMessenger/7.0.9.501 NetType/WIFI MiniProgramEnv/Windows WindowsWechat',
  'content-type': 'application/x-www-form-urlencoded',
  mpt: '',
  platform: '',
  scene: '',
  ua: '{"model":"microsoft"}',
  v: '',
  ver: '',
  wt2: '',
  zpAppId: '',
  Referer: '',
  'Accept-Encoding': 'gzip, deflate, br'
}

function sleep (delay) {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve()
    }, delay)
  })
}

exports.headers = headers

exports.sleep = sleep

The interface request is mainly to obtain the job list of the specified city first, and then say hello one by one;

const got = require('got')
const fs = require('fs')
const { headers, sleep } = require('./common')

function getJobList(page = 1) {
  return got('自己去抓包哦', {
    method: 'GET',
    headers,
    searchParams: {
      appId: 10002,
      expectId: 185008765,
      sortType: 1,
      cityCode: 101020100,
      districtCode: '',
      businessCode: '',
      subwayLineId: '',
      subwayStationId: '',
      page: page,
      pageSize: 10,
      salary: '',
      degree: '',
      experience: '',
      stage: '',
      scale: '',
      industry: '',
      longitude: '',
      latitude: '',
      positionCode: ''
    }
  })
}

function addJob(jobId, lid, securityId) {
  const body = {
    appId: '',
    jobId: jobId,
    lid: lid,
    securityId: securityId
  }
  return got('自己去抓包哦', {
    method: 'POST',
    headers,
    body: new URLSearchParams(body).toString()
  }).then(res => {
    console.log(res.body)
    return res
  })
}

async function main () {
  try {
    let jobList = []
    for (let i = 1;;i++) {
      const res = await getJobList(i)
      const data = JSON.parse(res.body)
      jobList.push(...data.zpData.jobList)
      if (!data.zpData.hasMore) {
        break
      }
    }
    const asyncArr = []
    jobList.forEach(async job => {
      console.log(job.jobName)
      asyncArr.push(addJob(job.encryptJobId, job.lid, job.securityId))
    })
    Promise.all(asyncArr)
  } catch (error) {
    console.log(error)
  }
}

main()

Then it is the main function to obtain the additional information in the trigger, and call the specified file by obtaining the file name written in the additional information, because I still have a resume file, so I have to distinguish it;

'use strict';
exports.main_handler = async (event, context, callback) => {
  for (const v of event["Message"].split("\r\n")) {
    console.log(v);
    require(`./${v}.js`)
  }
}

02. Create a cloud function

  1. Direct home page search cloud function

WJqirj.md.png

  1. Enter cloud function console

WJqFqs.md.png

  1. To create a cloud function, select custom creation as the creation method, Node.js as the operating environment, and directly select the upload folder for the function code, which is convenient and quick. Just select and upload our code folder directly;

WJqSG8.md.png

  • Note: The timeout period here can be set longer, after all, it is an interface request, it still takes some time, if it is set less, it will be broken before the request is completed;

WJbvIP.md.png

  1. Next, configure the trigger and select the timing trigger. We can choose some time points when it is hard to write, such as every minute, every day, etc., or you can use a custom trigger cycle and configure your own cron expression, such as nine o'clock every night That is 0 0 9 * * * * ;
  2. Finally, select for additional information, and then write the name of the file we want to run, which is request

WJbXVI.md.png

WJq9xg.md.png

  1. Click "Finish" to create the cloud function, and then we can view our cloud function in the list, enter the details, or modify the code and deploy.

03. Effect display

WJqDeA.png

WJbzPf.png

Web Function Experience Officer Recruitment Order

Surprise benefits are full, click to view event details

<img src="https://main.qcloudimg.com/raw/545c2c8589959c675b8c501e8b41e363.png" width="700"/>

Web Function experience

It has been released and launched in all major regions of the country. Welcome to experience and use it!

<img src="https://main.qcloudimg.com/raw/4ee70db1b518d4c0064711d1caf1572c.jpg" width="700"/>


One More Thing

Experience Tencent Cloud Serverless Demo now and receive the Serverless New User Gift Pack 👉 Tencent Cloud Serverless Newbie Experience .


Serverless
127 声望15 粉丝

Serverless 中文社区是由一群拥有相同价值观和理念的志愿者们共同发起,于 2019 年 12 月正式成立。