撸毛笔记-zippo会员中心(青龙脚本教程)

/*
微信小程序 zippo会员中心
以下都以青龙或nodejs环境为准

下面一行是建议定时,青龙拉库会自动读取
cron: 24 7,19 * * *
*/
/*
const和let的区别:
用const定义的变量以后不能再更改
用let定义的变量可以改
进阶内容: const 对象本身不可更改,但是对象里面的属性可以改,与指针有关
*/

const $ = new Env('微信小程序') //青龙拉库会把 new Env('qwerty') 里面的名字qwerty作为定时任务名
const got = require('got') //青龙发包依赖

const env_name = 'zippoCookie' //环境变量名字
const env = process.env[env_name] || '' //或 process.env.zippoCookie, node读取变量方法. 后面的 || 表示如果前面结果为false或者空字符串或者null或者undifined, 就取后面的值

//got的基本用法, 封装一下方便之后直接调用, 新手可以不动他直接用就行
async function request(opt) {
    const DEFAULT_RETRY = 3 //请求出错重试三次
    var resp = null, count = 0
    var fn = opt.fn || opt.url
    opt.method = opt?.method?.toUpperCase() || 'GET'
    while (count++ < DEFAULT_RETRY) {
        try {
            var err = null
            const errcodes = ['ECONNRESET', 'EADDRINUSE', 'ENOTFOUND', &#

你可能感兴趣的:(青龙脚本,笔记)