0

我目前正在建立一个网站,该网站将提供客户可以用狗狗币支付的服务。我正在使用 DogeAPI 和这些示例结帐脚本来尝试构建我的结帐页面。

问题是我无法让地址 ($new_address) 回显到页面。当我运行脚本时,只显示“请支付 1000 DOGE 以接收您的物品。确认您的付款最多可能需要 10 分钟。” 当我在 DogeAPI 上登录仪表板时,它没有显示任何地址已创建。

我有一种感觉,我需要某种代码来等待 file_get_ contents() 完成,然后开始 JSON 解码。我的代码如下。

注意:我的代码中确实有 API 密钥,我只是在此处发布代码之前将其删除。

//set to your API_KEY
$api_key = 'MY API HERE';

//set this to your users id
//must be alphanumeric only
$user_id = 'test123';

//set this to the amount the item costs
$amount_doge = '1000';

//send a request to the API to make a new payment address
//put info about the request in
$response = file_get_contents("https://www.dogeapi.com/wow/?api_key=$api_key&a=get_new_address&address_label=$user_id");

if($response !== 'Bad Query' && $response !== '') {
    $new_address = json_decode($response);
    //insert the new pending payment
    mysql_query("INSERT INTO `api_payments`
                           (`payment_label`,`payment_address`,`paid`,`amount`)
                    VALUES ('$user_id', '$new_address', '0', '$amount_doge')");

    //give them the address or echo a widget here
    //for this example we will just echo an address
    echo "Please pay $amount_doge DOGE to $response to receive your item. It may take up to 10 minutes to confirm your payment.";

} else {
    echo 'There was a problem processing your order.';
}
4

0 回答 0