【问题标题】:Creating HTTPS connection to Paypal server with PHP 5使用 PHP 5 创建到 Paypal 服务器的 HTTPS 连接
【发布时间】:2012-10-18 17:42:33
【问题描述】:

我正在尝试将 payflow pro 与现有网站集成。

没有适用于 PHP 的 SDK,与 PHP 的集成需要使用 Payflow HTTPS 接口。开发指南(https://cms.paypal.com/cms_content/AU/en_AU/files/developer/PP_WPPPF_HTTPSInterface_Guide.pdf)说我需要编写代码来创建到 Paypal 服务器的 HTTPS 连接。我应该使用什么方法来执行此操作,以及在建立连接后如何提交 HTTPS 请求?

【问题讨论】:

    标签: php https http-headers payflowpro


    【解决方案1】:

    只需使用任何常规方法发出 HTTP 请求,例如卷曲或file_get_contents。如果底层传输层支持 SSL 安全连接,则向https://... URL 发出请求将建立 SSL 安全连接;否则传输层将失败,说它无法建立 HTTPS 连接。

    【讨论】:

      【解决方案2】:

      我终于可以在这里找到一个例子:https://ppmts.custhelp.com/app/answers/detail/a_id/618

      <?
      $submiturl = "https://pilot-payflowpro.paypal.com/transaction:443/";
      
      $plist="USER=****&VENDOR=****&PARTNER=****&PWD=****&TENDER=C&" .
              "TRXTYPE=A&ACCT=5105105105105100&" .
              "EXPDATE=1209&STREET= 123 MainSt.&CVV2=123&AMT=1.00";
      
      $request_id = date('YmdGis');
      $user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
      
      // Here's your custom headers; adjust appropriately for your setup:
      $headers[] = "Content-Type: text/namevalue";    // either text/namevalue or text/xml
      $headers[] = "X-VPS-Timeout: 30";
      $headers[] = "X-VPS-VIT-OS-Name: Linux";        // Name of your Operating System (OS)
      $headers[] = "X-VPS-VIT-OS-Version: RHEL 4";    // OS Version
      $headers[] = "X-VPS-VIT-Client-Type: PHP/cURL"; // Language you are using
      $headers[] = "X-VPS-VIT-Client-Version: 0.01";  // For your info
      $headers[] = "X-VPS-VIT-Client-Architecture: x86";  // For your info
      $headers[] = "X-VPS-VIT-Integration-Product: MyApplication";  // For your info,  application name
      $headers[] = "X-VPS-VIT-Integration-Version: 0.01"; // Application version
      $headers[] = "X-VPS-Request-ID: " . $request_id;
      
      $user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $submiturl);
      curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
      curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
      curl_setopt($ch, CURLOPT_HEADER, 1); // tells curl to include headers in response
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
      curl_setopt($ch, CURLOPT_TIMEOUT, 45); // times out after 45 secs
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // this line makes it work under https
      curl_setopt($ch, CURLOPT_POSTFIELDS, $plist); //adding POST data
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  2); //verifies ssl certificate
      curl_setopt($ch, CURLOPT_FORBID_REUSE, TRUE); //forces closure of connection when done
      curl_setopt($ch, CURLOPT_POST, 1); //data sent as POST
      
      // $info = curl_getinfo($ch); //grabbing details of curl connection
      
      $result = curl_exec($ch);
      $headers = curl_getinfo($ch);
      curl_close($ch);
      echo $result;
      ?> 
      

      【讨论】:

      • +1 非常感谢;我一直在到处寻找这种简单而有效的解决方案。
      【解决方案3】:

      您有三个选择:

      1) 如果您喜欢冒险,可以使用 OSCommerce PHP PayFlow SDK 作为起点:https://www.x.com/sites/default/files/OsC23PayPalPayFlow.zip

      2) 您可以通读 payflow 开发指南并进行自己的手工 API 调用: https://cms.paypal.com/cms_content/US/en_US/files/developer/PP_PayflowPro_Guide.pdf

      3) 您可以试一试集成向导。我会为你自动生成代码:https://www.paypal-labs.com/integrationwizardccpayflow/main.php

      【讨论】:

        猜你喜欢
        • 2014-04-06
        • 1970-01-01
        • 1970-01-01
        • 2016-07-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-29
        相关资源
        最近更新 更多