收藏
回答

WeKnora Chat 接口签名为何一直失败?

调用 WeKnora 原子化接口 POST /api/v1/chat/completions 时,按官方文档签名仍返回INVALID_SIGNATURE。

文档规则:

  signature = HMAC-SHA256(Secret-Key, timestamp + "\n" + nonce + "\n" + request_id + "\n" + request_body)

  请求信息:

  Base URL: https://weknora.weixin.qq.com/api/v1

  Path: /chat/completions

  Method: POST

  Content-Type: application/json

  X-APPID: app-xxx-xxxx-xxxxx

  X-Request-ID: K80bMxI4Y9ik

  X-Timestamp: 当前秒级时间戳

  X-Nonce: 自定义字符串

  Secret-Key: 平台 openapi 页面获取,已脱敏


  request_body 使用实际发送的紧凑 JSON:

  {"model":"chat","messages":[{"role":"user","content":"你好,请简单介绍一下你自

  己"}],"stream":false,"max_tokens":128,"temperature":0.2}


  返回:

  {

    "error": {

      "code": "INVALID_SIGNATURE",

      "message": "签名验证失败",

      "detail": "签名不匹配,期望为32位十六进制值,实际为64位十六进制值"

    }

  }


  请问:

  1. X-Signature 是否应使用 HMAC-SHA256 的 hex 输出?

  2. request_body 是否必须紧凑 JSON,是否需要字段排序?

  3. 签名串是否还需要包含 method、path 或 query?

  4. 是否有官方 Python 签名示例?

回答关注问题邀请回答
收藏

3 个回答

登录 后发表内容