paypal即時(shí)到賬php實(shí)現(xiàn)代碼
更新時(shí)間:2010年11月28日 15:24:01 作者:
paypal即時(shí)到賬php實(shí)現(xiàn)代碼,需要的朋友可以參考下。
http://paypal.ebay.cn/integrationcenter/list__resource_2.html
中文php開(kāi)發(fā)簡(jiǎn)介:http://www.paypal-china.org/wangzhai/197.html
以下是ecshop中paypal的支付代碼
這段代碼是向paypal支付接口提交的
{{{
<form target="_blank" method="post" action="https://www.paypal.com/cgi-bin/webscr" style="text-align: center;"><input type="hidden" value="_xclick" name="cmd"/><input type="hidden" value="xfuajiao@hotmail.com" name="business"/> //商家注冊(cè)的郵箱
<input type="hidden" value="2009102370175" name="item_name"/><input type="hidden" value="2888.00" name="amount"/><input type="hidden" value="USD" name="currency_code"/><input type="hidden" value="http://127.0.0.1/ecshop/respond.php?code=paypal" name="return"/><input type="hidden" value="3" name="invoice"/><input type="hidden" value="utf-8" name="charset"/><input type="hidden" value="1" name="no_shipping"/><input type="hidden" value="" name="no_note"/><input type="hidden" value="http://127.0.0.1/ecshop/respond.php?code=paypal" name="notify_url"/><input type="hidden" value="2" name="rm"/><input type="hidden" value="http://127.0.0.1/ecshop/" name="cancel_return"/><input type="submit" value="立即使用 paypal 支付"/></form>
}}}
以下是官方提供的,接受到paypal傳回來(lái)的參數(shù)的,并且判斷是否支付成功。
支持成功后由于提交表單中有
<input type="hidden" value="http://127.0.0.1/ecshop/respond.php?code=paypal" name="return"/>
paypal將會(huì)主動(dòng)跳轉(zhuǎn)到espond.php?code=paypal這個(gè)頁(yè)面,頁(yè)面可現(xiàn)實(shí)以下POST得到的一些數(shù)據(jù)。
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// post back to PayPal system to validate
$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);
// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
if (!$fp) {
// HTTP ERROR
else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
?>
中文php開(kāi)發(fā)簡(jiǎn)介:http://www.paypal-china.org/wangzhai/197.html
以下是ecshop中paypal的支付代碼
這段代碼是向paypal支付接口提交的
{{{
<form target="_blank" method="post" action="https://www.paypal.com/cgi-bin/webscr" style="text-align: center;"><input type="hidden" value="_xclick" name="cmd"/><input type="hidden" value="xfuajiao@hotmail.com" name="business"/> //商家注冊(cè)的郵箱
<input type="hidden" value="2009102370175" name="item_name"/><input type="hidden" value="2888.00" name="amount"/><input type="hidden" value="USD" name="currency_code"/><input type="hidden" value="http://127.0.0.1/ecshop/respond.php?code=paypal" name="return"/><input type="hidden" value="3" name="invoice"/><input type="hidden" value="utf-8" name="charset"/><input type="hidden" value="1" name="no_shipping"/><input type="hidden" value="" name="no_note"/><input type="hidden" value="http://127.0.0.1/ecshop/respond.php?code=paypal" name="notify_url"/><input type="hidden" value="2" name="rm"/><input type="hidden" value="http://127.0.0.1/ecshop/" name="cancel_return"/><input type="submit" value="立即使用 paypal 支付"/></form>
}}}
以下是官方提供的,接受到paypal傳回來(lái)的參數(shù)的,并且判斷是否支付成功。
支持成功后由于提交表單中有
<input type="hidden" value="http://127.0.0.1/ecshop/respond.php?code=paypal" name="return"/>
paypal將會(huì)主動(dòng)跳轉(zhuǎn)到espond.php?code=paypal這個(gè)頁(yè)面,頁(yè)面可現(xiàn)實(shí)以下POST得到的一些數(shù)據(jù)。
復(fù)制代碼 代碼如下:
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// post back to PayPal system to validate
$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);
// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
if (!$fp) {
// HTTP ERROR
else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
?>
相關(guān)文章
PHP如何根據(jù)文件頭檢測(cè)文件類型實(shí)例代碼
這篇文章主要給大家介紹了關(guān)于PHP如何根據(jù)文件頭檢測(cè)文件類型的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用php具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-10-10
php編寫(xiě)的抽獎(jiǎng)程序中獎(jiǎng)概率算法
本文給大家分享的是php中獎(jiǎng)概率算法,可用于刮刮卡,大轉(zhuǎn)盤(pán)等抽獎(jiǎng)算法。用法很簡(jiǎn)單,代碼里有詳細(xì)注釋說(shuō)明,一看就懂,有需要的小伙伴參考下吧。2015-05-05
PHP運(yùn)行SVN命令顯示某用戶的文件更新記錄的代碼
使用SVN開(kāi)發(fā)者們平時(shí)開(kāi)發(fā)或代碼上線過(guò)程中需要知道某個(gè)時(shí)間段內(nèi)修改或添加過(guò)那些文件,所以用PHP寫(xiě)了個(gè)小程序,直接在瀏覽器中調(diào)用即可2014-01-01

