[英]Looking at paypal API - What is cURL?
我一直在看幾個利用貝寶(Paypal)API開發一個簡單腳本以使用它進行結帳的示例,在每個示例中,我一直在cURL上運行,我真的一點都不理解。 它僅僅是庫中的不同PHP函數,還是所有不同的東西? 更重要的是,我可以將cURL命令復制並粘貼到我的文檔中並且可以運行,還是需要下載一些內容才能使其在我的實時站點所在的本地服務器和共享托管服務器上正常工作? 最后,我可以去哪里學習? 我已經做了一些搜索,但是還沒有找到任何固體材料。 我非常感謝您的幫助。
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);
?>
使用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);
?>
您可以使用簡單的表格進行結帳。 要通過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" >
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.