爱意满满的作品展示区。
SimonOne

写了个 surge 脚本, hifini 自动定时签到

  •  
  •   SimonOne · May 13, 2024 · 2829 views
    This topic created in 761 days ago, the information mentioned may be changed or developed.

    不懂 js 的苦手写的难受死了(其实除了 abap 别的也不会)。

    花了一晚上,主要时间浪费在“网络请求是异步的,必须等到前一个函数获取 sign 后才能开始下一个函数签到”,但是我没有用 js 异步的经验,一直在 google 怎么样能让上一个函数异步完成拿到 sign 后再签到。

    贴出来给大家看下,要是有大哥能帮忙优化下就更好了。😆

    const jobName = "hifini.com 签到"
    const cookie = $persistentStore.read("hifiniDailyBonusCookie")
    const recentSignDate = $persistentStore.read("hifiniDailyBonusRecentSignDate")
    const today = new Date()
    const month = today.getMonth() + 1
    const signDate = `${today.getFullYear()}${month}${today.getDate()}`
    
    // 获取 sign
    function hifiniGetSign() {
      return new Promise(resolve => {
        console.log("获取签到的 sign")
        // 获取签到的 sign
        const request = {
          url: "https://www.hifini.com/",
          headers: {
            "Cookie": cookie,
            "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"
          }
        }
        $httpClient.get(request, (error, response, data) => {
          console.log("发送请求")
          if (response.status == 200) {
            var regex = /var sign = \"(\w+)";/
            var match = regex.exec(data);
            if (match !== null) {
              var sign = match[1]
              console.log(`已取得 sign=${sign}`)
              resolve(sign)
            } else {
              console.log(`未通过正则表达式${regex}找到匹配的 sign`)
              $done()
            }
          } else {
            console.log(`获取 sign 失败,返回码${response.status}`)
            $done()
          }
        })
      })
    }
    
    // 签到
    function hifiniSign(sign) {
      if (signDate !== recentSignDate) {
        console.log("本机今天尚未签到,开始签到请求")
        const request = {
          url: "https://www.hifini.com/sg_sign.htm",
          headers: {
            "Accept-Language": "zh-Hans,zh-CN;q=0.9,zh;q=0.8",
            "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
            "Cookie": cookie,
            "x-requested-with": "XMLHttpRequest",
            "Referer": "https://www.hifini.com/",
            "Sec-Ch-Ua": "\"Chromium\";v=\"124\", \"Google Chrome\";v=\"124\", \"Not-A.Brand\";v=\"99\"",
            "Sec-Ch-Ua-Mobile": "?0",
            "Sec-Ch-Ua-Platform": "\"macOS\"",
            "Sec-Fetch-Dest": "empty",
            "Sec-Fetch-Mode": "cors",
            "Sec-Fetch-Site": "same-origin",
            "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"
          },
          body: `sign=${sign}`
        }
        $httpClient.post(request, (error, response, data) => {
          console.log("发送签到请求")
          if (response.status == 200) {
            if (data == null) {
              console.log("请求成功,返回空")
              const title = jobName
              const subTitle = "请求成功,返回空,检查下"
              $notification.post(title, subTitle, "")
            } else {
              if (JSON.parse(data).code == 0) {
                const title = jobName
                const subTitle = "签到成功"
                const detail = JSON.parse(data).message
                console.log(detail)
                $persistentStore.write(signDate, "hifiniDailyBonusRecentSignDate")
                $notification.post(title, subTitle, detail)
              } else if (JSON.parse(data).code == -1) {
                const title = jobName
                const subTitle = "签到跳过"
                const detail = JSON.parse(data).message
                console.log(detail)
                $persistentStore.write(signDate, "hifiniDailyBonusRecentSignDate")
                $notification.post(title, subTitle, detail)
              } else {
                const title = jobName
                const subTitle = "签到失败"
                console.log(detail)
                const detail = `error: ${error}, response: ${response}, data: ${data}`
                $notification.post(title, subTitle, detail)
              }
            }
          } else {
            console.log(`请求失败,返回码${response.status}`)
            const title = jobName
            const subTitle = `请求失败,返回码${response.status}`
            $notification.post(title, subTitle, "")
          }
          $done()
        })
      } else {
        console.log("今天已经签过")
        const title = jobName
        const subTitle = "签到跳过"
        const detail = "今天已经签过啦!"
        $notification.post(title, subTitle, detail)
        $done()
      }
    }
    
    hifiniGetSign().then(sign => {
      hifiniSign(sign)
    })
    
    5 replies    2025-07-09 22:42:08 +08:00
    RangerWolf
        1
    RangerWolf  
       May 14, 2024   ❤️ 1
    脚本没用上,但是发现了一个宝藏网站,感谢 op
    jpyl0423
        2
    jpyl0423  
       May 14, 2024
    我本来想用 python 写一个放到青龙面板的,太懒一直没写,直接用 lz 的吧
    blankmiss
        3
    blankmiss  
       May 14, 2024
    有验证码 模拟登录 很麻烦
    SimonOne
        4
    SimonOne  
    OP
       May 14, 2024
    @blankmiss #3 😂所以改成半自动的,登录上了,拿到 cookie ,偶尔 cookie 失效了就再手动取下。
    ambroserencn
        5
    ambroserencn  
       Jul 9, 2025
    网站闭站了,心痛!我还有钱在里面呢……
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3066 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 238ms · UTC 07:13 · PVG 15:13 · LAX 00:13 · JFK 03:13
    ♥ Do have faith in what you're doing.