自分なりに色々調べたのですが解らず質問させていただきます。
このWEB APIを使いたく
https://developers.quoine.com/#authentication
色々試行錯誤しております。
サンプルソースがRubyでPHPで使用したいので自分なりに変更してみましたがうまくいかないのでご協力をお願いします。
error内容
1error内容 2Fatal error: Uncaught exception 'DomainException' with message 'Algorithm not supported' in 3/home/ubuntu/workspace/vendor/firebase/php-jwt/src/JWT.php on line 191 DomainException: Algorithm not supported in 4/home/ubuntu/workspace/vendor/firebase/php-jwt/src/JWT.php on line 191 Call Stack: 0.0015 236392 1. {main}() 5/home/ubuntu/workspace/quoinex_balance.php:0 0.0143 270496 2. Firebase\JWT\JWT::encode() /home/ubuntu/workspace/quoinex_balance.php:31 0.0144 272128 3. Firebase\JWT\JWT::sign() /home/ubuntu/workspace/vendor/firebase/php-jwt/src/JWT.php:170
以下サンプルコード
Ruby
1require 'uri' 2require 'net/http' 3require 'time' 4require 'jwt' 5 6uri = URI.parse("https://api.quoine.com") 7http = Net::HTTP.new(uri.host, uri.port) 8http.use_ssl = true 9 10token_id = 'YOUR_API_TOKEN_ID' 11user_secret = 'YOUR_API_SECRET' 12path = '/orders?product_id=1' 13 14auth_payload = { 15 path: path, 16 nonce: DateTime.now.strftime('%Q'), 17 token_id: token_id 18} 19 20signature = JWT.encode(auth_payload, user_secret, 'HS256') 21 22request = Net::HTTP::Get.new(path) 23request.add_field('X-Quoine-API-Version', '2') 24request.add_field('X-Quoine-Auth', signature) 25request.add_field('Content-Type', 'application/json') 26 27response = http.request(request)
以下、PHPで私が書いたコード
php
1<?php 2// https://developers.quoine.com/#authentication の仕様書に従い 3//JSON Web Tokenを使用する 4//composerをインストール(今回はWEBROOTの場所にインストール) 5//linuxでコマンド入力$ curl -sS https://getcomposer.org/installer | php -- --filename=composer 6//linuxでコマンド入力$ php composer require firebase/php-jwt 7include('./vendor/autoload.php'); 8 9//ライブラリーを読み込む 10use \Firebase\JWT\JWT; 11 12//API取得して入力(お金がないっていないので本物のコードです) 13$key = '309637'; 14$secret = 'iUbiLYh1UFY5tMOF0D2A3bCpcI7ksSPBoQ3QkM1SfgL7TMa3IJ6ew8ooVfA3GpteE6+9JA7Tmb6XiqJ+7yMtTQ=='; 15 16// URL作成 17$base_url = 'https://api.quoine.com'; 18$order_url = '/accounts/balance'; 19$url = $base_url . $order_url; 20$version = '2'; 21 22//ヘッダー情報作成 23$timestamp = time() . substr(microtime(), 2, 3); 24$method = 'POST'; 25 26$jwt = JWT::encode('path:' .$order_url,'nonce:' .$timestamp,'token_id:' .$key); 27$sign = JWT::decode($jwt, $secret, array('HS256')); 28 29//確認用 30print_r($sign."<br>"); 31 32$header = array( 33 'X-Quoine-API-Version:' . $version, 34 'X-Quoine-Auth:' . $sign, 35 'Content-Type:application/json', 36 //'Content-Length:'. strlen($body), 37); 38 39//確認用 40print_r($header); 41$context = stream_context_create(array( 42 'http' => array( 43 'method' => $method, 44 'header' => implode(PHP_EOL, $header), 45 // 'content' => $body, 46 ) 47)); 48 49// API呼び出し 50$response = file_get_contents($url, false, $context); 51$result = json_decode($response, true); 52print_r($result);

回答1件
あなたの回答
tips
プレビュー