Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php OKPAY回调API更新数据库_Php - Fatal编程技术网

Php OKPAY回调API更新数据库

Php OKPAY回调API更新数据库,php,Php,好的,我正在使用OKPAY在支付完成时启动IPN回调,我已经使用测试工具发送成功支付的请求,但它没有更新我的信息 $market = isset($_GET['ok_txn_currency']) ? $_GET['ok_txn_currency'] : ''; $amount = isset($_GET['ok_txn_net']) ? $_GET['ok_txn_net'] : ''; $username = isset($_GET['username']) ? $_

好的,我正在使用OKPAY在支付完成时启动IPN回调,我已经使用测试工具发送成功支付的请求,但它没有更新我的信息

    $market = isset($_GET['ok_txn_currency']) ? $_GET['ok_txn_currency'] : '';
    $amount = isset($_GET['ok_txn_net']) ? $_GET['ok_txn_net'] : '';
    $username = isset($_GET['username']) ? $_GET['username'] : '';
    $status = isset($_GET['ok_txn_status']) ? $_GET['ok_txn_status'] : '';
    $txid = isset($_GET['ok_txn_id']) ? $_GET['ok_txn_id'] : '';


    // Read the post from OKPAY and add 'ok_verify' 
    $req = 'ok_verify=true'; 
    foreach ($_POST as $key => $value) {
        $value = urlencode(stripslashes($value));
        $req .= "&$key=$value";
    }
    // Post back to OKPAY to validate 
    $header .= "POST /ipn-verify.html HTTP/1.0\r\n"; 
    $header .= "Host: www.okpay.com\r\n"; 
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; 
    $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; 
    $fp = fsockopen ('www.okpay.com', 80, $errno, $errstr, 30); 

    if (!$fp)
    {
        exit('Error postback');
    }
    fputs ($fp, $header . $req); 
    while (!feof($fp))
        $res = fgets ($fp, 1024); 
    fclose ($fp);
    if ($res != "VERIFIED")
    {
        exit('Not verified');
    }

    if($_POST['ok_txn_status'] !== 'completed')
        exit('Invalid ok_txn_status');


        $checktx = $this->db->prepare("SELECT * FROM transactions WHERE txid=? LIMIT 1");
        $checktx->execute(array($txid));
        $result = $checktx->fetch();
        if(!$result):
            if(isset($market) && isset($amount)):
            //insert into transactions and update balance
            $transaction = $this->db->prepare("INSERT INTO transactions(market,amount,
            username,txid,transaction,status) VALUES(?,?,?,?,?,?)");
            $transaction->execute(array($market,$amount,$username,$invoice,'deposit','1'));
            if($transaction):
            echo 'debug 1';
            echo $market;
                //get the user and their balance
                $getuserbalance = $this->db->prepare("SELECT * FROM user WHERE username=?");
                $getuserbalance->execute(array($username));
                $userbalance = $getuserbalance->fetch();
                //this is their new balance
                $newbalance = $amount + $userbalance->{$market};
                $updateuser = $this->db->prepare("UPDATE user SET ".htmlentities($market)."=? WHERE username=?");
                $updateuser->execute(array($newbalance,$username));
            endif;
        endif;
    endif;
它给了我一个200OK的回报,但不是数据库。抱歉,代码太长了

if ($res != "VERIFIED")
{
    exit('Not verified');
}
这是你的错误。当您使用IPN测试工具时,状态将为TEST而不是VERIFIED