2025年9月11日星期四

HiFiNi任务脚本(2025年9月版)

1.购买服务器阿里云:服务器购买地址https://t.aliyun.com/U/DT4XYh若失效,可用地址

1.购买服务器

阿里云:

服务器购买地址

https://t.aliyun.com/U/DT4XYh

若失效,可用地址

https://www.aliyun.com/activity/wuying/dj?source=5176.29345612&userCode=49hts92d

腾讯云:

https://curl.qcloud.com/wJpWmSfU

若失效,可用地址

https://cloud.tencent.com/act/cps/redirect?redirect=2446&cps_key=ad201ee2ef3b771157f72ee5464b1fea&from=console

华为云

https://activity.huaweicloud.com/cps.html?fromacct=64b5cf7cc11b4840bb4ed2ea0b2f4468&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905

2.部署教程

2024年最新青龙面板跑脚本教程(一)持续更新中

3.代码如下

# -*- coding: utf-8 -*-"""cron: 1 0 0 * * *new Env('HiFiNi');"""
import hashlibimport jsonimport osimport reimport time
import requests
from sendNotify import send
requests.packages.urllib3.disable_warnings()

def login(username, password):    """    登录HiFiNi网站    :param username: 用户名    :param password: 密码(明文,函数内部会进行MD5加密)    :return: 登录成功返回cookie字符串,失败返回None    """    try:        # 对密码进行MD5加密        password_md5 = hashlib.md5(password.encode('utf-8')).hexdigest()
        login_url = "https://www.hifiti.com/user-login.htm"        headers = {            "content-type""application/x-www-form-urlencoded; charset=UTF-8",            "x-requested-with""XMLHttpRequest",            "user-agent""Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36",        }
        data = {            "email": username,            "password": password_md5        }
        response = requests.post(            url=login_url,             headers=headers,             data=data,            timeout=15            verify=False        )
        response_text = response.text.strip()        print(f"登录响应: {response_text}")
        # 检查登录是否成功        if "登录成功" in response_text:            # 提取cookie            cookies = response.cookies            bbs_token = None            bbs_sid = None
            # 从响应头中提取cookie            for cookie in cookies:                if cookie.name == "bbs_token":                    bbs_token = cookie.value                elif cookie.name == "bbs_sid":                    bbs_sid = cookie.value
            if bbs_token and bbs_sid:                cookie_string = f"bbs_sid={bbs_sid}; bbs_token={bbs_token}"                print(f"登录成功,获取到cookie: {cookie_string}")                return cookie_string            else:                print("登录成功但无法提取cookie")                return None        else:            print(f"登录失败: {response_text}")            return None
    except Exception as e:        print(f"登录过程中发生异常: {str(e)}")        return None

def start(cookie):    max_retries = 20    retries = 0    msg = ""    while retries < max_retries:        try:            msg += "第{}次执行签到\n".format(str(retries + 1))            sign_in_url = "https://www.hifiti.com/sg_sign.htm"            headers = {                "Cookie": cookie,                "authority""www.hifiti.com",                "accept""text/plain, */*; q=0.01",                "accept-language""zh-CN,zh;q=0.9",                "origin""https://www.hifiti.com",                "referer""https://www.hifiti.com/",                "sec-ch-ua"'"Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"',                "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/114.0.0.0 Safari/537.36",                "x-requested-with""XMLHttpRequest",            }
            rsp = requests.post(                url=sign_in_url, headers=headers, timeout=15, verify=False            )            rsp_text = rsp.text.strip()            print(rsp_text)            success = False            if "今天已经签过啦!" in rsp_text:                msg += "已经签到过了,不再重复签到!\n"                success = True            elif "成功" in rsp_text:                rsp_json = json.loads(rsp_text)                msg += rsp_json["message"]                success = True            elif "503 Service Temporarily" in rsp_text or "502 Bad Gateway" in rsp_text:                msg += "服务器异常!\n"            elif "请登录后再签到!" in rsp_text:                msg += "Cookie没有正确设置!\n"                success = True            elif "操作存在风险,请稍后重试" in rsp_text:                msg += "没有设置sign导致的!\n"                success = False                send("hifini 签到失败:", msg)            else:                msg += "未知异常!\n"                msg += rsp_text + "\n"
            # rsp_json = json.loads(rsp_text)            # print(rsp_json['code'])            # print(rsp_json['message'])            if success:                print("签到结果: ", msg)                send("hifini 签到结果", msg)                break  # 成功执行签到,跳出循环            elif retries >= max_retries:                print("达到最大重试次数,签到失败。")                send("hifini 签到结果", msg)                break            else:                retries += 1                print("等待20秒后进行重试...")                time.sleep(20)        except Exception as e:            print("签到失败,失败原因:" + str(e))            send("hifini 签到结果"str(e))            retries += 1            if retries >= max_retries:                print("达到最大重试次数,签到失败。")                break            else:                print("等待20秒后进行重试...")                time.sleep(20)

if __name__ == "__main__":    # 优先使用环境变量中的cookie    cookie = os.getenv("HIFINI_COOKIE")    username = None    password = None

    # 如果没有cookie,尝试使用用户名密码登录    if not cookie:        if username and password:            print("未找到cookie,尝试使用用户名密码登录...")            cookie = login(username, password)            if not cookie:                print("登录失败,无法获取cookie")                exit(1)        else:            print("请设置HIFINI_COOKIE环境变量,或者设置HIFINI_USERNAME和HIFINI_PASSWORD环境变量")            exit(1)
    start(cookie)

解析

该脚本为HiFiNi 自动签到脚本主要作用包括:

  • 通过 Cookie(或用户名+密码获取 Cookie)自动登录 HiFiNi(hifiti.com) 并执行每日签到。

  • 失败会按固定间隔最多重试 20 次;成功或重要异常会通过 sendNotify.send 推送结果(适配青龙面板通知)。

  • 支持在无 Cookie 时尝试账号密码登录(脚本中留了位,但默认从环境变量读取 Cookie 更常用)。

运行入口

  • __main__

    • 优先读取环境变量 HIFINI_COOKIE

    • 若无 Cookie,尝试用用户名/密码调用 login() 获取 Cookie(当前示例中 username/password 未从环境变量读取,需要你补齐)。

    • 调用 start(cookie) 开始签到并处理重试与通知。

核心函数

  • login(username, password) -> cookie_str | None

    • 将明文密码做 MD5 后提交到 https://www.hifiti.com/user-login.htm

    • 登录成功后从响应 Set-Cookie 提取 bbs_sidbbs_token,拼成 "bbs_sid=...; bbs_token=..." 返回。

    • 失败返回 None

    • 作用:在没有现成 Cookie 时,自动获取可用 Cookie。

  • start(cookie)

    • 包含 "今天已经签过啦!" → 视为成功

    • 包含 "成功" → 解析 JSON 并记录 message

    • 503/502 → 记录"服务器异常",继续重试

    • "请登录后再签到!" → 提示 Cookie 未设置或失效(视作已终止)

    • "操作存在风险,请稍后重试" → 提示未设置 sign(站点反爬校验),会发送失败通知

    • 其他 → 作为未知异常记录

    • 带上 Cookie 请求 https://www.hifiti.com/sg_sign.htm 完成签到。

    • 最多重试 max_retries=20 次,每次失败等待 20 秒

    • 根据返回文本判断:

    • 成功或终止时通过 send("hifini 签到结果", msg) 推送。

依赖与环境

  • 依赖:requestssendNotify(青龙面板通知模块)。

  • 重要环境变量:

    • HIFINI_COOKIE:形如 bbs_sid=...; bbs_token=...

    • (可扩展)HIFINI_USERNAMEHIFINI_PASSWORD:若你想走 login(),需要自行从环境变量读取并传入。

典型使用方式

  • 推荐直接设置 HIFINI_COOKIE 后运行;Cookie 失效再考虑 login() 补充逻辑。

  • 青龙定时(示例注释):cron: 1 0 0 * * *



注意

本文部分变量已做脱敏处理,仅用于测试和学习研究,禁止用于商业用途,不能保证其合法性,准确性,完整性和有效性,请根据情况自行判断。技术层面需要提供帮助,可以通过打赏的方式进行探讨。

【相关文章】

HiFiNi任务脚本


历史脚本txt文件获取>>
服务器搭建,人工服务咨询>>


没有评论:

发表评论

HiFiNi任务脚本(2025年9月版)

1.购买服务器阿里云:服务器购买地址https://t.aliyun.com/U/DT4XYh若失效,可用地址 1.购买服务器 阿里云: 服务器购买地址 https : //t.aliyun.com/U/DT4XYh 若失效,可用地址 https ://www.aliyun....