2017-08-16 176 views
-2

我正在使用API​​ 並將變量傳遞給API的函數,但在此情況下它的工作原理如下: curl_init('https://www.coinpayments.net/api.php?txid=123456');如何在函數內傳遞一個變量?

我想通過一個變量傳遞TxID添加價值,我盡我所能,但上面的功能不受以下方式運行:

$value="https://www.coinpayments.net/api.php?txid=".$txnid; 

     curl_init($value); 

    curl_init('https://www.coinpayments.net/api.php?txid=$txnid'); 
    curl_init('https://www.coinpayments.net/api.php?txid='$txnid''); 
    curl_init("https://www.coinpayments.net/api.php?txid='".$txnid."'"); 
    curl_init("https://www.coinpayments.net/api.php?txid=$txnid"); 
+1

什麼是不工作? – ArtOsi

+1

'$ value =「https://www.coinpayments.net/api.php?txid=」。$ txnid;'這看起來很好。什麼是你得到的錯誤 – Thamaraiselvam

+1

curl_init(「https://www.coinpayments.net/api.php?txid=$txnid」);應該在技術上工作 –

回答

0

當我使用的瀏覽器 火上面API URL它顯示錯誤

API requests can only be made via POST. For documentation see: https://www.coinpayments.net/apidoc 

所以你必須使用下面的代碼來傳遞變量作爲之後的參數

<?php 

$curl = curl_init(); 

curl_setopt_array($curl, array(
    CURLOPT_URL => "https://www.coinpayments.net/api.php", 
    CURLOPT_RETURNTRANSFER => true, 
    CURLOPT_CUSTOMREQUEST => "POST", 
    CURLOPT_POSTFIELDS => "{'txn_id':".$txn_id."}", 
    CURLOPT_HTTPHEADER => array(
    "cache-control: no-cache", 
    "content-type: application/json" 
), 
)); 

$response = curl_exec($curl); 
$err = curl_error($curl); 

curl_close($curl); 

if ($err) { 
    echo "cURL Error #:" . $err; 
} else { 
    echo $response; 
} 
?> 

我接到了上面的URL響應當我使用上面的代碼

{ 
    "error": "No HMAC signature sent", 
    "result": [] 
} 
相關問題