dpvm7231 2012-03-31 22:46
浏览 56
已采纳

PayPal:将电子邮件地址传递给return /“thank you”页面

I've successfully created a small "pay now" button with PayPal IPN and a listener. The button itself is wizard-generated.

After the payment, the user is redirected to a return/"thank you" page on my host.

Everything works as expected, but I need to receive the customer e-mail on the "thank you" page too: how can I do that?

  • 写回答

1条回答 默认 最新

  • duanliexi1052 2012-04-01 02:37
    关注

    You can get the user email using the Payment Data Transfer (PDT), which sends a GET variable named tx to your redirect url.

    The tx variable contains a transaction number which you can use to send to a post request to Paypal's server and retrieve the transaction information.

    The last time I used PDT was a year ago, but I believe there is a setting in your Paypal account that you need to enable and set a redirect url for this to work.

    Here are some links that describes PDT in further detail:

    Here is an example of how to parse send a post request to Paypal and parse the data. I just dug this up from an old file. So no guarantees that it works. This is based off a script that Paypal uses as an example for php. You can use curl instead, and that's probably the better choice. I think there is some kind of security issue with using fsockopen.

    //Paypal will give you a token to use once you enable PDT
    $auth_token = 'token';
    
    //Transaction number
    $tx_token = $_GET['tx'];
    
    $payPalUrl = ( $dev === true ) ? 'ssl://www.sandbox.paypal.com' : 'ssl://www.paypal.com';
    
    $req = 'cmd=_notify-synch';
    $req .= "&tx=$tx_token&at=$auth_token";
    
    
    $header .= "POST /cgi-bin/webscr HTTP/1.0
    ";
    $header .= "Content-Type: application/x-www-form-urlencoded
    ";
    $header .= "Content-Length: " . strlen($req) . "
    
    ";
    $fp = fsockopen ($payPalUrl, 443, $errno, $errstr, 30);
    
    $keyarray = false;
    
    if ( $fp ) {
        fputs ($fp, $header . $req);
    
        $res = '';
        $headerdone = false;
        while (!feof($fp)) {
            $line = fgets ($fp, 1024);
            if (strcmp($line, "
    ") == 0) {
                $headerdone = true;
            }
            else if ($headerdone) {
                $res .= $line;
            }
        }
    
        $lines = explode("
    ", $res);
    
        if (strcmp ($lines[0], "SUCCESS") == 0) {
                //If successful we can now get the data returned in an associative array
            $keyarray = array();
            for ($i=1; $i<count($lines);$i++){
                list($key,$val) = explode("=", $lines[$i]);
                $keyarray[urldecode($key)] = urldecode($val);
            }
        }
    }
    fclose ($fp);
    return $keyarray;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示