微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

尝试在 cfgroovy

如何解决尝试在 cfgroovy

我知道 cfgroovy 似乎是死项目,但我试图在 cfgroovy 上运行 PHP 代码但它不起作用,如果我在我的 xampp 服务器中运行 PHP 代码,它运行良好,但是当我运行时cfgroovy 中的 PHP 代码,我得到一个无效的: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#">

我得到的错误是这个

https://prnt.sc/xibngw

我缩小了问题的范围,这似乎是一个问题

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 举报,一经查实,本站将立刻删除。