php - 尝试在 cfgroovy 上使用 Coldfusion 运行 PHP 代码
问题描述
我知道 cfgroovy 似乎是死项目,但我试图在 cfgroovy 上运行 php 代码但它不起作用,如果我在我的 xampp 服务器中运行 PHP 代码,它运行良好,但是当我运行该 php 代码时在 cfgroovy 中,我得到一个无效:nonce 错误
这是我在 cfgroovy 中的代码
php代码是这样的:
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', $path . hash('sha256', $request['nonce'] . $postdata, true), 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
解决方案
推荐阅读
- javascript - 如何在下面的代码中添加小数
- typescript - 如何指定回调函数的类型?
- scala - (Scala)我是否正确使用选项?
- java - Android 获取一个Layout拥有的所有children(包括Sub-childs)
- javascript - Ionic3 - 如何通过 ShareProvider 将数据从主页发送到另一个 ts 文件
- java - Maven:当shade将项目打包到jar时,如何删除本地覆盖类并使用依赖项中的原始类进行编译
- linker - 为什么将我自己的 C 库文件放入 ld 搜索路径不起作用?
- r - 数据框创建观察而不是变量
- android - 通知服务
- emacs - Emacs OSX 10.13 配置问题