简体   繁体   English

将PHP脚本反向工程为Google Appscript(Javascript)

[英]Reverse engineering PHP script to Google Appscript (Javascript)

I have a problem with reverse engineering a php script to work with google spreadsheet. 我在反向工程中使用PHP脚本与Google电子表格一起工作时遇到问题。 First I will show you the original php code and then show you my solution. 首先,我将向您展示原始的php代码,然后向您展示我的解决方案。 At this point I have no indication as to what is wrong with my code. 在这一点上,我没有迹象表明我的代码有什么问题。


1 Original php code. 1原始的php代码。 Source: bittrex.com/Home/Api 资料来源:bittrex.com/Home/Api

$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 Reverse engineered google appscript code (just pure Javascript) of 1. 2个反向工程的Google appscript代码(仅是纯Javascript),为1。

/* 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);  
 }

I can't seem to figure out what the problem is. 我似乎无法弄清楚问题出在哪里。 There seems to be no output on the screen at all. 屏幕上似乎根本没有输出。 Not even an error. 甚至没有错误。 Hopefully I can get some bugtesting suggestions. 希望我能得到一些调试建议。

I'm not sure if this line will work in JavaScript: 我不确定这行是否可以在JavaScript中使用:

/* Bring it all together */
var uri = url.concat(inputapikey).concat(apik).concat(inputnonce).concat(nonce);

String concatenation in JavaScript is done with the plus sign. JavaScript中的字符串串联使用加号完成。

Try: 尝试:

var uri = inputapikey + apik + inputnonce + nonce;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM