【问题标题】:Paypal use of clientid & clientSecret for PHPPaypal 使用 PHP 的 clientid 和 clientSecret
【发布时间】:2014-09-03 19:14:04
【问题描述】:

我长期使用 Paypal API 进行开发。

现在,我的网站已上线,但我遇到了将代码迁移到生活中的问题, 并且我认为我需要添加我在开发站点上没有的 clientid+clientSecret。

(正如我在 https://github.com/paypal/rest-api-sdk-php 和一些工作区看到的那样)。

另外,我希望对下面的代码进行最小的更改,即使让它在生活网站中运行似乎已经过时了。

作为开发人员,我使用这样的“setExressCheckout”方法 (注意 echo $response - 我不希望这条线。该怎么做?)

// =========== 代码开始

<?php

/*.
require_module 'standard';
    require_module 'standard_reflection';
    require_module 'spl';
    require_module 'mysqli';
    require_module 'hash';
    require_module 'session';
    require_module 'streams';
.*/

    require_once __DIR__ . "/stdlib/all.php";

/*. array .*/ $body_data = null;

$body_data_txt = "";

/*. string .*/ $htmlpage  = "";

/*. array .*/ $tokenAr = array();

$response = "";

session_start();

$url = trim('https://www.sandbox.paypal.com/cgi-bin/webscr');

$body_data = array( 'USER' => "*******",
                    'PWD' => "*******",                                    
                    'SIGNATURE' => "******",
                    'VERSION' => "95.0",
                    'PAYMENTREQUEST_0_PAYMENTACTION' => "Sale",
                    'PAYMENTREQUEST_0_AMT' => (string)$_SESSION["AMOUNT"],
                    'PAYMENTREQUEST_0_CURRENCYCODE' => 'USD',
                    'RETURNURL' => "*****",
                    'CANCELURL' => "******",
                    'METHOD' => "SetExpressCheckout"
                                );

$body_data_txt = http_build_query($body_data, '', chr(38));
try
{
    //create request and add headers
    $params = array(
        'http' => array(
            'protocol_version' => "1.1",
            'method' => "POST",
            'header' => "".
            "Connection: close\r\n".
            "Content-Length: ".strlen($body_data_txt)."\r\n".
            "Content-type: "."application/x-www-form-urlencoded"."\r\n",
            'content' => $body_data_txt
    ));

    //create stream context
     $ctx = stream_context_create($params);

    //open the stream and send request
    try {
        $fp = fopen($url, 'r', false, $ctx);
    } catch(ErrorException $e) {
        throw new ErrorException("cannot open url" . $url . " error:" . $e->getMessage());
    }
     //get response
     $response = (string)stream_get_contents($fp);
     //check to see if stream is open
     if ($response === "") {
        throw new Exception("php error message = " . "$php_errormsg");
     }

     //close the stream
     fclose($fp);   

     $key = explode("&", $response);
     if (substr($response, 0, 1) === "<") {
        echo $response; // ******************************
     }
     ....

// ============ 代码结束

代码无法按预期运行,因为“echo $response ...”行不应运行。 它的屏幕内容标题为:

"没有买家或卖家

免费注册。

... "

据我调查,我需要客户端 ID 和客户端密钥。我在https://developer.paypal.com 上制作的。 但是如何使用它 - 对我的代码进行最少的更改?

谢谢:)

【问题讨论】:

    标签: php paypal clientid


    【解决方案1】:

    我找到了我的问题的解决方案 - 不需要 clientid 和 clientsecret。

    开发模式和生活模式的代码工作方式相同。

    url 错误,应该是:$url = trim('https://api-3t.paypal.com/nvp');

    无论如何,谢谢:)

    【讨论】:

      猜你喜欢
      • 2016-05-30
      • 2017-09-01
      • 2020-01-21
      • 2014-08-05
      • 1970-01-01
      • 2012-08-01
      • 2021-07-21
      • 1970-01-01
      • 2017-11-07
      相关资源
      最近更新 更多