0

我一直在看几个利用 paypal 的 API 来开发一个简单的脚本以便能够使用它来结帐的例子,并且在每个例子中我都在运行 cURL,我真的一点也不明白。只是库中的不同 PHP 函数,还是完全不同的东西?更重要的是,我可以将 cURL 命令复制并粘贴到我的文档中并且它会工作,还是我需要下载一些东西才能让它在我的本地服务器和我的实时站点所在的共享托管服务器上工作?最后,我在哪里可以学习这个?我做了一些搜索,但没有找到任何可靠的材料。我真的很感激任何帮助。

4

2 回答 2

1

PHP手册中对cURL示例的基本理解

<?php

$ch = curl_init("http://www.example.com/");
$fp = fopen("example_homepage.txt", "w");

curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);
curl_close($ch);
fclose($fp);
?>

PHP 手册

带有 PayPal API 的 cURL。[在网上找到的]

<?php

$ch = curl_init();
$clientId = "myId";
$secret = "mySecret";

curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_USERPWD, $clientId.":".$secret);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");

$result = curl_exec($ch);

if(empty($result))die("Error: No response.");
else
{
    $json = json_decode($result);
    print_r($json->access_token);
}

curl_close($ch);

?>
于 2013-04-16T06:28:42.950 回答
0

您可以使用简单的表格进行结帐。要通过 cURL 使用,您需要启用 cURL 并在 PHP 代码中使用它。

以下是简单的方法。

<form action="https://paypal.com/cgi-bin/webscr" method="post">  
    <input type="hidden" name="business" value="sandy_1314264698_biz@gmail.com ">  
    <input type="hidden" name="cmd" value="_xclick-subscriptions">  
    <input type="hidden" name="item_name" value="sand bag">  
    <input type="hidden" name="item_number" value="1234">  
    <input type="hidden" name="currency_code" value="USD">  
    <input type="hidden" name="notify_url" value="http://abc.com/xyz.php">
    <input type="hidden" name="return" value="http://google.com">

    <!-- Display the payment button. --> 


<input type="image" name="submit" border="0" src="btn_subscribe_LG.gif" alt="PayPal - The safer, easier way to pay online">  
<img alt="" border="0" width="1" height="1" src="https://www.paypal.com/en_US/i/scr/pixel.gif" >  

于 2013-04-16T06:30:30.587 回答