马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 playok 于 2026-2-9 17:43 编辑
利用青龙面板,每日自动签到Hifini 。
使用说明见脚本:
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """
- HiFiNi 音乐磁场自动签到脚本
- 签到地址: https://hifiti.com/sg_sign.htm
- 作者: 千问
- 任务名称
- name: HiFiNi 音乐磁场签到
- 定时规则
- cron: 0 0 9 * * ?
- 使用说明:在环境变量中添加 HIFINI_COOKIE
- 通知(可选):若是需要提醒,可在notify.py中配置一下,比如配置企业微信通知,可将企微的消息推送的webhook地址key配置到QYWX_KEY中
- """
- import json
- import os
- import random
- import sys
- import time
- from typing import List
- import requests
- class Hifini(object):
- name = "HiFiNi 音乐磁场"
- def __init__(self, check_item: dict):
- self.SIGN_URL = "https://hifiti.com/sg_sign.htm"
- self.cookie_str = check_item.get("cookie", "").strip()
- if not self.cookie_str:
- raise ValueError("必须提供有效 Cookie")
- # 解析 cookie 字符串为字典
- self.cookies = {}
- for part in self.cookie_str.split(";"):
- part = part.strip()
- if "=" in part:
- key, val = part.split("=", 1)
- self.cookies[key] = val
- # 检查关键字段
- if "bbs_sid" not in self.cookies or "bbs_token" not in self.cookies:
- print("⚠️ Cookie 中可能缺少 bbs_sid 或 bbs_token,但仍尝试签到")
- def sign_in(self) -> str:
- """执行签到并返回结果字符串"""
- headers = {
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0 Safari/537.36",
- "Referer": "https://hifiti.com/",
- "Origin": "https://hifiti.com",
- "X-Requested-With": "XMLHttpRequest",
- "Accept": "text/plain, */*; q=0.01",
- "Cache-Control": "no-cache",
- "Pragma": "no-cache",
- "Sec-Fetch-Site": "same-origin",
- "Sec-Fetch-Mode": "cors",
- }
- try:
- resp = requests.post(
- self.SIGN_URL,
- headers=headers,
- cookies=self.cookies,
- timeout=15
- )
- resp.encoding = 'utf-8'
- text = resp.text.strip()
- if resp.status_code == 200:
- if "今日已签到" in text or "已经签到" in text:
- return "✅ 今日已签到"
- elif "成功" in text or "签到成功" in text or "奖励" in text:
- return "✅ 签到成功"
- else:
- return f"❓ 未知响应: {text[:100]}"
- else:
- return f"❌ HTTP {resp.status_code}: {text[:100]}"
- except Exception as e:
- return f"💥 请求异常: {str(e)}"
- def main(self) -> str:
- try:
- result = self.sign_in()
- return f"状态: {result}"
- except Exception as e:
- return f"签到失败: {str(e)}"
- # 从青龙环境变量读取Cookie并处理多账户
- def get_hifini_cookies() -> List[str]:
- cookies = []
- hifini_env = os.getenv('HIFINI_COOKIE', '').strip()
- if not hifini_env:
- print("未找到环境变量 HIFINI_COOKIE")
- # 尝试从 config.json 读取
- try:
- config_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "config.json")
- with open(config_path, encoding="utf-8") as f:
- data = json.load(f)
- config_cookies = data.get("HIFINI_COOKIE", [])
- for item in config_cookies:
- if isinstance(item, str):
- cookies.append(item)
- elif isinstance(item, dict) and 'cookie' in item:
- cookies.append(item['cookie'])
- if cookies:
- print(f"从 config.json 读取到 {len(cookies)} 个账号")
- return cookies
- except Exception as e:
- print(f"读取 config.json 失败: {e}")
- return []
- # 支持换行分隔的多账号
- lines = hifini_env.split('\n')
- for line in lines:
- line = line.strip()
- if line:
- cookies.append(line)
- print(f"从环境变量读取到 {len(cookies)} 个账号")
- return cookies
- # === 青龙路径与通知模块(放在最后,按你的要求)===
- # 添加青龙脚本根目录到Python路径
- QL_SCRIPTS_DIR = '/ql/scripts'
- if os.path.exists(QL_SCRIPTS_DIR):
- sys.path.append(QL_SCRIPTS_DIR)
- # 添加 notify 可能存在的其他路径
- POSSIBLE_PATHS = [
- '/ql',
- '/ql/data/config', # ✅ 新版青龙正确路径
- '/ql/config',
- '/ql/scripts',
- os.path.dirname(__file__)
- ]
- for path in POSSIBLE_PATHS:
- if os.path.isfile(os.path.join(path, 'notify.py')):
- sys.path.append(path)
- break
- def send_notification(title: str, content: str):
- """发送青龙通知"""
- try:
- from notify import send
- return send(title, content)
- except ImportError:
- print("⚠️ 无法加载通知模块,请检查路径配置")
- print(f"【通知】{title}\n{content}")
- return None
- except Exception as e:
- print(f"通知发送失败: {e}")
- print(f"通知内容:\n{title}\n{content}")
- return None
- # === 主程序入口 ===
- if __name__ == "__main__":
- cookies = get_hifini_cookies()
- if not cookies:
- print("没有找到有效的 HiFiNi Cookie")
- exit(1)
- results = []
- for idx, cookie in enumerate(cookies, 1):
- print(f"\n==== 处理第 {idx}/{len(cookies)} 个账号 ====")
- try:
- check_item = {"cookie": cookie}
- hifini = Hifini(check_item)
- result = hifini.main()
- results.append(result)
- print(f"账号 {idx} 处理完成: {result}")
- except Exception as e:
- error_msg = f"账号 {idx} 处理失败: {str(e)}"
- results.append(error_msg)
- print(error_msg)
- # 账号间随机延迟
- if idx < len(cookies):
- delay = random.uniform(2, 5)
- print(f"等待 {delay:.2f} 秒后处理下一个账号...")
- time.sleep(delay)
- # 汇总结果
- final_title = "🎧 HiFiNi 签到结果汇总"
- final_content = "\n\n".join([f"【账号 {i+1}】\n{result}" for i, result in enumerate(results)])
- # 统计
- success_count = sum(1 for r in results if "✅" in r)
- total_count = len(results)
- final_content += f"\n\n📊 统计信息:\n成功: {success_count}/{total_count}\n失败: {total_count - success_count}/{total_count}"
- print("\n==== 开始发送通知 ====")
- send_notification(final_title, final_content)
- print("==== 全部处理完成 ====")
复制代码
执行日志截图:
运行日志截图
企微通知截图:
企微通知截图
|