PHP如何實(shí)現(xiàn)PayPal支付功能-創(chuàng)新互聯(lián)

本篇內(nèi)容介紹了“PHP如何實(shí)現(xiàn)PayPal支付功能”的有關(guān)知識,在實(shí)際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

建始網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián),建始網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為建始數(shù)千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設(shè)公司要多少錢,請找那個(gè)售后服務(wù)好的建始做網(wǎng)站的公司定做!

簡單整理一下PHP項(xiàng)目整合PayPal支付功能。

一、表單的構(gòu)建:

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

二、IPN驗(yàn)證部分

<?php
class paypal {
  var $ipn_data = array();     // array contains the POST values for IPN
  var $fields = array();      // 提交給Paypal的表單參數(shù),例:item_name=iPhone 6,quantity=1,amount=499,currency_code=USD等所有表單信息,
                     // 在調(diào)用驗(yàn)證IPN之前事先需要初始化好
  var $paypal_url = 'https://www.paypal.com/cgi-bin/webscr';//sandbox:https://www.sandbox.paypal.com/cgi-bin/webscr
  
  function validate_ipn() {//驗(yàn)證IPN
      // parse the paypal URL
      $url_par=parse_url($this->paypal_url);
      // generate the post string from the _POST vars aswell as load the
      // _POST vars into an arry so we can play with them from the calling
      // script.
      $post_str = '';
      foreach ($_POST as $field=>$value) {
        $this->ipn_data["$field"] = $value;
        $post_str .= $field.'='.urlencode(stripslashes($value)).'&';
      }
      $post_str.="cmd=_notify-validate"; // append ipn command
      // open the connection to paypal
      $fp = fsockopen($url_par[host],"80",$errnum,$errstr,30);
      if(!$fp) {
        // could not open the connection.
        return false;
      } else {
        // Post the data back to paypal
        fputs($fp, "POST ".$url_par[path]." HTTP/1.1\r\n");
        fputs($fp, "Host: ".$url_par[host]."\r\n");
        fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
        fputs($fp, "Content-length: ".strlen($post_str)."\r\n");
        fputs($fp, "Connection: close\r\n\r\n");
        fputs($fp, $post_str . "\r\n\r\n");
        // loop through the response from the server and append to variable
        while(!feof($fp)) {
          $this->validate_ipn_response .= fgets($fp, 1024);
        }
        fclose($fp); // close connection
     }
    if (eregi("VERIFIED",$this->validate_ipn_response)) {
      return true;
    } else {
      return false;
    }
  }
}
?>

“PHP如何實(shí)現(xiàn)PayPal支付功能”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

分享標(biāo)題:PHP如何實(shí)現(xiàn)PayPal支付功能-創(chuàng)新互聯(lián)
網(wǎng)站網(wǎng)址:http://bm7419.com/article14/dssige.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供用戶體驗(yàn)、品牌網(wǎng)站設(shè)計(jì)網(wǎng)站制作、軟件開發(fā)、關(guān)鍵詞優(yōu)化、標(biāo)簽優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

綿陽服務(wù)器托管