国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

PHP整合PayPal支付

2024-05-04 23:36:08
字體:
來源:轉載
供稿:網友

PayPal作為全球運用最廣的在線支付工具,一直被很多外貿B2C網站納為首選支付工具。不過對于自主開發網站的商戶來說,PayPal接口的集成經常遇到很多問題,今天Lance就在這里給大家分享一下php項目中PayPal接口的集成方法。

簡單整理一下PHP項目整合PayPal支付功能。

一、表單的構建:

 

 
  1. <form method="post" name="form" action="https://www.paypal.com/cgi-bin/webscr"
  2. <input type="hidden" name="rm" value="2"/> 
  3. <input type="hidden" name="cmd" value="_xclick"/> 
  4. <input type="hidden" name="business" value="商家賬號"/> 
  5. <input type="hidden" name="return" value="返回網址"/> 
  6. <input type="hidden" name="cancel_return" value="取消返回網址"/> 
  7. <input type="hidden" name="notify_url" value="用于接收PayPal發送的即時付款通知的URL,必須是有效的URL"/> 
  8. <input type="hidden" name="item_name" value="物品名稱"/> 
  9. <input type="hidden" name="item_number" value="可用于跟蹤購買或捐贈的傳遞變量,在付款完成時傳回給您"/> 
  10. <input type="hidden" name="amount" value="物品的價格(購物車中所有物品的總價格"/> 
  11. <input type="hidden" name="currency_code" value="幣種"/> 
  12. </form> 

二、IPN驗證部分

 

 
  1. <?php 
  2. class paypal { 
  3.   var $ipn_data = array(); // array contains the POST values for IPN 
  4.   var $fields = array(); // 提交給Paypal的表單參數,例:item_name=iPhone 6,quantity=1,amount=499,currency_code=USD等所有表單信息, 
  5.                      // 在調用驗證IPN之前事先需要初始化好 
  6.   var $paypal_url = 'https://www.paypal.com/cgi-bin/webscr';//sandbox:https://www.sandbox.paypal.com/cgi-bin/webscr 
  7.    
  8.   function validate_ipn() {//驗證IPN 
  9.       // parse the paypal URL 
  10.       $url_par=parse_url($this->paypal_url); 
  11.       // generate the post string from the _POST vars aswell as load the 
  12.       // _POST vars into an arry so we can play with them from the calling 
  13.       // script. 
  14.       $post_str = ''
  15.       foreach ($_POST as $field=>$value) { 
  16.         $this->ipn_data["$field"] = $value
  17.         $post_str .= $field.'='.urlencode(stripslashes($value)).'&'
  18.       } 
  19.       $post_str.="cmd=_notify-validate"// append ipn command 
  20.       // open the connection to paypal 
  21.       $fp = fsockopen($url_par[host],"80",$errnum,$errstr,30); 
  22.       if(!$fp) { 
  23.         // could not open the connection. 
  24.         return false; 
  25.       } else { 
  26.         // Post the data back to paypal 
  27.         fputs($fp"POST ".$url_par[path]." HTTP/1.1/r/n"); 
  28.         fputs($fp"Host: ".$url_par[host]."/r/n"); 
  29.         fputs($fp"Content-type: application/x-www-form-urlencoded/r/n"); 
  30.         fputs($fp"Content-length: ".strlen($post_str)."/r/n"); 
  31.         fputs($fp"Connection: close/r/n/r/n"); 
  32.         fputs($fp$post_str . "/r/n/r/n"); 
  33.         // loop through the response from the server and append to variable 
  34.         while(!feof($fp)) { 
  35.           $this->validate_ipn_response .= fgets($fp, 1024); 
  36.         } 
  37.         fclose($fp); // close connection 
  38.      } 
  39.     if (eregi("VERIFIED",$this->validate_ipn_response)) { 
  40.       return true; 
  41.     } else { 
  42.       return false; 
  43.     } 
  44.   } 
  45. ?> 

以上所述就是本文的全部內容了,希望大家能夠喜歡。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 贵南县| 锦州市| 河东区| 电白县| 巴青县| 湖口县| 定边县| 汕头市| 卓尼县| 彩票| 祁连县| 丰台区| 阿鲁科尔沁旗| 依兰县| 顺昌县| 定边县| 威海市| 将乐县| 广南县| 房产| 穆棱市| 南涧| 南靖县| 上饶县| 济宁市| 五家渠市| 吉木萨尔县| 柘荣县| 黄冈市| 贵定县| 富顺县| 信宜市| 固阳县| 芷江| 南召县| 思南县| 荃湾区| 霞浦县| 霍邱县| 忻州市| 吴旗县|