Initial commit: Fengxiang order monitor with WeChat & Xiaomi speaker push
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
"""获取最新一条订单并推送到企业微信群"""
|
||||
|
||||
import json
|
||||
import datetime
|
||||
import requests
|
||||
|
||||
DATA_API = "https://fs.szfx.com/saasmerchant/pcweb/order/quickpayorder/list"
|
||||
SHOP_ID = "20434543575189"
|
||||
WEBHOOK_URL = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=644ab6d9-3b66-4166-88e9-5a8a89e3731d"
|
||||
|
||||
STATUS_MAP = {1: "已完成", 3: "已退款", 4: "退款中", 5: "已关闭"}
|
||||
|
||||
|
||||
def fmt_ts(ts):
|
||||
return datetime.datetime.fromtimestamp(ts).strftime("%Y-%m-%d %H:%M:%S") if ts else "-"
|
||||
|
||||
|
||||
def fmt_money(cents):
|
||||
return f"{cents / 100:.2f}元" if cents else "0.00元"
|
||||
|
||||
|
||||
def load_cookies():
|
||||
with open("cookies.json", "r", encoding="utf-8") as f:
|
||||
return json.load(f)
|
||||
|
||||
|
||||
def fetch_latest_order():
|
||||
cookies = load_cookies()
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
|
||||
"Referer": "https://fs.szfx.com/MMS",
|
||||
"Origin": "https://fs.szfx.com",
|
||||
}
|
||||
payload = {"shopId": SHOP_ID, "page": 1, "pageSize": 1}
|
||||
resp = requests.post(DATA_API, json=payload, headers=headers, cookies=cookies, timeout=30)
|
||||
data = resp.json()
|
||||
if data.get("errno") != 0:
|
||||
print(f"请求失败: {data}")
|
||||
return None
|
||||
return data["data"]["list"][0]
|
||||
|
||||
|
||||
def format_order(order):
|
||||
status = STATUS_MAP.get(order["status"], str(order["status"]))
|
||||
return (
|
||||
f"【新订单通知】\n"
|
||||
f"订单号:{order['orderId']}\n"
|
||||
f"店铺:{order['shopName']}\n"
|
||||
f"城市:{order['city']}\n"
|
||||
f"大区:{order['largeAreaName']}\n"
|
||||
f"企业:{order['companyName']}\n"
|
||||
f"用餐地点:{order['workplaceName']}\n"
|
||||
f"下单时间:{fmt_ts(order['createTime'])}\n"
|
||||
f"支付时间:{fmt_ts(order['payTime'])}\n"
|
||||
f"完成时间:{fmt_ts(order['finishTime'])}\n"
|
||||
f"订单金额:{fmt_money(order['allPrice'])}\n"
|
||||
f"实付金额:{fmt_money(order['amountPayable'])}\n"
|
||||
f"支付方式:{order['payTypeName']}\n"
|
||||
f"订单来源:{order['orderSourceName']}\n"
|
||||
f"状态:{status}"
|
||||
)
|
||||
|
||||
|
||||
def send_to_wecom(text):
|
||||
payload = {
|
||||
"msgtype": "text",
|
||||
"text": {"content": text}
|
||||
}
|
||||
resp = requests.post(WEBHOOK_URL, json=payload, timeout=10)
|
||||
result = resp.json()
|
||||
if result.get("errcode") == 0:
|
||||
print("推送成功!")
|
||||
else:
|
||||
print(f"推送失败: {result}")
|
||||
return result
|
||||
|
||||
|
||||
def main():
|
||||
order = fetch_latest_order()
|
||||
if not order:
|
||||
return
|
||||
|
||||
msg = format_order(order)
|
||||
print(msg)
|
||||
print("\n--- 正在推送到企业微信群 ---\n")
|
||||
send_to_wecom(msg)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user