Php UnionPay payment interface development concise tutorial, php concise tutorial
This article describes how to develop the UnionPay payment interface for php. We will share this with you for your reference. The details are as follows:
The payment interface now has a third-party payment interface and a bank payment interface. Here we will introduce the php UnionPay payment interface development method.
Pay attention to the following two important parts:
PHP running environment is 5.4.18 or above
Openssl extension is enabled
The column above in the development manual is only for reference, because it is basically wrong. You can try to go to the next demo on the official website... Note: currently, UnionPay development does not provide a test key. It can only be developed in a formal environment.
The following is a payment class I wrote using ThinkPHP.
/*** UnionPay payment v0.1 * @ auther: Summer <dengwz7788@gmail.com>; * @ date: 20151202 ***/class NetPayAction extends BaseAction {// in the class initialization method, introduce the related class library public function _ initialize () {header ("Content-type: text/html; charset = UTF-8"); vendor ('netpay. util. common ',"",". php "); // import the encryption core folder vendor ('netpay. util. secssUtil ',"",". class. php "); // import the encryption core folder vendor ('netpay. util. settings_INI ',"",". php "); // import the encryption core folder vendor ('netpay. util. S Etemediacs ',"",". php "); // import the encrypted core folder $ this-> securityPropFile =$ _ SERVER ['document _ root']. "/ThinkPHP/Extend/Vendor/Netpay/config/security. properties "; // who knows what this is? They asked me to add $ this-> b2cPaySend = _ APP __. "/Index/NetPay/b2cPaySend"; $ this-> b2cRefundSend = _ APP __. "/Index/NetPay/b2cRefundSend"; $ this-> b2cQuerySend = _ APP __. "/Index/NetPay/b2cQuerySend"; $ this->; MerBgUrl = _ APP __. "/Index/NetPay/MerBgUrl"; $ thi S-> MerPageUrl = _ APP __. "/Index/NetPay/MerPageUrl";} public function index () {$ paramArray = array ('merid' => 'Merchant ID ', 'merorderno' => '123 ', 'orderamt '=> '1', 'trandate' => '20140901', 'trantime' => '20160901', 'trantype' => '20160901 ', 'busitype' => '000000', 'version' => '000000', 'curryno' => 'cny ', 'accessstype' =>; '0 ', 'commoditymsg '=> 'test Item 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 = require ($ 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; reverse; MerBgUrl; SplitType; MerSplitMsg; PayTimeOut; MerResv; Version; reverse; CommodityMsg; signature; AccessType; AcqCode; OrderExpiryTime; TranType; RemoteAddr; Referred; TranTime; TimeStamp; CardTranData "; foreach ($ _ SESSION as $ k => $ v) {if (strstr ($ params, $ k) {$ html. = "<input type = 'did' name = '". $ k. "'value = '". $ v. "'/>" ;}}$ html. = "<nput type = 'button 'Type = 'hidd' value = 'submit order'>"; $ 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) {// payment successful $ _ SESSION ["VERIFY_KEY"] = "success ";} else {// payment failed $ _ SESSION ["VERIFY_KEY"] = "fail ";}}}}}
UnionPay payment should be relatively simple !!