result.txt 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import time
  2. import hmac
  3. import hashlib
  4. import requests
  5. import uuid
  6. # 1. 配置(直接填你的)
  7. app_id = "hmDeOtXZVbeo2AZ-x58yPssZLg4Tcb1W"
  8. app_secret = "pj9UirhGUFPsFnCizCz-Qo1dOGi3kxRIrDKKmJZu2aRCPgtTogTubDRW1weM4KNL"
  9. url = "http://192.168.92.61:8003/api/v1/open/auth/token" # 注意带 /open/
  10. # 2. 生成参数
  11. timestamp = str(int(time.time())) # 秒级时间戳
  12. nonce = uuid.uuid4().hex # 随机字符串
  13. message = app_id + timestamp + nonce
  14. # 3. 计算 HMAC-SHA256 签名
  15. signature = hmac.new(
  16. key=app_secret.encode("utf-8"),
  17. msg=message.encode("utf-8"),
  18. digestmod=hashlib.sha256
  19. ).hexdigest()
  20. # 4. 构造请求头
  21. headers = {
  22. "Content-Type": "application/json",
  23. "X-Api-Key": app_id,
  24. "X-Timestamp": timestamp,
  25. "X-Nonce": nonce,
  26. "X-Signature": signature
  27. }
  28. # 5. 发送请求(body 为空 {})
  29. body = {}
  30. resp = requests.post(url, json=body, headers=headers)
  31. # 6. 打印结果
  32. print("=== 请求信息 ===")
  33. print("headers:", headers)
  34. print("status_code:", resp.status_code)
  35. print("response:", resp.text)