This article illustrates the development method of the PHP UnionPay payment interface. Share to everyone for your reference, specific as follows:
The payment interface now has a third party payment interface as well as a bank payment interface. Here is a introduction to the PHP version of the UnionPay payment interface development methods.
Pay for UnionPay, first of all pay attention to two important parts:
PHP operating environment is 5.4.18 or more
Open the extension OpenSSL
Development manuals The above is only for reference, because the basic is wrong. You can try to go to the official website next demo ... Note that now UnionPay development, no test key provided, can only be developed in the formal environment
Here is a payment class that I wrote with thinkphp
/** * UnionPay pays v0.1 * @auther:summer<dengwz7788@gmail.com>; * @date: 20151202 * **/class Netpayaction extends baseaction{//In class initialization method, introduce the related class Library public function _initialize () {Header ("C
Ontent-type:text/html;charset=utf-8 "); Vendor (' Netpay.util.common ', "", ". php"); Import Encryption Core folder vendor (' Netpay.util.SecssUtil ', "", ". class.php"); Import Encryption Core folder vendor (' Netpay.util.Settings_INI ', "", ". php"); Import Encryption Core folder vendor (' Netpay.util.Settings ', "", ". php"); Import Encryption Core folder $this->securitypropfile= $_server[' Document_root ']. "/thinkphp/extend/vendor/netpay/config/security.properties"; Who knows what this is, anyway they want me to add the $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 ' => ' Merchant number ', ' Merorderno ' => ' 0000001944663232 ', ' Orderamt ' => ' 1 ', ' trandate ' => ' 20151219 ', ' trantime ' => ' 171248 ', ' trantype ' => ' 0001 ', ' Busitype ' => ' 0001 ', ' Version ' => ' 20140728 ', ' curryno ' => ' CNY ', ' AccessType ' =>; ' 0 ', ' commoditymsg ' => ' test Product # 1th ', ' 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);
The 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);
The 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= ' submit order ' >";
$html. = "<;/from>";
$this->html = $html;
$this->display ();
The 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)) {//Paid successfully $_session["verify_key"] = "success";
else {//payment failed $_session["Verify_key"] = "fail";
}
}
}
}
}
UnionPay payment should be relatively simple!!
More about PHP Interested readers can view the site topics: "PHP common Database Operation skills Summary", "PHP array" operation Skills Daquan, "PHP Sorting algorithm Summary", "PHP common traversal algorithm and skills summary", "PHP Data structure and algorithm tutorial", " PHP Programming algorithm Summary, "PHP Mathematical Calculation Skills Summary", "PHP Regular Expression Usage summary", "PHP operation and operator usage Summary" and "PHP string (String) Usage Summary"
I hope this article will help you with the PHP program design.