test(hjc): 一站式入向推送测试脚本(POST /api/hjc/push/project,appKey+timestamp+sign 鉴权)

This commit is contained in:
2026-09-09 10:59:00 +08:00
parent 32a3d1918c
commit 9b050c9dc5
+101
View File
@@ -0,0 +1,101 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
汇吉采 <-- 一站式:推送标书项目测试脚本(入向 POST /api/hjc/push/project
用法:
python hjc_test_push.py # 默认 http://uk.frp.one:62335
python hjc_test_push.py http://uk.frp.one:62335
python hjc_test_push.py --base http://uk.frp.one:62335 --project-no TEST-xxx
无第三方依赖,仅标准库(hashlib + urllib)。时间用北京时间(UTC+8)。
签名 sign = MD5(appKey + password + timestamp)timestamp = yyyyMMddHHmm。
"""
import sys
import json
import hashlib
import urllib.request
import urllib.error
import datetime
APP_KEY = "HJC_Official_Website"
PASSWORD = "vQ8$kR3#mW6@xP2!nF"
DEFAULT_BASE = "http://uk.frp.one:62335"
DEFAULT_PAYLOAD = {
"projectNo": "TEST-HJC-20260801",
"projectName": "测试标书项目·服务器采购",
"category": "货物类",
"tenderPrice": 500.00,
"files": "[{\"name\":\"招标文件.pdf\",\"url\":\"https://file.example.com/t.pdf\"}]",
"tenderOnsaleTime": "2026-08-01 09:00:00",
"tenderOffsaleTime": "2026-08-10 17:00:00",
"bulletinName": "中标公告-测试",
"customerName": "某招标单位",
"supplierName": "某中标公司",
"bidAmount": 128000.00,
"content": "测试公告正文。中标供应商:某中标公司,中标金额 128000 元。",
"fileList": "[{\"name\":\"中标通知书.pdf\",\"url\":\"https://file.example.com/n.pdf\"}]",
"needSellTender": 1,
"sellingMethod": 2
}
def bj_now() -> str:
"""北京时间 yyyyMMddHHmm"""
return (datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(hours=8)).strftime("%Y%m%d%H%M")
def main():
base = DEFAULT_BASE
payload = dict(DEFAULT_PAYLOAD)
args = sys.argv[1:]
i = 0
while i < len(args):
a = args[i]
if a in ("--base", "-b"):
base = args[i + 1]
i += 2
elif a in ("--project-no", "-p"):
payload["projectNo"] = args[i + 1]
i += 2
elif a == "--json":
with open(args[i + 1], encoding="utf-8") as f:
payload = json.load(f)
i += 2
else:
base = a # 位置参数作为 baseUrl
i += 1
url = base.rstrip("/") + "/api/hjc/push/project"
ts = bj_now()
sign = hashlib.md5((APP_KEY + PASSWORD + ts).encode("utf-8")).hexdigest()
body = json.dumps(payload, ensure_ascii=False).encode("utf-8")
req = urllib.request.Request(url, data=body, method="POST", headers={
"Content-Type": "application/json; charset=utf-8",
"appKey": APP_KEY,
"timestamp": ts,
"sign": sign,
"tenantId": "10626"
})
print("== 请求 ==")
print("URL:", url)
print("timestamp:", ts, "| sign:", sign)
print("body:", body.decode("utf-8"))
print()
print("== 响应 ==")
try:
with urllib.request.urlopen(req, timeout=20) as resp:
print("HTTP", resp.status)
print(resp.read().decode("utf-8"))
except urllib.error.HTTPError as e:
print("HTTP", e.code)
print(e.read().decode("utf-8"))
except Exception as e:
print("ERROR:", type(e).__name__, e)
if __name__ == "__main__":
main()