import time
import hmac
import hashlib
import requests
import uuid

# 1. 配置（直接填你的）
app_id = "hmDeOtXZVbeo2AZ-x58yPssZLg4Tcb1W"
app_secret = "pj9UirhGUFPsFnCizCz-Qo1dOGi3kxRIrDKKmJZu2aRCPgtTogTubDRW1weM4KNL"
url = "http://192.168.92.61:8003/api/v1/open/auth/token"  # 注意带 /open/

# 2. 生成参数
timestamp = str(int(time.time()))  # 秒级时间戳
nonce = uuid.uuid4().hex  # 随机字符串
message = app_id + timestamp + nonce

# 3. 计算 HMAC-SHA256 签名
signature = hmac.new(
    key=app_secret.encode("utf-8"),
    msg=message.encode("utf-8"),
    digestmod=hashlib.sha256
).hexdigest()

# 4. 构造请求头
headers = {
    "Content-Type": "application/json",
    "X-Api-Key": app_id,
    "X-Timestamp": timestamp,
    "X-Nonce": nonce,
    "X-Signature": signature
}

# 5. 发送请求（body 为空 {}）
body = {}
resp = requests.post(url, json=body, headers=headers)

# 6. 打印结果
print("=== 请求信息 ===")
print("headers:", headers)
print("status_code:", resp.status_code)
print("response:", resp.text)