php autobuy,将sql插入talbe(coinpayment)

qoefvg9y  于 2021-07-24  发布在  Java
关注(0)|答案(0)|浏览(188)

我有一个问题,我有以下代码,但我不能让它执行sql到我的网站后,购买完成。
下面的一个是purchase.php,它从数据库中获取数据并执行到不同的按钮,目前最重要的是#id(计划id)#concurrents等。。那是计划信息。

session_start();
$page = "Purchase";
include 'header.php';

    if(isset($_POST['shop']))
    {
        $id = $_POST['buyNow'];
        $concs = $_POST['concurrents'];
        $api = $_POST['api'];
        header('Location: payments/btcpaypal.php?id='.$id.'&concurrents='.$concs.'&api='.$api.'');
    }

?>
<main id="main-container">

<div class="block block-themed">
<div class="block-header">
<h3 style="color: white;" class="block-title"><center><i class="fa fa-shopping-cart"></i> Buy plan</h3></i>
<div class="block-options">
</div>
</div>
<div class="block-content-full">
<table class="table table-striped table-hover table-vcenter">
<thead>
<th class="text-center"><i class="fa fa-info text-danger"></i> Name</th>
<th class="text-center"><i class="fa fa-sitemap text-danger"></i> Network</th>
<th class="text-center"><i class="fa fa-dedent text-danger"></i> Concurrents</th>
<th class="text-center"><i class="fa fa-server text-danger"></i> Servers</th>
<th class="text-center"><i class="si si-clock text-danger"></i> Max stress Time</th>
<th class="text-center"><i class="si si-graph text-danger"></i> API</th>
<th class="text-center"><i class="fa fa-calendar text-danger"></i> Length</th>
<th class="text-center"><i class="fa fa-dollar text-danger"></i> Price</th>
<th class="text-center"><i class="fa fa-bitcoin text-danger"></i> BTC/PAYPAL</th>
</thead>
<tbody>
<?php
        $SQLGetPlans = $odb -> query("SELECT * FROM `plans` WHERE `private` = 0 ORDER BY `ID` ASC");
                                                while ($getInfo = $SQLGetPlans -> fetch(PDO::FETCH_ASSOC))
                                                {
                                    $id = $getInfo['ID'];
                                    $name = $getInfo['name'];
                                    $price = $getInfo['price'];
                                    $length = $getInfo['length'];
                                    $unit = $getInfo['unit'];
                                    $concurrents = $getInfo['concurrents'];
                                    $mbt = $getInfo['mbt'];
                                    $network = $getInfo['vip'];
                                    $api = $getInfo['api'];
                                    $totalservers = $getInfo['totalservers'];

                                    if($network == "0")
                                    {
                                        $network = '<b class="text-primary"> Normal</b>';
                                        $colorx = 'bg-body-light';

                                    }elseif($network == "1")
                                    {
                                        $network = '<span class="text-primary font-w700"></i> VIP </span>';
                                        $colorx = 'bg-primary';
                                    }
                                    if($api == "0")
                                    {
                                        $api = '<span class="text-primary font-w700"></i> No </i></span>';
                                    }elseif($api == "1")
                                    {
                                        $api = '<span class="text-primary font-w700"></i> Yes </i></span>';
                                    }
echo '
<tr>
<td class="text-center font-w700 h5 text-info"> '.$name.'</td>
<td class="text-center">'.$network.'</td>
<td class="text-center font-w700">'.$concurrents.'</td>
<td class="text-center font-w700">'.$totalservers.'</td>
<td class="text-center font-w700">'.$mbt.' seconds.</td>
<td class="text-center font-w700">'.$api.'</td>
<td class="text-center font-w700">'.htmlentities($length).' '.htmlspecialchars($unit).'</td>
<td class="text-center text-primary h5 font-w700">'.$price.'$</td>
<td class="text-center">
<a href="payments/btcpaypal.php?id='.$id.'&concurrents='.$concurrents.'&api='.$getInfo['api'].'"><button type="submit" name="shop" value="shop" class="btn btn-primary" >AUTOBUY</button></a>
</td>
</tr>
';
}
?>
</tbody>
</table>
</div>
</div>

                    </div> 
        </div>
</div>

<?php include('footer.php'); ?>

现在下一个是btcpaypal.php,它与coinpayments一起工作它工作它重定向到coinpayments放置正确的计划id正确的价格,所有都正确,但付款后它不会给它的用户。不执行此sql,它应该

<?php

    ob_start();
    session_start();
    require_once '../users/configuration.php';
    require_once '../users/init.php';

    if(isset($_GET['id']) && Is_Numeric($_GET['id']) && $user -> LoggedIn()){

        $id = (int)$_GET['id'];
        $row = $odb -> query("SELECT * FROM `plans` WHERE `ID` = '$id'") -> fetch();

        $concurrents = $_GET['concurrents'];
        $api = $_GET['api'];

        // 

        $planPrice = $row['price']; 

        // 

        $query = array(
            "cmd" => "_pay",
            "reset" => "1",
            "ipn_url" => "https://". $_SERVER['SERVER_NAME'] ."/payments/plan.php",
            "merchant" => "956cfdgfdgfdgdfg7e2a45d44",
            "item_name" => 'Game: ' . rand(5994, 19963), 
            "currency" => "USD",
            "amountf" => $planPrice,
            "quantity" => "1",
            "custom" => $id . "_" . $_SESSION['ID'],
            "allow_quantity" => "0",
            "want_shipping" => "0",
            "allow_extra" => "0" 
        );

        $header = "https://www.coinpayments.net/index.php?". http_build_query($query);
        header('Location: ' . $header);
        exit;

    }
    else{
        header('Location: home.php');
        exit;
    }

?>

这是我在ipnurl中输入的内容,也在btcpaypal.php中

<?php

    if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) {
        error_log("No marchenet or secret were set \n", 3, "error_log");
        die;
    }

    require_once '../user/configuration.php';
    require_once '../user/init.php';

    set_time_limit(0);

    if ($_SERVER['PHP_AUTH_USER'] != "956c8979bsdfdsfsdfdsfd44" || $_SERVER['PHP_AUTH_PW'] != "kofw34o0sdfsdfsdfsdo4i") {
        error_log("Marchenet or secret are incorrect \n", 3, "error_log");
        die;
    }

    if ($_POST['status'] < 100 && $_POST['status'] != 2) {
        error_log("Bad status \n", 3, "error_log");
        die;
    }

    if ($_POST['currency1'] != "USD") {
        error_log("Bad currency \n", 3, "error_log");
        die;
    }

    $orderId = $_POST['txn_id'];
    list($planID,$userID) = explode("_",$_POST['custom']);

    if (!is_numeric($planID) || !is_numeric($userID)) {
        die;
    }

    $SQL = $odb -> prepare("SELECT * FROM `plans` WHERE `ID` = :id");
    $SQL -> execute(array(':id' => $planID));
    $plan = $SQL -> fetch();
    $isvip = $plan["vip"];

    if ($_POST['amount1'] != $plan['price']) {
        error_log("Bad amount \n", 3, "error_log");
        die;
    }

    $SQL = $odb -> prepare("INSERT INTO `payments` VALUES(NULL, :ip, :planid, :transactionid, :status, :payer, UNIX_TIMESTAMP())");
    $SQL -> execute(array(':ip' => "::1", ':planid' => $planID, ':transactionid' => $orderId, ':transactionid' => "2", ':payer' => $_POST['email']));

    // Key Gen
    function generateRandomString($length = 10) {
        $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $charactersLength = strlen($characters);
        $randomString = '';
     for ($i = 0; $i < $length; $i++) {
            $randomString .= $characters[rand(0, $charactersLength - 1)];
         }
    return $randomString;
    }

    $string = generateRandomString();

    $unit = $plan['unit'];
    $length = $plan['length'];
    $newExpire = strtotime("+{$length} {$unit}");
    $updateSQL = $odb -> prepare("UPDATE `users` SET `expire` = :expire, `membership` = :plan, `avip` = :vip WHERE `ID` = :id");
    $updateSQL -> execute(array(':expire' => $newExpire, ':plan' => (int)$planID, ':id' => (int)$userID, ':vip' => $isvip));

 ?>

最后一个不执行sql计划不更新,会有什么问题?这是修改过的代码,我不太擅长php,我不能让它工作,如果有人能帮我我愿意付钱给你。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题