Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to develop UnionPay payment interface in php version

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you the php version of how to develop UnionPay payment interface, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

UnionPay should first pay attention to two important parts:

The PHP operating environment is above 5.4.18.

Extended openssl is opened.

The columns in the development manual are for reference only, because they are basically wrong. You can try to go to a demo on the official website. Note that UnionPay is now developed. There is no test key provided, and it can only be developed in a formal environment.

Here is a payment class I wrote in ThinkPHP

/ * * UnionPay v0.1 * @ auther:Summer;* @ date:20151202* / class NetPayAction extends BaseAction {/ / in the class initialization method, introduce the relevant class library public function _ initialize () {header ("Content-type:text/html;charset=utf-8"); vendor ('Netpay.util.common', "," .php "); / / Import the encrypted core folder vendor (' Netpay.util.SecssUtil',", ".class.php") / / Import the encrypted core folder vendor ('Netpay.util.Settings_INI', "," .php "); / / import the encrypted core folder vendor (' Netpay.util.Settings',", ".php"); / / import the encrypted core folder $this- > securityPropFile= $_ SERVER ['DOCUMENT_ROOT']. "/ ThinkPHP/Extend/Vendor/Netpay/config/security.properties"; / / who knows what it is, but they want 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"; $this- > MerPageUrl = _ _ APP__. "/ Index/NetPay/MerPageUrl" } public function index () {$paramArray=array ('MerId' = >' merchant number', 'MerOrderNo' = >' 00001944663232', 'OrderAmt' = >' 1Qing, 'TranDate' = >' 20151219', 'TranTime' = >' 171248', 'TranType' = >' 0001', 'BusiType' = >' 0001', 'Version' = >' 20140728', 'CurryNo' = >' CNY', 'AccessType' = > '0commodity,' 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 = 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 ="; "; $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;TimeStCardTranData "; foreach ($_ SESSION as $k = > $v) {if (strstr ($params, $k)) {$html. =";}} $html. = "; $html. ="; $this- > html = $html; $this- > display ();} public function pgReturn () {if ($_ POST) {if ($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 succeeded $SESSION ["VERIFY_KEY"] = "success";} else {/ / payment failed $_ SESSION ["VERIFY_KEY"] = "fail" } above are all the contents of the article "how to develop UnionPay payment interface in php version". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report