将PHP脚本反向工程到Google Appscript(Javascript)
我有一个问题,反向工程的php脚本与谷歌电子表格。首先,我将向您展示原始php代码,然后向您展示我的解决方案。在这一点上,我没有迹象表明我的代码有什么问题 1原始php代码。来源:bittrex.com/Home/Api将PHP脚本反向工程到Google Appscript(Javascript),javascript,php,json,google-apps-script,Javascript,Php,Json,Google Apps Script,我有一个问题,反向工程的php脚本与谷歌电子表格。首先,我将向您展示原始php代码,然后向您展示我的解决方案。在这一点上,我没有迹象表明我的代码有什么问题 1原始php代码。来源:bittrex.com/Home/Api $apikey='xxx'; $apisecret='xxx'; $nonce=time(); $uri='https://bittrex.com/api/v1.1/market/getopenorders?apikey='.$apikey.'&nonce='.$non
$apikey='xxx';
$apisecret='xxx';
$nonce=time();
$uri='https://bittrex.com/api/v1.1/market/getopenorders?apikey='.$apikey.'&nonce='.$nonce;
$sign=hash_hmac('sha512',$uri,$apisecret);
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('apisign:'.$sign));
$execResult = curl_exec($ch);
$obj = json_decode($execResult);
2反向工程的google appscript代码只是1的纯Javascript
/* Generate Nonce */
function nonceGen() {
var d = new Date();
var timeStamp = d.getTime();
return timeStamp;
}
/* Encode with standard HMAC-SHA512 */
function signKey(url, secret) {
var signature = Utilities.base64Encode(Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_512, url, secret));
return signature;
}
function getBalances(apik, apis) {
/* Set important variables */
var url = 'https://bittrex.com/api/v1.1/account/getbalances';
var inputapikey = '?apikey=';
var inputnonce = '&nonce=';
var nonce = nonceGen();
/* Bring it all together */
var uri = url.concat(inputapikey).concat(apik).concat(inputnonce).concat(nonce);
/* Sign the message */
var sign = signKey(uri,apis);
/* Set apisign as header */
var headers = { 'apisign' : sign };
var options = { 'method' : 'get', 'headers' : headers };
/* Retrieve response and parse the json into the data variable */
var response = UrlFetchApp.fetch(uri, options);
var data = JSON.parse(response.getContentText());
/* Output on screen */
Logger.log(data);
}
我似乎不明白问题出在哪里。屏幕上似乎根本没有输出。甚至一个错误都没有。希望我能得到一些错误测试建议。我不确定这行代码是否适用于JavaScript:
/* Bring it all together */
var uri = url.concat(inputapikey).concat(apik).concat(inputnonce).concat(nonce);
JavaScript中的字符串连接是用加号完成的
尝试:
也许您应该开始制作一些输出或控制台日志,以查看脚本中实际发生的情况。还可以查看开发工具,以查看请求是否正确以及是否得到预期的响应。Apps script.gs脚本文件使用Logger.log'some text:'+myVariable;将输出打印到日志。使用View、Log查看输出。或者您可以选择一个函数,然后单击该bug来运行调试器。
var uri = inputapikey + apik + inputnonce + nonce;