- hr_sdk.wage_import:DrissionPage 注入 cookie 打开 HR 门户,页面内 WS 订阅 + fetch 上传,解析 over: 结果;build_xlsx 第 9 列卡号强制数值(修复「卡号必须是数字」) - 纯 HTTP 导入不可用:服务端异步任务与浏览器会话强绑定,且前端无轮询接口(已核实),结果通道只能用浏览器上下文 - desktopauto 0.5.0 新增 cardocr:身份证/银行卡 OCR、号码纠错、Luhn 与模 11-2 校验、交叉核对 - 新增插件 XQ0084 银行卡更新EHR系统:AI 表格待处理行 → 影像识别 → 一致性核对/异常名单 - .gitignore 忽略 tests/aitable_probe/_out/(含员工证件照,禁止入库)
62 lines
2.3 KiB
Python
62 lines
2.3 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""XQ0084 提醒层:钉钉群机器人 Markdown 推送(仅标准库 + 项目级重试)。"""
|
||
import base64
|
||
import hashlib
|
||
import hmac
|
||
import json
|
||
import time
|
||
import urllib.parse
|
||
import urllib.request
|
||
|
||
from ..config import logger
|
||
|
||
DEFAULT_TIMEOUT = 10
|
||
DEFAULT_RETRY_TIMES = 3
|
||
|
||
|
||
def _build_sign(secret, timestamp_ms):
|
||
string_to_sign = f"{timestamp_ms}\n{secret}"
|
||
hmac_code = hmac.new(secret.encode("utf-8"), string_to_sign.encode("utf-8"),
|
||
digestmod=hashlib.sha256).digest()
|
||
return urllib.parse.quote_plus(base64.b64encode(hmac_code))
|
||
|
||
|
||
def _build_url(webhook, secret=""):
|
||
if not secret:
|
||
return webhook
|
||
ts = int(round(time.time() * 1000))
|
||
separator = "&" if "?" in webhook else "?"
|
||
return f"{webhook}{separator}timestamp={ts}&sign={_build_sign(secret, ts)}"
|
||
|
||
|
||
def send_markdown(webhook, secret, title, text):
|
||
"""向群机器人推送 Markdown;webhook 为空时跳过。"""
|
||
webhook = (webhook or "").strip()
|
||
if not webhook:
|
||
return {"success": False, "message": "未配置 Webhook,跳过推送"}
|
||
payload = {
|
||
"msgtype": "markdown",
|
||
"markdown": {"title": title or "通知", "text": text or ""},
|
||
}
|
||
body = json.dumps(payload, ensure_ascii=False).encode("utf-8")
|
||
url = _build_url(webhook, (secret or "").strip())
|
||
last_err = ""
|
||
for attempt in range(1, DEFAULT_RETRY_TIMES + 1):
|
||
try:
|
||
req = urllib.request.Request(
|
||
url, data=body, method="POST",
|
||
headers={"Content-Type": "application/json; charset=utf-8"})
|
||
with urllib.request.urlopen(req, timeout=DEFAULT_TIMEOUT) as resp:
|
||
raw = resp.read().decode("utf-8", errors="replace")
|
||
data = json.loads(raw) if raw else {}
|
||
if data.get("errcode") == 0:
|
||
logger.info("钉钉群消息推送成功")
|
||
return {"success": True, "message": "ok"}
|
||
last_err = f"errcode={data.get('errcode')} errmsg={data.get('errmsg')}"
|
||
except Exception as e:
|
||
last_err = str(e)
|
||
logger.warning("钉钉推送第 %d/%d 次失败:%s", attempt, DEFAULT_RETRY_TIMES, last_err)
|
||
if attempt < DEFAULT_RETRY_TIMES:
|
||
time.sleep(1.0 * attempt)
|
||
return {"success": False, "message": last_err}
|