贝宝 Return ?PayerID=

PayPal Return ?PayerID=

PayPal return index.php?PayerID=N3QKU3H2STQZN 付款完成后,我的函数 addCash 被忽略。

它在以前的网络服务器上工作(已删除),我不知道 php.ini

上是否缺少任何扩展

系统信息 Centos 7 +PHP 版本 7.4.28

Header.php

$paypal_email = getJsonSettings("paypal");

支付完成后执行的函数AddCash。

function addCash($account_id, $coins)
    {
        global $database;

        $stmt = $database->runQueryAccount("UPDATE user SET credit = credit + ? WHERE id = ?");
        $stmt->bindParam(1, $coins, PDO::PARAM_INT);
        $stmt->bindParam(2, $account_id, PDO::PARAM_INT);
        $stmt->execute();
    }

函数donate.php

<?php
    $jsondataDonate = file_get_contents('include/db/donate.json');
    $jsondataDonate = json_decode($jsondataDonate, true);
    
    $jsondataCurrency = file_get_contents('include/db/currency.json');
    $jsondataCurrency = json_decode($jsondataCurrency,true);
    
    if(isset($_POST["method"]) && strtolower($_POST["method"])=='paypal' && isset($_POST['id']) && isset($_POST['type']))
    {
        $return_url = $site_url."index.php";
        $cancel_url = $site_url."index.php";
        $notify_url = $site_url."paypal.php";
        
        $querystring = '';
        $querystring .= "?business=".urlencode($paypal_email)."&";
        
        $price = $jsondataDonate[$_POST['id']]['list'][$_POST['type']];
        
        $querystring .= "item_name=".urlencode($jsondataDonate[$_POST['id']]['name'].' ['.$price['price'].' - '.$price['cash'].' Cash]')."&";
        $querystring .= "amount=".urlencode($price['price'])."&";
        $querystring .= "noshipping=1"."&";
        $querystring .= "cmd=".urlencode(stripslashes("_xclick"))."&";
        $querystring .= "no_note=".urlencode(stripslashes("1"))."&";
        $querystring .= "currency_code=".urlencode(stripslashes($price['currency']))."&";
        $querystring .= "bn=".urlencode(stripslashes("PP-BuyNowBF:btn_buynow_LG.gif:NonHostedGuest"))."&";
        $querystring .= "first_name=".urlencode(stripslashes(getAccountName($_SESSION['id'])))."&";
        
        $querystring .= "return=".urlencode(stripslashes($return_url))."&";
        $querystring .= "cancel_return=".urlencode(stripslashes($cancel_url))."&";
        $querystring .= "notify_url=".urlencode($notify_url)."&";
        $querystring .= "item_number=".urlencode($jsondataDonate[$_POST['id']]['name'].' ['.$price['price'].' - '.$price['cash'].' Cash]')."&";
        $querystring .= "custom=".urlencode($_SESSION['id']);
        
        $url = 'https://www.sandbox.paypal.com/cgi-bin/webscr'.$querystring;
        if(!headers_sent()) {
            header('Location: '.$url);
            exit;
        } else {
            echo '<script type="text/javascript">';
            echo 'window.location.href="'.$url.'";';
            echo '</script>';
            echo '<noscript>';
            echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
            echo '</noscript>';
            exit;
        }
        
        exit();
    }
?>

paypal.php

 <?php
    include 'include/functions/header.php';

    if (isset($_POST["txn_id"]) && isset($_POST["txn_type"]) && isset($_POST["item_name"]) && isset($_POST["item_number"]) && isset($_POST["payment_status"]) && isset($_POST["mc_gross"])&& isset($_POST["mc_currency"])&& isset($_POST["receiver_email"])&& isset($_POST["custom"]))
    {
        $req = 'cmd=_notify-validate';
        foreach ($_POST as $key => $value) {
            $value = urlencode(stripslashes($value));
            $value = preg_replace('/(.*[^%^0^D])(%0A)(.*)/i','%0D%0A',$value);// IPN fix
            $req .= "&$key=$value";
        }

        $data['item_name']          = $_POST['item_name'];
        $data['item_number']        = $_POST['item_number'];
        $data['payment_status']     = $_POST['payment_status'];
        $data['payment_amount']     = $_POST['mc_gross'];
        $data['payment_currency']   = $_POST['mc_currency'];
        $data['txn_id']             = $_POST['txn_id'];
        $data['receiver_email']     = $_POST['receiver_email'];
        $data['payer_email']        = $_POST['payer_email'];
        $data['custom']             = $_POST['custom'];

        $curl_result=$curl_err='';
        $ch = curl_init();
        //curl_setopt($ch, CURLOPT_URL,'https://www.sandbox.paypal.com/cgi-bin/webscr');
        curl_setopt($ch, CURLOPT_URL,'https://www.sandbox.paypal.com/cgi-bin/webscr');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
        curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
        curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($req)));
        curl_setopt($ch, CURLOPT_HEADER , 1);
        curl_setopt($ch, CURLOPT_VERBOSE, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);

        $curl_result = curl_exec($ch);
        $curl_err = curl_error($ch);
        curl_close($ch);
        
        if (strpos($curl_result, "VERIFIED")!==false && strtolower($data['receiver_email']) == strtolower($paypal_email)) {
            
            $jsondataDonate = file_get_contents('include/db/donate.json');
            $jsondataDonate = json_decode($jsondataDonate, true);
            
            foreach($jsondataDonate as $key => $donate)
                if(strtolower($donate['name'])=="paypal")
                    foreach($donate['list'] as $list)
                    {
                        $type = $donate['name'].' ['.$list['price'].' - '.$list['cash'].' Cash]';
                        if($type==$data['item_name'] && $list['price']==$data['payment_amount'] && $data['payment_currency']==$list['currency'])
                            addCash($data['custom'], $list['cash']);
                    }
        }
    }
?>

$type = $donate['name']; if($type==$data['item_name'] && $list['price']==$data['payment_amount'] && $data['payment_currency']==$list['currency']){ addCash($data['custom'], $list['cash']); }