php版銀聯支付介面開發簡單一實例詳解

來源:互聯網
上載者:User
這篇文章主要介紹了php版銀聯支付介面開發的方法,結合執行個體形式分析了php銀聯支付介面開發的具體流程與相關操作技巧,需要的朋友可以參考下

支付介面現在有第三方的支付介面也有銀行的支付介面。這裡就來介紹php版本銀聯支付介面開發的方法。

銀聯支付,首先要注意二重要的部分:

PHP運行環境是5.4.18以上

開了擴充openssl

開發手冊上面的列子只做參考,因為基本都是錯的。你可以試著去官網下一個demo。。。注意現在銀聯開發,沒有測試密鑰提供,只能在正式環境開發

下面是我用ThinkPHP編寫的一個支付類

/*** 銀聯支付 v0.1* @auther:Summer<dengwz7788@gmail.com>;* @date:20151202* **/class NetPayAction extends BaseAction{//在類初始化方法中,引入相關類庫public function _initialize() { header("Content-type:text/html;charset=utf-8"); vendor('Netpay.util.common',"",".php"); //匯入加密核心檔案夾 vendor('Netpay.util.SecssUtil',"",".class.php"); //匯入加密核心檔案夾 vendor('Netpay.util.Settings_INI',"",".php"); //匯入加密核心檔案夾 vendor('Netpay.util.Settings',"",".php"); //匯入加密核心檔案夾 $this->securityPropFile= $_SERVER['DOCUMENT_ROOT'] . "/ThinkPHP/Extend/Vendor/Netpay/config/security.properties"; //誰知道這是啥,反正他們要我加的 $this->b2cPaySend = __APP__."/Index/NetPay/b2cPaySend"; $this->b2cRefundSend = __APP__."/Index/NetPay/b2cRefundSend"; $this->b2cQuerySend = __APP__."/Index/NetPay/b2cQuerySend"; $this->;MerBgUrl = __APP__."/Index/NetPay/MerBgUrl"; $this->MerPageUrl = __APP__."/Index/NetPay/MerPageUrl";}public function index(){ $paramArray=array (   'MerId' => '商戶號',   'MerOrderNo' => '0000001944663232',   'OrderAmt' => '1',   'TranDate' => '20151219',  'TranTime' =>'171248',  'TranType' => '0001',  'BusiType' =>'0001',  'Version' => '20140728',  'CurryNo' => 'CNY',  'AccessType' =>; '0',  'CommodityMsg' => '測試商品1號',  'MerPageUrl' => $this->MerBgUrl,  'MerBgUrl' =>$this->MerPageUrl,  'MerResv' => 'MerResv', ); if (count($paramArray) >0) {  $dispatchUrl = $this->b2cPaySend;  $transResvedJson = array();  $cardInfoJson = array();  $sendMap = array();   foreach ($paramArray as $key => $value) {   if (isEmpty($value)) {    continue;   }   if (startWith($key, "trans_")) {     $key = substr($key, strlen("trans_"));        $transResvedJson[$key] = $value;   } else     if (startWith($key, "card_")) {       $key = substr($key, strlen("card_"));       $cardInfoJson[$key] = $value;     } else {       $sendMap[$key] = $value;     }  }  $transResvedStr = null;  $cardResvedStr = null;  if (count($transResvedJson) >0) {   $transResvedStr = json_encode($transResvedJson);  }  if (count($cardInfoJson) > 0) {   $cardResvedStr = json_encode($cardInfoJson);  } $secssUtil = new SecssUtil(); if (! isEmpty($transResvedStr)) {  $transResvedStr = $secssUtil->decryptData($transResvedStr);  $sendMap["TranReserved"] = $transResvedStr;  } if (! isEmpty($cardResvedStr)) {   $cardResvedStr = $secssUtil->decryptData($cardResvedStr);   $sendMap["card_"] = $cardResvedStr;  }  $securityPropFile = $this>securityPropFile;  $secssUtil->init($securityPropFile);  $secssUtil->sign($sendMap);  $sendMap["Signature"] = $secssUtil->getSign();  $_SESSION = $sendMap;  header("Location:" . $dispatchUrl); }}public function b2cPaySend(){  layout(false);  $settings = new Settings_INI();  $settings->oad($this->securityPropFile);  $pay_url = "https://payment.chinapay.com/CTITS/service/rest/page/nref/000000000017/0/0/0/0/0";  $html = "<form name='payment' action='{$pay_url}' method='POST' target='_blank'>;";  $params = "TranReserved;MerId;MerOrderNo;OrderAmt;CurryNo;TranDate;SplitMethod;BusiType;MerPageUrl;MerBgUrl;SplitType;MerSplitMsg;PayTimeOut;MerResv;Version;BankInstNo;CommodityMsg;Signature;AccessType;AcqCode;OrderExpiryTime;TranType;RemoteAddr;Referred;TranTime;TimeStamp;CardTranData";  foreach ($_SESSION as $k =>$v) {   if (strstr($params, $k)) {     $html .= "<input type='hidden' name = '" . $k . "' value ='" . $v . "'/>";   }  }    $html .= "<nput type='button' type='hidden' value='提交訂單' >";    $html .= "<;/from>";    $this->html = $html;    $this->display();}public function pgReturn(){ if ($_POST) {   if (count($_POST) > 0) {    $secssUtil = new SecssUtil();    $securityPropFile = $this>securityPropFile;    $secssUtil->init($securityPropFile);    $text = array();    foreach($_POST as $key=>$value){      $text[$key] = urldecode($value);    }   if ($secssUtil->verify($text)) {            //支付成功     $_SESSION["VERIFY_KEY"] = "success";   } else {    //支付失敗     $_SESSION["VERIFY_KEY"] = "fail";   }  }  } }}

銀聯支付應該是算比較簡單的!!

總結:以上就是本篇文的全部內容,希望能對大家的學習有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.