跳到主要内容

请求返回InvalidAuthHeader

可能原因:

  1. 没有使用和文档中台配置中相同的secret

  2. 计算token时使用的值和实际发送的不同,包括timeStamp、zOffice-message-nonce、请求体

  3. 计算token时和发送请求时请求体序列化结果不一致。例如,如果使用map构建请求体,spring默认使用jackson序列化map,那么就需要使用jackson序列化的字符串计算token。

  4. 使用org.apache.http.entity.StringEntity封装请求体,未指定Content-Type,导致客户端和服务端计算auth头时的请求体不同

    StringEntity jsonEntity = new StringEntity(body, ContentType.APPLICATION_JSON); // UTF-8编码
    StringEntity htmlEntity = new StringEntity(body); // ISO-8859-1编码
  5. Content-Type没有设置为application/json,openApi只接受json格式的请求体。