问题描述
我知道 cfgroovy 似乎是死项目,但我试图在 cfgroovy 上运行 PHP 代码但它不起作用,如果我在我的 xampp 服务器中运行 PHP 代码,它运行良好,但是当我运行时cfgroovy 中的 PHP 代码,我得到一个无效的:nonce 错误
这是我在 cfgroovy 中的代码
https://github.com/payward/kraken-api-client
这是我在 CF 中使用 cfgroovy 的代码,我在 Coldfusion 目录中安装了最新的 querbus JAr 文件以使其工作
<cftry>
<g:script lang="PHP">
<?PHP
$key = 'APIKEY';
$secret = 'APISECRET';
$request = array();
if(!isset($request['nonce'])) {
$nonce = explode(' ',microtime());
$request['nonce'] = $nonce[1] . str_pad(substr($nonce[0],2,6),6,'0');
}
$pspostdata = http_build_query($request,'','&');
$variables["postdata"] = $request['nonce'] . $pspostdata;
$version = '0';
$method = 'TradeBalance';
$path = '/' . $version . '/private/' . $method;
$sign = hash_hmac('sha512',$path . hash('sha256',$variables["postdata"] . $pspostdata,true),base64_decode($secret),true);
$variables["myArray"] = base64_encode($sign);
$headers = array(
'API-Key: ' . $key,'API-Sign: ' . base64_encode($sign)
);
$cl = curl_init();
curl_setopt_array($cl,array(
CURLOPT_SSL_VERIFYPEER => true,CURLOPT_SSL_VERIFYHOST => 2,CURLOPT_USERAGENT => 'Kraken PHP API Agent',CURLOPT_POST => true,CURLOPT_RETURNTRANSFER => true)
);
// make request
curl_setopt($cl,CURLOPT_URL,'https://api.kraken.com' . $path);
curl_setopt($cl,CURLOPT_POSTFIELDS,$pspostdata);
curl_setopt($cl,CURLOPT_HTTPHEADER,$headers);
$variables["results"] = curl_exec($cl);
// decode results
//$variables["myArray"] = json_decode($variables["results"],true);
?>
</g:script>
<cfhttp url="https://api.kraken.com/0/private/TradeBalance" method="POST" result="result">
<cfhttpparam name="API-Key" type="HEADER" value="#key#">
<cfhttpparam name="API-Sign" type="HEADER" value='#variables["myArray"]#'>
</cfhttp>
<cfdump var="#variables#">
<cfdump var="#result#">
我得到的错误是这个
我缩小了问题的范围,这似乎是一个问题
hash_hmac('sha512',$request['nonce'] . $postdata,base64_decode($this->secret),true);
使用我下载的 jar 和正在使用的 xampp,我使用的是 xampp 3.3.2 版
我的是:xampp : 7.025 和 querbus jar 适用于 5.4.0 - 如果我修复了 hash_hmac 函数,我该如何在 PHP 版本 5.4.0 或我 Coldfusion 中进行
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)