【问题标题】:Paypal PDT not working using CURLPaypal PDT 无法使用 CURL
【发布时间】:2015-11-28 15:03:06
【问题描述】:

Paypal 返回站点并提供交易 ID,现在使用 CURL 发布数据它只是不起作用,谁能帮助我。它没有打印成功消息。我已经搜索了堆栈溢出,但仍然没有。

    $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 是否正在发布数据

标签: php curl paypal


【解决方案1】:

我看不到“成功消息”——也没有任何尝试在 curl 请求后输出任何内容,唯一让我印象深刻的事情——其他人可能不同意——是选项中没有任何东西可以专门处理 https 通信根据我的经验,这需要设置其他选项。我之前没有处理过 PayPal api,所以这可能没有任何用处,但是.....

尝试下载cacert.pem 的副本 - 谷歌是你的朋友。

<?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>';
?>

【讨论】:

  • 是弗雷德·格温吗? ;-) ... +1 提供帮助。虽然我做的唯一 php 是在这里阅读问题,但我认为您正在了解有关 https args 的内容。也适用于 o.p. , 所以。也是你的朋友。尝试搜索[paypal] [php],我看到~3550 Q/As。祝大家好运。
  • 放大后心想,这不可能是他,他看起来好年轻啊! ;-)
猜你喜欢
  • 2014-05-28
  • 2018-12-23
  • 1970-01-01
  • 2012-04-21
  • 2014-07-18
  • 1970-01-01
  • 2013-10-03
  • 2012-10-13
  • 1970-01-01
相关资源
最近更新 更多