You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ebay API数字签名报错215113:签名参数时间戳无效

解决Ebay API签名错误215113:Invalid timestamp in signature parameters

以下是针对代码中存在的问题的具体修复步骤:

1. 修正签名组件的定义方式

你当前的coveredComponents错误地将完整键值对(如@method: GET)作为组件名称,而HTTP签名规范要求组件仅保留标识符(如@method),实际值需单独存储用于构建签名基串。修改代码如下:

// 仅保留组件标识符
var coveredComponentNames = new List<string> { "@method", "@path", "@authority", "@content-digest", "content-type" };
// 存储每个组件的实际值
var componentValues = new Dictionary<string, string>
{
    { "@method", method },
    { "@path", path },
    { "@authority", authority },
    { "@content-digest", ComputeContentDigest(payload) },
    { "content-type", contentType }
};

2. 重构签名基串生成逻辑

原CreateSignatureBase方法的@signature-params格式不符合规范,需要修正为包含算法标识、正确的组件列表格式:

private static string CreateSignatureBase(Dictionary<string, string> componentValues, long created, string keyId, List<string> componentNames)
{
    var sb = new StringBuilder();
    // 按顺序添加每个组件的键值对
    foreach (var name in componentNames)
    {
        sb.AppendLine($"{name}: {componentValues[name]}");
    }
    // 构建符合规范的@signature-params
    string coveredComponentsStr = string.Join(" ", componentNames);
    sb.AppendLine($"@signature-params: (created={created}; keyid=\"{keyId}\"; alg=\"ed25519\"; covered={coveredComponentsStr})");
    return sb.ToString().TrimEnd();
}

调用时改为:

string signatureBase = CreateSignatureBase(componentValues, timestamp, keyId, coveredComponentNames);

3. 修正Signature-Input请求头

请求头中的Signature-Input必须使用组件标识符,而非完整键值对,同时需指定签名算法:

request.Headers.Add("Signature-Input", $"sig1=({string.Join(" ", coveredComponentNames)});created={timestamp};keyid=\"{keyId}\";alg=\"ed25519\"");

4. 验证系统时间同步

确保你的本地系统时间与UTC时间偏差不超过5分钟(Ebay API对时间戳的有效窗口通常为±5分钟),若系统时间偏差过大,即使格式正确也会触发该错误。

5. 可选:移除GET请求的冗余Content

GET请求通常不需要携带请求体,可移除以下代码,避免不必要的头信息干扰:

var content = new StringContent(payload, Encoding.UTF8, contentType);
request.Content = content;

内容的提问来源于stack exchange,提问作者user25788528

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 19:43:14