青年大学习自动完成

前言

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

步骤

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

命令

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 语句可以实现每周自动执行命令

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

cron examples

posted @ 2023-02-21 12:39  LiamYe  阅读(497)  评论(1)    收藏  举报