Note that there are some explanatory texts on larger screens.

plurals
  1. POConvert Ruby Code To PHP (Vicurex API)
    text
    copied!<p>I'm stuck trying to convert some sample Ruby API code from <a href="https://vircurex.com/welcome/api?locale=en" rel="nofollow">https://vircurex.com/welcome/api?locale=en</a> to PHP. Here is the Ruby Code provided:</p> <pre><code>t = Time.now.gmtime.strftime("%Y-%m-%dT%H:%M:%S"); trx_id = Digest::SHA2.hexdigest("#{t}-#{rand}") user_name = "MY_USER_NAME" secret_word = "123456789" tok = Digest::SHA2.hexdigest("#{secret_word};#{user_name};#{t};#{trx_id};create_order;sell;10;btc;50;nmc") Order.call_https("https://vircurex.com", "/api/create_order.json?account=#{user_name}&amp;id=#{trx_id}&amp;token=#{tok}&amp;timestamp=#{t}&amp;ordertype=sell&amp;amount=10&amp;currency1=btc&amp;unitprice=50&amp;currency2=nmc") def self.call_https(my_url,my_params) uri = URI.parse(my_url) http = Net::HTTP.new(uri.host, '443') http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_PEER response="" resp="" http.start do |http| cmd = my_params req = Net::HTTP::Get.new(cmd) response = http.request(req) resp = response.body end return ActiveSupport::JSON.decode(resp) end </code></pre> <p>Here is what I attempted to come up with so far in PHP, but i know nothing of Ruby, so it is hard to figure out what the original code is doing:</p> <pre><code>date_default_timezone_set("UTC"); $t = date("Y-m-d H:i:s", time()); $trx_id = hash("sha256", $t."-".rand()); // i think this is wrong $user_name = "MY_USER_NAME"; $secret_word = "123456789"; $tok = hash("sha256", $secret_word.";".$user_name.";".$t.";".$trx_id.";create_order;sell;10;btc;50;nmc"); $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, "https://vircurex.com/api/create_order.json?account=$username&amp;id=$trx_id&amp;token=$tok&amp;timestamp=$t&amp;ordertype=sell&amp;amount=10&amp;currency1=btc&amp;unitprice=50&amp;currency2=nmc"); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); $resp = curl_exec($ch); return json_decode($resp); </code></pre> <p>Can someone familiar with both languages please help me out? Thanks!</p> <p>I get the following response with my code:</p> <pre><code>stdClass Object ( [status] =&gt; 8003 [statustxt] =&gt; Authentication failed ) </code></pre> <p>So obviously, something is not being translated correctly. I just need to generate some working PHP code to use with the API listed. You can create an account to test the code if you like.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload