前言

​ 发送get请求,实现完成青年大学习(后台记录学习记录)

步骤

  • 创建一个Github Action,将代码复制到工作流
  • Get clone 本地,修改信息后pull到仓库
  • 代码中的信息,手机本地抓包青年大学习即可

命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var url="http://dxx.****.com/v1/user/commit";/打卡请求所对应url
var stage_id="22";//打卡期数
var org=[*,2***,2***,2**2];//所对应的组织
var last_org=2**2;//对应的组织的最后一项
var org_name="****团支部";//团支部名称

let msg
const checkpass = async request => {

const { name,number } = await request.json()
console.log(name,number)
const headers = { 'Content-Type': 'application/json' }
const { number } = await request.json()
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");

var raw = JSON.stringify({"stage_id":stage_id,"name":name,"tel":number,"org":org,"last_org":last_org,"org_name":org_name});

var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};

const result = await fetch(url, requestOptions)
.then(function(response) {
console.log(response)
console.log("ok")
return response.json();
})
.then(function(myJson) {
msg = myJson;

})
.catch(error => console.log('error', error));
console.log(msg)
return new Response(JSON.stringify(msg), { headers })
}
async function handleRequest(request) {
let response
if (request.method === 'POST') {
response = await checkpass(request)
} else {
response = new Response(“Error,Github@iflynews”, { headers: { 'Content-Type': 'text/html' } })
}
return response
}

addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})

定时任务

添加 schedule 语句可以实现每周自动执行命令

1
2
3
4
5
on:
schedule:
# * is a special character in YAML so you have to quote this string
- cron: '30 12 * * MON'
# 每周一 12:30执行

cron examples