Files
soul-yongping/scripts/post_to_feishu.py
卡若 991e17698c feat: 内容管理第5批优化 - Bug修复 + 分享功能 + 代付功能
1. Bug修复:
   - 修复Markdown星号/下划线在小程序端原样显示问题(markdownToHtml增加__和_支持,contentParser增加Markdown格式剥离)
   - 修复@提及无反应(MentionSuggestion使用ref保持persons最新值,解决闭包捕获空数组问题)
   - 修复#链接标签点击"未找到小程序配置"(增加appId直接跳转降级路径)

2. 分享功能优化:
   - "分享到朋友圈"改为"分享给好友"(open-type从shareTimeline改为share)
   - 90%收益提示移到分享按钮下方
   - 阅读20%后向上滑动弹出分享浮层提示(4秒自动消失)

3. 代付功能:
   - 后端:新增UserBalance/BalanceTransaction/GiftUnlock三个模型
   - 后端:新增8个余额相关API(查询/充值/充值确认/代付/领取/退款/交易记录/礼物信息)
   - 小程序:阅读页新增"代付分享"按钮,支持用余额为好友解锁章节
   - 分享链接携带gift参数,好友打开自动领取解锁

Made-with: Cursor
2026-03-15 09:20:27 +08:00

83 lines
2.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
发文本到卡若日志飞书群webhook
用法:
python3 post_to_feishu.py "任意文本"
python3 post_to_feishu.py --release 9.23 --title "9.23 第110场Soul变现逻辑全程公开"
"""
import argparse
import json
import os
from pathlib import Path
from urllib.request import Request, urlopen
CONFIG_PATH = Path(__file__).resolve().parent / "feishu_publish_config.json"
WEBHOOK_ENV = "FEISHU_KARUO_LOG_WEBHOOK"
DEFAULT_WEBHOOK = "https://open.feishu.cn/open-apis/bot/v2/hook/34b762fc-5b9b-4abb-a05a-96c8fb9599f1"
WIKI_URL = "https://cunkebao.feishu.cn/wiki/FNP6wdvNKij7yMkb3xCce0CYnpd"
MINIPROGRAM_BASE = "https://soul.quwanzhi.com/read"
MATERIAL_HINT = "材料找卡若AI拿"
def load_webhook():
if os.environ.get(WEBHOOK_ENV):
return os.environ.get(WEBHOOK_ENV)
if CONFIG_PATH.exists():
with open(CONFIG_PATH, "r", encoding="utf-8") as f:
data = json.load(f)
return data.get("feishu_karuo_log_webhook") or data.get("webhook")
return DEFAULT_WEBHOOK
def send_text(text: str) -> bool:
webhook = load_webhook()
if not webhook:
print("未配置 webhook请设置 feishu_publish_config.json 或 FEISHU_KARUO_LOG_WEBHOOK")
return False
payload = {"msg_type": "text", "content": {"text": text}}
req = Request(
webhook,
data=json.dumps(payload).encode("utf-8"),
headers={"Content-Type": "application/json"},
method="POST",
)
try:
with urlopen(req, timeout=10) as resp:
r = json.loads(resp.read().decode())
if r.get("code") != 0:
print("飞书返回:", r)
return False
print("已发送到卡若日志飞书群")
return True
except Exception as e:
print("发送失败:", e)
return False
def main():
parser = argparse.ArgumentParser()
parser.add_argument("text", nargs="?", help="要发送的文本")
parser.add_argument("--release", help="章节 id如 9.23")
parser.add_argument("--title", help="文章标题")
args = parser.parse_args()
if args.release:
title = args.title or args.release
text = f"""📢 新发布
{title}
📱 小程序:{MINIPROGRAM_BASE}/{args.release}
📚 飞书目录:{WIKI_URL}
{MATERIAL_HINT}"""
send_text(text)
elif args.text:
send_text(args.text)
else:
parser.print_help()
if __name__ == "__main__":
main()