這裏是第一步,創建表單,把它放在你想要購買按鈕的地方,它可以在任何頁面上,你可以通過PayPal網站上的按鈕嚮導創建它,只需添加這個notify_url隱藏輸入。 您可以編輯使用PHP進入量,ITEM_NAME,企業郵箱,自定義這些字段...
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="[email protected]">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="item_name" value="Item Name">
<input type="hidden" name="item_number" value="150">
<input type="hidden" name="amount" value="100.00">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="tax_rate" value="0.000">
<input type="hidden" name="shipping" value="0.00">
<input type="hidden" name="custom" value="user_id_goes_here">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
<input type="hidden" name="notify_url" value="http://checking-url-goes-here/file.php">
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
第二步,檢查是它有效的付款,file.php(或任何文件URL你notify_url隱藏輸入指定上面表格):
<?php
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
if (!$fp) {
//ERROR READING PAGE - CODE ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
//VALID CODE, DO WHATEVER YOU WANT WITH IT HERE, PAYMENT IS CONFIRMED...
}
else if (strcmp ($res, "INVALID") == 0) {
//INVALID CODE
}
}
?>
您可以測試代碼裏: https://developer.paypal.com/ (貝寶沙箱) 只需更換
www.p aypal.com
與
www.sandbox.paypal.com
(你可以在兩個地方找到它)。
就是這樣......
我問這個方向,也沒有人想在這裏告訴我...
我甚至得-2評級這個問題,但這些都不缺點足夠聰明,寫我這些例子,因爲我要求...
而我是誰應得的缺點?
(我希望有人會發現有用的那些例子)
「這是網上四處傳播,所以任何人都應該知道** **這......」而事實上,通過同樣的原因,任何人都能夠閱讀並嘗試弄清楚。然後回來一個更具體的問題/問題。 – mellamokb 2011-03-07 19:41:45
如果我能找到它,我不會在這裏問...所以這是一個問題... – SharkTheDark 2011-03-07 20:07:12