Files
37duAutomation/plugins/XQ0001-0100/XQ0042 抖音平台核对/config/__init__.py
T
puddy 0a32518060 refactor: 重构多插件 UI 与配置结构,新增抖音/新美大平台核对插件
- 新增 XQ0042 抖音平台核对、XQ0041 新美大平台核对插件的 UI 源码与打包脚本
- 重构续签电子签、服务岗转正不通过电子签等插件的版本与配置
- 删除旧版考勤异常处理、微盟数据导出等冗余插件文件
- 修复出勤积分更新插件的 OPM 推送判断逻辑
- 优化壳子插件页面的 iframe 滚动条样式
2026-10-28 10:51:27 +08:00

200 lines
8.8 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.
# -*- coding: utf-8 -*-
"""xq0042 抖音平台核对 - 配置常量与全局钩子。
插件自包含:只依赖标准库 / 第三方库 / 底座注入的 RunContext。
各业务模块统一经 config.log() / config.progress() 输出,由 run() 启动时注入 ctx。
当前阶段只做「登录态获取与验证」(抖音来客)。
2026-10-28 实测:
登录页 https://life.douyin.com/p/login
首页 https://life.douyin.com/p/home[?groupid=...]
会话票据种在 .life.douyin.com:sessionid_ls / sessionid_ss_ls / sid_tt_ls / sid_guard_ls
"""
import os
import time
# ==================== 平台:抖音来客 ====================
HOME_URL = 'https://life.douyin.com/p/home'
LOGIN_URL = 'https://life.douyin.com/p/login'
BACKEND_HOST = 'life.douyin.com' # 来客后台主域
LOGIN_PAGE_HINTS = ('/p/login', 'login') # 登录页路径(同域下的排除项)
PASSPORT_HINTS = ( # 统一登录/账号域
'sso.douyin.com', 'passport.douyin.com', 'open.douyin.com',
'douyin.com/login', 'account.douyin.com',
)
# 登录票据 Cookie:名字带分区后缀 `_ls`(老版本/无分区时是裸名),按前缀匹配
SESSION_COOKIE_PREFIXES = ('sessionid', 'sid_tt', 'sid_guard', 'sid_ucp')
# 票据候选(子串匹配,仅用于日志摘要)与埋点排除项
TICKET_KEY_HINTS = ('session', 'sid', 'token', 'ticket', 'userid', 'user_id')
IGNORE_KEY_HINTS = (
'ttwid', 'mstoken', 'csrf', '_ga', '_gid', '__ac', 's_v_web_id', 'tt_scid',
'monitor', 'abtest', 'odin', 'store-region', 'passport_csrf',
)
# ==================== 核销明细导出(履约管理 → 导出工具) ====================
# 实测 2026-10-28:导出工具弹窗「核销明细」提交的就是这个接口,
# 返回 downloadStruct(download_id + status=1 生成中),完成后在「导出记录」里出现。
ORDER_URL = ('https://life.douyin.com/p/liteapp/fulfillment-admin/order-list'
'?admin_industry=45&groupid=1732612560882691')
ORDER_GROUP_ID = '1732612560882691' # 当前账号(URL 里取不到时的兜底)
ROOT_LIFE_ACCOUNT_ID = '7044832462517569568' # 主账号 ID(localStorage 解析失败时的兜底)
VERIFY_EXPORT_API = ('https://life.douyin.com/life/trade_view/v1/management/verify/query/'
'download_verify_record_list')
DOWNLOAD_LIST_API = 'https://life.douyin.com/life/settle/v1/download/list/'
DOWNLOAD_TYPE = 10031001 # 导出记录页(财务 → 导出记录)
VERIFY_VIEW_TYPE = 'common_view_verify_record'
VERIFY_SHOW_REASON = 'catering_comprehensive_coupon'
# 商品类型过滤(与页面默认一致:团购券/次卡等全部可核销类型)
VERIFY_PRODUCT_OPTIONS = ['1', '11', '15', '2601', '26', '130011', '2201', '1801', '1802',
'1803', '1804', '2901', '1501', '2801', '100112', '110301', '1502']
RECORD_SECONDS = 180 # 导出任务生成超时(秒)
RECORD_POLL = 10 # 轮询生成状态的间隔(秒)
# ==================== 提现记录(余额提现记录)导出 ====================
# 实测 2026-10-28:财务 → 导出记录(/p/fulfillsettle/export_records/16)点「导出」,
# 走的是 GET withdraw/capital/download_records_list,时间参数为秒级时间戳;
# 记录列表 download_type=16,文件名形如「资金账户交易提现记录_起_止.xlsx」。
WITHDRAW_URL = ('https://life.douyin.com/p/fulfillsettle/export_records/16'
'?groupid=1732612560882691')
WITHDRAW_EXPORT_API = ('https://life.douyin.com/life/settle/v1/withdraw/capital/'
'download_records_list/')
WITHDRAW_DOWNLOAD_TYPE = 16 # 余额提现记录
WITHDRAW_FUND_ACCOUNT_TYPE = 6 # 资金账户类型(页面默认)
DELETE_API = 'https://life.douyin.com/life/settle/v1/download/delete/'
# 平台限制:提现记录类导出最多 30 条,满了再发起会返回
# 224000002「最多仅支持30个待下载文件,请删除部分历史文件后重试」。
# 因此每次导出前先查列表:记录数超过「保留阈值」就删最早的、只留最新 N 条。
# 阈值可在插件界面手动改(record_limit_verify / record_limit_withdraw)。
RECORD_LIMIT_VERIFY = 60 # 核销明细:该类列表暂未遇到 30 条限制,先记 60
RECORD_LIMIT_WITHDRAW = 25 # 提现记录:平台 30 条硬上限,留 5 条余量
RECORD_LIMIT_CODE = 224000002 # 「最多仅支持30个待下载文件」的业务错误码
RECORD_LIMIT_MIN = 5 # 阈值下限:防止误填过小导致批量删记录
# 删除导出记录要限流:连续删除间隔随机抖动,单次运行设上限,避免被平台风控判定异常
DELETE_MIN_INTERVAL = 1.0 # 两条删除之间的最短间隔(秒)
DELETE_MAX_INTERVAL = 2.0 # 最长间隔(秒),实际取值在两者之间随机
DELETE_MAX_PER_RUN = 20 # 单次运行最多删几条,超出部分留到下次运行
# ==================== 输出目录 ====================
WORK_DIR = r'D:\资料\财务\抖音平台核对' # 核销明细 + 台账统一目录
# ==================== 运行参数 ====================
LOGIN_WAIT = 600 # 等待人工登录(含验证码/滑块)超时
BACKEND_STABLE = 15 # 后台页连续稳定秒数(登录后有短暂回跳登录页的现象)
SETTLE_WAIT = 8 # 登录成功后等首屏请求结束再抓 cookie
POLL_SECONDS = 2
RETRY_MAX = 3
HEADLESS = False # 人工登录必须可见浏览器
# ==================== 共享路径 ====================
def _app_data_dir():
return os.path.join(
os.getenv('LOCALAPPDATA') or os.getenv('APPDATA') or os.path.expanduser('~'),
'37duAutomation')
SESSIONS_DIR = os.path.join(_app_data_dir(), '.sessions')
COOKIE_FILE = os.path.join(SESSIONS_DIR, 'douyin_cookies.json')
COOKIE_HEADER_FILE = os.path.join(SESSIONS_DIR, 'douyin_cookies_header.txt')
TOKEN_FILE = os.path.join(SESSIONS_DIR, 'douyin_tokens.json')
META_FILE = os.path.join(SESSIONS_DIR, 'douyin_session_meta.json')
def get_browser_profile_dir():
"""独立固定浏览器用户目录:登录态跨次保留,不占用日常 Chrome 配置。"""
return os.path.join(_app_data_dir(), 'browser_sessions', 'xq0042')
# ==================== 浏览器窗口(全屏 + 置顶) ====================
def apply_window_mode(page):
"""把浏览器窗口设为全屏并置顶(登录要人工操作,避免被其它窗口挡住)。"""
try:
page.set.window.full()
except Exception as e:
log(f'设置窗口全屏失败(忽略):{e}', 'WARN')
if os.name == 'nt':
try:
_set_topmost(page.process_id)
except Exception as e:
log(f'设置窗口置顶失败(忽略):{e}', 'WARN')
def _set_topmost(pid):
"""把指定进程的主窗口设为 HWND_TOPMOST(Win32 SetWindowPos,仅 Windows)。"""
if not pid:
return
import ctypes
from ctypes import wintypes
user32 = ctypes.windll.user32
user32.IsWindowVisible.argtypes = [wintypes.HWND]
user32.GetWindowTextLengthW.argtypes = [wintypes.HWND]
user32.GetWindowThreadProcessId.argtypes = [wintypes.HWND, ctypes.POINTER(wintypes.DWORD)]
hwnds = []
@ctypes.WINFUNCTYPE(wintypes.BOOL, wintypes.HWND, wintypes.LPARAM)
def _collect(hwnd, _lparam):
if user32.IsWindowVisible(hwnd) and user32.GetWindowTextLengthW(hwnd) > 0:
proc = wintypes.DWORD()
user32.GetWindowThreadProcessId(hwnd, ctypes.byref(proc))
if proc.value == pid:
hwnds.append(hwnd)
return True
user32.EnumWindows.argtypes = [ctypes.WINFUNCTYPE(wintypes.BOOL, wintypes.HWND, wintypes.LPARAM),
wintypes.LPARAM]
user32.EnumWindows(_collect, 0)
user32.SetWindowPos.argtypes = [wintypes.HWND, wintypes.HWND, ctypes.c_int,
ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_uint]
for hwnd in hwnds:
user32.SetWindowPos(hwnd, wintypes.HWND(-1), 0, 0, 0, 0, 0x0001 | 0x0002) # NOSIZE | NOMOVE
# ==================== 全局钩子(run() 启动时注入) ====================
_log = None
_progress = None
_debug = False
def set_log(fn):
global _log
_log = fn
def set_progress(fn):
global _progress
_progress = fn
def set_debug(on):
global _debug
_debug = bool(on)
def debug_enabled():
return _debug
def log(msg, level='INFO'):
text = f'[{time.strftime("%H:%M:%S")}] {msg}'
if level == 'DEBUG' and not _debug:
return
if _log:
_log(str(msg), level)
else:
print(f'[{level}] {text}')
def progress(pct):
if _progress:
try:
_progress(int(pct))
except Exception:
pass