Blockchain.info

回調在使用區塊鏈 api 的程序中不起作用

  • March 11, 2017

我正在嘗試通過 Blockchain API 創建自動接收比特幣付款。我有我的 API 密鑰、xpub 和一切。我正在使用 PHP。

這是我生成錢包地址的部分程式碼:

$scrt = my_super_secret_code_60_chars_long;
$my_callback_url = "http://mysite.com/lib/payment.php?secret={$scrt}";
$my_xpub = "my_xpub_key";
$my_api_key = "my_secret_api_key";

$root_url = "https://api.blockchain.info/v2/receive";
$parameters = "xpub=" .$my_xpub. "&callback=" .urlencode($my_callback_url). "&key=" .$my_api_key;


$qry= "SELECT ID,RECEIVE_ADDR FROM MY_TABLE WHERE WALLET = '{$_GET['wallet']}' ";
$result = mysqli_query($conn,$qry);
$row = mysqli_fetch_row($result);
$reci = $row[1];
$uid = $row[0];
if ($reci=='none') {
//if the user does not have generated receive address, triggering this
$response = file_get_contents($root_url . '?' . $parameters);
$object = json_decode($response);

echo 'Send Payment To : ' . $object->address;

$qry= "UPDATE MY_TABLE SET RECEIVE_ADDR='". $object->address ."' WHERE WALLET = '{$_GET['wallet']}' ";
mysqli_query($conn,$qry);   
} 

此程式碼有效,但我對payment.php. 收到付款時不會觸發,但是手動,我可以通過使用正確參數呼叫 PHP 來模擬收到的付款。

以下是相關部分payment.php

<?php
$scrtt = $_GET['secret']; //password is passed back to the callback URL
$transaction_hash = $_GET['transaction_hash'];
$value_in_satoshi = $_GET['value'];
$value_in_btc = $value_in_satoshi / 100000000;

$gt='CALLBACK CALLED - TXID:'.$transaction_hash.' VALUE '.$value_in_satoshi.' SCRT:'.$scrtt.' CONFIRMS:'.$_GET['confirmations'];
$qry= "INSERT INTO DEBUG (TE) VALUES ('{$gt}')";
mysqli_query($conn,$qry);
//code above is for debugging - but not triggered however payment is received
if ($scrtt== my_super_secret_code) {
if ($_GET['confirmations'] >= 2) {
$confirms=$_GET['confirmations'];   
$qry= "SELECT ID FROM MY_TABLE WHERE RECEIVE_ADDR = '{$_GET['address']}'";

$result = mysqli_query($conn,$qry);
$row = mysqli_fetch_row($result);
$uid = $row[0];

$qry= "SELECT TXHASH FROM PAYMENTS WHERE TXHASH = '{$_GET['transaction_hash']}' ";

$result = mysqli_query($conn,$qry);
$row = mysqli_fetch_row($result);
$tx = $row[0];

if ($tx <> $transaction_hash) {

   $qry="INSERT INTO PAYMENTS (TXHASH,USER_ID,SATS,CONFIRMS) VALUES ('{$transaction_hash}',{$uid},{$value_in_satoshi},{$confirms})";
mysqli_query($conn,$qry);       

//new tx - insert   
}

//Insert into confirmed payments

} 
}
echo '*ok*';
?>

我的問題是,回調永遠不會被呼叫——誰能檢查我的程式碼並告訴我問題出在哪裡?

謝謝

更新:

我調查了一下,這是我的結果(但它仍然不起作用)

我找到了直接在區塊鏈上檢查回調日誌的 url: https ://api.blockchain.info/v2/receive/callback_log?callback=http-urlencoded_my_website/callback.php?parameters&key=my-api-key

日誌向我顯示了類似的內容:

callback":"http://mysite.com/callback.php?param=myparam","called_at":"2017-03-10T13:05:39Z","response_code":403,"raw_response":"<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n<title>403 Forbidden</title>\n</head><body>\n<h1>Forbidden</h1>\n<p>You don't have permission to access /callback.php\non this server.<br />\n</p>\n<p>Additionally, a 403 Forbidden\nerror was encountered while trying to use an ErrorDocument to handle the request.</p>\n</body></html>\n"}]

有人可以幫我嗎?我是這個域的所有者,我可以使用我所有的瀏覽器訪問這個頁面。

解決方案:

從我網頁上的 /public_html 中刪除 .htaccess 文件後,它開始工作了..如此簡單的解決方案..

我認為它也可以通過一些重新配置來完成,但我沒有使用.htaccess,所以它對我來說是最簡單的解決方案:)

引用自:https://bitcoin.stackexchange.com/questions/51980