function xchange796_query($appid, $apikey, $secretkey, $url) { // from https://796.com/wiki.html $timestamp = time(); $params = array('appid' => $appid, 'apikey' => $apikey, 'secretkey' => $secretkey, 'timestamp' => $timestamp); ksort($params); // "be careful that the sequence is quite important" $param_uri = http_build_query($params, '', '&'); $sig = base64_encode(hash_hmac('sha1', $param_uri, $secretkey)); $token_url = url_add("https://796.com/oauth/token", array('appid' => $appid, 'timestamp' => $timestamp, 'apikey' => $apikey, 'secretkey' => $secretkey, 'sig' => $sig)); // our curl handle (initialize if required) $ch = crypto_curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; 796 PHP client; ' . php_uname('s') . '; PHP/' . phpversion() . ')'); curl_setopt($ch, CURLOPT_URL, crypto_wrap_url($token_url)); // curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // run the query $res = curl_exec($ch); if ($res === false) { throw new ExternalAPIException('Could not get reply: ' . curl_error($ch)); } $dec = crypto_json_decode($res, "in authentication"); if (isset($dec['errno']) && $dec['errno']) { throw new ExternalAPIException("Could not get OAuth Token: " . htmlspecialchars($dec['msg'])); } if (!isset($dec['data']['access_token'])) { throw new ExternalAPIException("No access token provided"); } $token = $dec['data']['access_token']; crypto_log("Obtained OAuth token"); // now, call the given URL // 796 has a bug where the token can't be urlencoded again, so we can't use url_add() (though we should) $destination_url = $url . "?access_token=" . $token; // our curl handle (initialize if required) $ch = crypto_curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; 796 PHP client; ' . php_uname('s') . '; PHP/' . phpversion() . ')'); curl_setopt($ch, CURLOPT_URL, crypto_wrap_url($destination_url)); // curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // run the query $res = curl_exec($ch); if ($res === false) { throw new ExternalAPIException('Could not get reply: ' . curl_error($ch)); } $dec = crypto_json_decode($res, "in request"); if (isset($dec['errno']) && $dec['errno']) { throw new ExternalAPIException("Error in reply: " . htmlspecialchars($dec['msg'])); } if (!isset($dec['data'])) { throw new ExternalAPIException("No data in reply"); } return $dec['data']; }
function cryptostocks_api($key, $email, $method) { $token_id = rand(0, 0xffff); $request_time = time(); $token = $key . ";" . $email . ";" . $request_time . ";" . $token_id . ";" . $method; $url = url_add("https://cryptostocks.com/api/" . urlencode($method) . ".json", array('account' => $email, 'id' => $token_id, 'token' => hash('sha256', $token), 'timestamp' => $request_time)); $content = crypto_get_contents(crypto_wrap_url($url)); if (!$content) { throw new ExternalAPIException("API returned empty data"); } $data = crypto_json_decode($content); return $data; }
/** * Basic tests for {@link #url_add()} using absolute URLs. */ function testUrlAddAbsolute() { $this->assertEquals("http://openclerk.org/url", url_add('http://openclerk.org/url', array())); $this->assertEquals("http://openclerk.org/url?key=bar", url_add('http://openclerk.org/url', array('key' => 'bar'))); $this->assertEquals("http://openclerk.org/url?key=bar&bar=foo", url_add('http://openclerk.org/url', array('key' => 'bar', 'bar' => 'foo'))); }
<?php if (strtotime($user['created_at']) >= strtotime("-1 hour") || require_get("welcome", false)) { ?> <div class="success"> <ul> <li><?php echo t("Welcome to :site_name!"); ?> </li> <li><?php echo t("To get started, first select the currencies that you are interested in below, and then follow the wizards to configure your addresses, accounts and reports."); ?> </li> <li><?php echo t("If you have any problems in getting set up, please send us :email or tweet :twitter.", array(':email' => link_to(url_add('mailto:' . get_site_config('site_email'), array('subject' => 'Problems Signing Up')), t("an e-mail")), ':twitter' => '<a class="twitter" href="https://twitter.com/cryptfolio">@cryptfolio</a>')); ?> </li> </ul> </div> <?php /* trafficvance conversion tracking pixel for Dennis */ ?> <script type="text/javascript" src="http://tracking.trafficvance.com/?id=1G18D7G6C0EG334F874F&fetch=0&value=0"> </script> <noscript><div style="display: inline;"><img height="1" width="1" style="border-style: none;" alt="" src="http://tracking.trafficvance.com/?id=1G18D7G6C0EG334F874F&fetch=1&value=0" /></div></noscript> <?php } ?>
<?php /** * Openclerk version check job. */ $exchange = "version_check"; crypto_log("Local version: " . get_site_config('openclerk_version')); // call cryptfolio.com to find the latest openclerk.org version $version = crypto_get_contents(crypto_wrap_url(url_add('https://cryptfolio.com/version', array('absolute_url' => get_site_config('absolute_url'), 'openclerk_version' => get_site_config('openclerk_version'))))); crypto_log("Remote version: " . $version); if (!$version) { throw new ExternalAPIException("Could not retrieve remote Openclerk version"); } // compare if (version_compare($version, get_site_config('openclerk_version')) > 0) { // delete any unread messages $q = db()->prepare("DELETE FROM admin_messages WHERE message_type=? AND is_read=0"); $q->execute(array('version_check')); // and insert a new one $q = db()->prepare("INSERT INTO admin_messages SET message_type=?, message=?"); $q->execute(array('version_check', '<a href="http://openclerk.org">A new version</a> of Openclerk is available: ' . $version)); crypto_log("Inserted new admin_message."); }
/** * * @throws {@link DifficultyException} if something happened and the balance could not be obtained. */ function getDifficulty(Logger $logger) { $url = "https://blockchain.info/q/getdifficulty"; if (Config::get('blockchain_api_key', false)) { $logger->info("Using Blockchain API key."); $url = url_add($url, array('api_code' => Config::get('blockchain_api_key'))); } $logger->info($url); $value = Fetch::get($url); if (!is_numeric($value)) { $logger->error("Difficulty is non-numeric: " . htmlspecialchars($value)); throw new BlockException("Blockchain returned non-numeric value: '" . htmlspecialchars($value) . "'"); } else { $logger->info("Difficulty : " . $value); } return $value; }