如何解决Coinbase Pro API 无效签名 ColdFusion
我试图从 Coinbase Pro 获取简单的帐户信息,但似乎无法弄清楚 CB-ACCESS-SIGN 标头。我不断收到“无效签名”消息。
来自 Coinbase Pro API 文档:
CB-ACCESS-SIGN 标头是通过使用以下方法创建 sha256 HMAC 生成的 prehash 字符串时间戳 + 方法上的 base64 解码密钥
- requestPath + body(其中 + 表示字符串连接)并对输出进行 base64 编码。时间戳值与 CB-ACCESS-TIMESTAMP 标头。
body为请求正文字符串,无请求时省略 正文(通常用于 GET 请求)。
方法应该是大写。
我的代码:
<cfscript>
accessKey = 'xxx';
passphrase = 'yyy';
theSecret = 'zzz';
// create an epoch time stamp
theTime = Now();
utcTime = dateConvert('local2UTC',theTime);
ISOtimeStamp = dateFormat(utcTime,"yyyy-mm-dd")&"T"&timeFormat(utcTime,"HH:mm:ss")&".761Z";
timeStamp = numberFormat(dateDiff("s","January 1 1970 00:00",ISOtimeStamp) + 28800.761,"_.000");
requestPath = '/accounts';
theBody = "";
method = "GET";
// create the prehash string by concatenating required parts
what = '#timeStamp#' & '#method#' & '#requestPath#' & '#theBody#';
// decode the base64 secret
theKey = binaryDecode(theSecret,"base64");
// create s sha256 hmac with the key
theHmac = hmac("#what#","#theKey#","HMACSHA256");
// encode the result
cas = toBase64(theHmac);
</cfscript>
<cfhttp url="https://api.pro.coinbase.com/v2/accounts" method="get" result="y">
<cfhttpparam type="header" name="CB-ACCESS-KEY" value="#accessKey#" >
<cfhttpparam type="header" name="CB-ACCESS-SIGN" value="#ucase(cas)#" >
<cfhttpparam type="header" name="CB-ACCESS-TIMESTAMP" value="#timeStamp#" >
<cfhttpparam type="header" name="CB-ACCESS-PAsspHRASE" value="#passphrase#" >
</cfhttp>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。