Paypal PDT不工作使用CURL [英] Paypal PDT not working using CURL

查看:217
本文介绍了Paypal PDT不工作使用CURL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Paypal返回网站并提供交易ID,现在使用CURL发布数据,它只是不工作,任何人都可以帮助我。

Paypal returns to the site and gives the transaction ID, now using CURL to post data it just isnt working, can anyone help me. It isnt printing the success message.i have searched stack overflow, and still nothing.

    $tx = $_GET['tx'];
            $ID = $_GET['cm'];
            $currency = $_GET['cc'];
            $identity = '0iMIW7w4OXAed9Tvz6l9fpUY8B-E_WtE3toU7sT5gIzDJc9uPUgt9sVCN30'; 


              // Further processing
              // Init cURL

                // Init cURL
                $request = curl_init();

                // Set request options
                $url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
                $fields = array(    
                    'cmd' => '_notify-synch',
                    'tx' => $tx,
                    'at' => $identity,
                );
                curl_setopt($request,CURLOPT_URL, $url);
                curl_setopt($request,CURLOPT_POST, count($fields));
                curl_setopt($request,CURLOPT_POSTFIELDS, http_build_query($fields));
                curl_setopt($request,CURLOPT_RETURNTRANSFER, TRUE);
                curl_setopt($request,CURLOPT_HEADER, FALSE);

                // Execute request and get response and status code
                $response = curl_exec($request);
                $status   = curl_getinfo($request, CURLINFO_HTTP_CODE);

                // Close connection
                curl_close($request);


推荐答案

我看不到成功消息尝试在curl请求之后输出任何内容,唯一让我感到震惊的事情 - 以及其他人可能完全不同意 - 是在选项中没有什么可以专门处理https通信,在我的经验中,需要设置其他选项。我以前没有处理过PayPal API,所以这可能没有什么用处,但.....

I can see no "success message" - nor any attempt to output anything after the curl request, the only thing that struck me - and others may well disagree - is that there is nothing in the options to specifically deal with https communications which, in my experience, require other options to be set. I've not dealt with the PayPal api before so this might provide nothing of use, but.....

请尝试下载 cacert.pem - google是您的朋友。

try downloading a copy of cacert.pem - google is your friend.

<?php
    $tx = $_GET['tx'];
    $ID = $_GET['cm'];
    $currency = $_GET['cc'];
    $identity = '0iMIW7w4OXAed9Tvz6l9fpUY8B-E_WtE3toU7sT5gIzDJc9uPUgt9sVCN30';

    /* Use the full path to your own cacert.pem, download from the interwebs if you do not have a copy */
    $cacert = 'c:/wwwroot/cacert.pem'; 

    $url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
    $fields = array(    
        'cmd'   => '_notify-synch',
        'tx'    => $tx,
        'at'    => $identity,
    );

    $request = curl_init();
    curl_setopt($request,CURLOPT_URL, $url);

    if( parse_url( $url,PHP_URL_SCHEME )=='https' ){
        curl_setopt( $request, CURLOPT_SSL_VERIFYPEER, FALSE ); /* set to true once you get this working */
        curl_setopt( $request, CURLOPT_SSL_VERIFYHOST, 2 );
        curl_setopt( $request, CURLOPT_CAINFO, realpath( $cacert ) );
    }


    /* this should be true or false not count($fields): in this case true*/
    /*curl_setopt($request,CURLOPT_POST, count( $fields ) );*/
    curl_setopt($request,CURLOPT_POST, true );
    curl_setopt($request,CURLOPT_POSTFIELDS, http_build_query( $fields ) );
    curl_setopt($request,CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($request,CURLOPT_HEADER, FALSE);

    /* Quite often requests get rejected for no useragent */
    curl_setopt($request,CURLOPT_USERAGENT, 'paypal-mozilla-chrome-useragent' );
    curl_setopt($request, CURLINFO_HEADER_OUT, TRUE );


    $response = curl_exec($request);
    $status   = curl_getinfo($request, CURLINFO_HTTP_CODE);

    curl_close($request);
    /* See what the curl request has retrieved */
    echo '<pre>',print_r( $response, true ),$status,'</pre>';
?>

这篇关于Paypal PDT不工作使用CURL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆