当用户从我的网站付款时向用户显示简单文本

时间:2015-08-19 11:11:03

标签: php paypal

我有两个php文件:1- get.php 2- send.php。考虑用户点击“购买”按钮并请求在支付网关页面中进行连接。用户的send.php如下:

     <?php
        session_start();
        if(isset($_SESSION['login_user'])) { 
$username = $_SESSION['login_user'];          
function send($url,$api,$amount,$redirect){
            $ch = curl_init();
            curl_setopt($ch,CURLOPT_URL,$url);
            curl_setopt($ch,CURLOPT_POSTFIELDS,"api=$api&amount=$amount&redirect=$redirect");
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
            curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
            $res = curl_exec($ch);
            curl_close($ch);
            return $res;
            }
            $url = 'http://payment.com/payment-test/gateway-send';
            $api = 'adxcv-zzadq-polkjsad-opp13opoz-1sdf455aadzmck1244567';
            $amount = 1000;
            $redirect = urlencode('http://localhost/get.php');
            $result = send($url,$api,$amount,$redirect);
            if($result > 0 && is_numeric($result)){
            $go = "http://payment.com/payment-test/gateway-$result";
    //save the username and the get_id in a table.        
    header("Location: $go");
            }}
        esle {echo "found an error in connecting to payment gateway";} ?>

现在,用户进入支付网关页面并成功进行操作支付。现在银行的付款网关页面将trans_idid_get发送到get.php文件,get.php文件如下:

    function get($url,$api,$trans_id,$id_get){
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_POSTFIELDS,"api=$api&id_get=$id_get&trans_id=$trans_id");
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    $res = curl_exec($ch);
    curl_close($ch);
    return $res;
    }
    $url = 'http://payment.com/payment-test/gateway-result-second';
    $api = 'adxcv-zzadq-polkjsad-opp13opoz-1sdf455aadzmck1244567';
    $trans_id = $_POST['trans_id'];
    $id_get = $_POST['id_get'];
    $result = get($url,$api,$trans_id,$id_get);
    if($result == '1') { 
//find the `$id_get`value in the table and put the `trans_id` within the same raw that the id_get is
echo "successfully"; }
    else {echo "Unsuccessfully";}

get.php中的问题是echo不知道将消息发送给哪个用户。如果我使用get.php文件顶部的会话,则结果session_start()从支付网关网站获得会话。

0 个答案:

没有答案