faucetpay.io商户API处理回调数据时出现的问题

问题描述 投票:0回答:1

我目前正在配置我的网站,以利用来自 https://faucetpay.io/merchant 的 faucetpay.io 商家 API,其中还有一个简短的文档,不幸的是不够清晰。我联系了他们的支持,目前还没有回复。我在我的index.html中实现了以下内容:

<form action="https://faucetpay.io/merchant/webscr" method="post" autocomplete="off">
<input type="hidden" name="merchant_username" value="sanox">
<input type="hidden" name="item_description" value="RCP Webpage - buy 64 spesmilo points">
<input type="hidden" name="amount1" value="0.001">
<input type="hidden" name="currency1" value="USDT">
<input type="hidden" name="callback_url" value="https://example.com/callback.html">
<input type="hidden" name="success_url" value="https://example.com/callback.html">
<input type="hidden" name="cancel_url" value="https://example.com/index.html">
<input type="submit" class="w3-btn w3-purple" name="submit" value="Buy ₷64">

在我的callback.html中,我实现了以下内容:

<?php
error_reporting(E_ALL ^ E_DEPRECATED ^ E_WARNING ^ E_NOTICE);
header("Content-Type: text/html; charset=UTF-8");
require('res/config.php');
session_start();

if (isset($_SESSION['app'])) {
    $user = $_SESSION['app'];

// Debugging
var_dump($_POST); // Check the entire POST data

$token = $_POST['token'];
echo "Token: " . $token;

$payment_info = json_decode(file_get_contents("https://faucetpay.io/merchant/get-payment/" . $token), true);
$token_status = $payment_info['valid'];
$merchant_username = $payment_info['merchant_username'];
$my_username = "sanox";

if ($my_username == $merchant_username && $token_status) {
    // Processing logic when validation is successful
    mysql_query("UPDATE crypto_users SET points = points + 64 WHERE `email` = '$user'");
    echo 'Thank you. Payment processed. ₷64 added to your account!';
} else {
    echo "Invalid payment attempt. TokenID: " . $token;
    echo " Merchant Username: " . $merchant_username;
}
} else {
    die('Please login first!');
}
?> 

我注意到,在与我的其他用户 sanox1 进行测试时,他的账户中正确扣除了 0.001 USDT 的余额,并且我在我的商家账户 sanox 中看到了该交易。然而,在callback.html的输出中,所有变量例如$token、$merchant_username 等似乎为 null 或为空,我看到 array(0) { } 令牌:无效的付款尝试。代币ID: 商家用户名: 您能帮我理解为什么会发生这种情况吗?也许我没有正确传递令牌?另外我不太明白 https://faucetpay.io/merchanthttps://faucetpay.io/merchant/get- payment/

之间有什么联系

预先感谢您的协助。

php cryptoapi
1个回答
0
投票
<?php
// callback.php

// Retrieve the token from the URL parameters
$token = $_POST['token'];

// FaucetPay API endpoint
$apiEndpoint = "https://faucetpay.io/merchant/get-payment/$token";

// Make a GET request to FaucetPay API
$response = file_get_contents($apiEndpoint);

// Check if the request was successful and if the response is valid JSON
if ($response === false) {
    echo "Error fetching data from FaucetPay API.";
} else {
    $data = json_decode($response, true);

    if ($data === null) {
        echo "Error decoding JSON response from FaucetPay API.";
    } else {
        // Process the JSON response
        print_r($data);

        // Check if the payment is valid
        if ($data['valid']) {
            
 

                // Update the database if validation is successful
                $email = '[email protected]'; // Replace with your actual email field
                 

                // Your database connection code here
                $conn = new mysqli('localhost', 'user', 'pass', 'db');

                // Check the connection
                if ($conn->connect_error) {
                    die("Connection failed: " . $conn->connect_error);
                }

                // Prepare and execute the SQL statement
                $sql = "somesql here";
                if ($conn->query($sql) === TRUE) {
                    echo "Record updated successfully";
                }
            
            
            
 
        } else {
            echo "Invalid payment. Validation failed.";
        }
    }
}
?>

最后下面的callback.php对我有用。我根据faucetpay支持的建议使用https://webhook.site/进行了一些测试,然后在表单中从

<input type="hidden" name="callback_url" value="https://webhook.site/MY_ID">
更改为
<input type="hidden" name="callback_url" value="https://example.com/callback.php">

© www.soinside.com 2019 - 2024. All rights reserved.