返回列表 发布新帖

[其他应用] 【青龙面板】Hifini 音乐磁场每日自动签到

706 2
发表于 2026-2-9 17:26:42 | 查看全部 阅读模式 IP:–贵州–遵义

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
本帖最后由 playok 于 2026-2-9 17:43 编辑

利用青龙面板,每日自动签到Hifini 。

使用说明见脚本:
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. HiFiNi 音乐磁场自动签到脚本
  5. 签到地址: https://hifiti.com/sg_sign.htm
  6. 作者: 千问
  7. 任务名称
  8. name: HiFiNi 音乐磁场签到
  9. 定时规则
  10. cron: 0 0 9 * * ?
  11. 使用说明:在环境变量中添加 HIFINI_COOKIE
  12. 通知(可选):若是需要提醒,可在notify.py中配置一下,比如配置企业微信通知,可将企微的消息推送的webhook地址key配置到QYWX_KEY中
  13. """

  14. import json
  15. import os
  16. import random
  17. import sys
  18. import time
  19. from typing import List

  20. import requests

  21. class Hifini(object):
  22.     name = "HiFiNi 音乐磁场"

  23.     def __init__(self, check_item: dict):
  24.         self.SIGN_URL = "https://hifiti.com/sg_sign.htm"
  25.         self.cookie_str = check_item.get("cookie", "").strip()
  26.         if not self.cookie_str:
  27.             raise ValueError("必须提供有效 Cookie")

  28.         # 解析 cookie 字符串为字典
  29.         self.cookies = {}
  30.         for part in self.cookie_str.split(";"):
  31.             part = part.strip()
  32.             if "=" in part:
  33.                 key, val = part.split("=", 1)
  34.                 self.cookies[key] = val

  35.         # 检查关键字段
  36.         if "bbs_sid" not in self.cookies or "bbs_token" not in self.cookies:
  37.             print("⚠️ Cookie 中可能缺少 bbs_sid 或 bbs_token,但仍尝试签到")

  38.     def sign_in(self) -> str:
  39.         """执行签到并返回结果字符串"""
  40.         headers = {
  41.             "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0 Safari/537.36",
  42.             "Referer": "https://hifiti.com/",
  43.             "Origin": "https://hifiti.com",
  44.             "X-Requested-With": "XMLHttpRequest",
  45.             "Accept": "text/plain, */*; q=0.01",
  46.             "Cache-Control": "no-cache",
  47.             "Pragma": "no-cache",
  48.             "Sec-Fetch-Site": "same-origin",
  49.             "Sec-Fetch-Mode": "cors",
  50.         }

  51.         try:
  52.             resp = requests.post(
  53.                 self.SIGN_URL,
  54.                 headers=headers,
  55.                 cookies=self.cookies,
  56.                 timeout=15
  57.             )
  58.             resp.encoding = 'utf-8'
  59.             text = resp.text.strip()

  60.             if resp.status_code == 200:
  61.                 if "今日已签到" in text or "已经签到" in text:
  62.                     return "✅ 今日已签到"
  63.                 elif "成功" in text or "签到成功" in text or "奖励" in text:
  64.                     return "✅ 签到成功"
  65.                 else:
  66.                     return f"❓ 未知响应: {text[:100]}"
  67.             else:
  68.                 return f"❌ HTTP {resp.status_code}: {text[:100]}"
  69.         except Exception as e:
  70.             return f"💥 请求异常: {str(e)}"

  71.     def main(self) -> str:
  72.         try:
  73.             result = self.sign_in()
  74.             return f"状态: {result}"
  75.         except Exception as e:
  76.             return f"签到失败: {str(e)}"


  77. # 从青龙环境变量读取Cookie并处理多账户
  78. def get_hifini_cookies() -> List[str]:
  79.     cookies = []
  80.     hifini_env = os.getenv('HIFINI_COOKIE', '').strip()

  81.     if not hifini_env:
  82.         print("未找到环境变量 HIFINI_COOKIE")
  83.         # 尝试从 config.json 读取
  84.         try:
  85.             config_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "config.json")
  86.             with open(config_path, encoding="utf-8") as f:
  87.                 data = json.load(f)
  88.                 config_cookies = data.get("HIFINI_COOKIE", [])
  89.                 for item in config_cookies:
  90.                     if isinstance(item, str):
  91.                         cookies.append(item)
  92.                     elif isinstance(item, dict) and 'cookie' in item:
  93.                         cookies.append(item['cookie'])
  94.                 if cookies:
  95.                     print(f"从 config.json 读取到 {len(cookies)} 个账号")
  96.                 return cookies
  97.         except Exception as e:
  98.             print(f"读取 config.json 失败: {e}")
  99.             return []

  100.     # 支持换行分隔的多账号
  101.     lines = hifini_env.split('\n')
  102.     for line in lines:
  103.         line = line.strip()
  104.         if line:
  105.             cookies.append(line)

  106.     print(f"从环境变量读取到 {len(cookies)} 个账号")
  107.     return cookies


  108. # === 青龙路径与通知模块(放在最后,按你的要求)===

  109. # 添加青龙脚本根目录到Python路径
  110. QL_SCRIPTS_DIR = '/ql/scripts'
  111. if os.path.exists(QL_SCRIPTS_DIR):
  112.     sys.path.append(QL_SCRIPTS_DIR)

  113. # 添加 notify 可能存在的其他路径
  114. POSSIBLE_PATHS = [
  115.     '/ql',
  116.     '/ql/data/config',      # ✅ 新版青龙正确路径
  117.     '/ql/config',
  118.     '/ql/scripts',
  119.     os.path.dirname(__file__)
  120. ]

  121. for path in POSSIBLE_PATHS:
  122.     if os.path.isfile(os.path.join(path, 'notify.py')):
  123.         sys.path.append(path)
  124.         break

  125. def send_notification(title: str, content: str):
  126.     """发送青龙通知"""
  127.     try:
  128.         from notify import send
  129.         return send(title, content)
  130.     except ImportError:
  131.         print("⚠️ 无法加载通知模块,请检查路径配置")
  132.         print(f"【通知】{title}\n{content}")
  133.         return None
  134.     except Exception as e:
  135.         print(f"通知发送失败: {e}")
  136.         print(f"通知内容:\n{title}\n{content}")
  137.         return None


  138. # === 主程序入口 ===
  139. if __name__ == "__main__":
  140.     cookies = get_hifini_cookies()
  141.     if not cookies:
  142.         print("没有找到有效的 HiFiNi Cookie")
  143.         exit(1)

  144.     results = []
  145.     for idx, cookie in enumerate(cookies, 1):
  146.         print(f"\n==== 处理第 {idx}/{len(cookies)} 个账号 ====")
  147.         try:
  148.             check_item = {"cookie": cookie}
  149.             hifini = Hifini(check_item)
  150.             result = hifini.main()
  151.             results.append(result)
  152.             print(f"账号 {idx} 处理完成: {result}")
  153.         except Exception as e:
  154.             error_msg = f"账号 {idx} 处理失败: {str(e)}"
  155.             results.append(error_msg)
  156.             print(error_msg)

  157.         # 账号间随机延迟
  158.         if idx < len(cookies):
  159.             delay = random.uniform(2, 5)
  160.             print(f"等待 {delay:.2f} 秒后处理下一个账号...")
  161.             time.sleep(delay)

  162.     # 汇总结果
  163.     final_title = "🎧 HiFiNi 签到结果汇总"
  164.     final_content = "\n\n".join([f"【账号 {i+1}】\n{result}" for i, result in enumerate(results)])

  165.     # 统计
  166.     success_count = sum(1 for r in results if "✅" in r)
  167.     total_count = len(results)
  168.     final_content += f"\n\n📊 统计信息:\n成功: {success_count}/{total_count}\n失败: {total_count - success_count}/{total_count}"

  169.     print("\n==== 开始发送通知 ====")
  170.     send_notification(final_title, final_content)
  171.     print("==== 全部处理完成 ====")
复制代码

执行日志截图:

运行日志截图

运行日志截图



企微通知截图:

企微通知截图

企微通知截图

评论2

playok楼主Lv.4 发表于 2026-2-10 14:24:26 | 查看全部 IP:–贵州–遵义
青龙面板使用教程见夏佬的玩转青龙面板
夏夏子Lv.7绿联NAS社区会员用户 发表于 2026-2-10 08:53:09 | 查看全部 IP:–湖南
6

评论

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Copyright © 2026 绿联NAS私有云社区 版权所有 All Rights Reserved. 粤公网安备44030002002555号| 粤ICP备12028978号
关灯 在本版发帖
联系技术支持
返回顶部
快速回复 返回顶部 返回列表