In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how to get started with the php version of Bank of Communications online bank payment interface development. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it.
Summary: the online bank payment interface and Alipay interface are generally similar, the main difference is that the core of the interface provided by the Bank of Communications, for example, encryption is achieved through java, so, to find a way to make php and java can communicate normally, to this end, the official also provides two sets of implementation methods, one is to communicate through socket, the other is to bridge through java, the following is a demonstration of socket method.
1. Configure the running environment
1.1 install java, download java from oracle website, then install and configure the correct environment variables.
1.2 Import the test certificate into the java virtual machine.
Keytool "- import-keystore" address where the java virtual machine places the certificate "- storepass changeit-alias test_bocommca-file" Certificate path completes the import.
Example: keytool "- import-keystore" C:\ Program Files\ Java\ jre1.5\ lib\ security\ cacerts "- storepass changeit-alias test_bocommca-file" C:\ socket\ cert\ test_root.cer "
1.3 modify the configuration file (in/B2CMerchantSocket.xml).
When testing with an official test firm, there is no need for configuration, otherwise it should be configured, as described in the xml file.
1.4 start the socket service
Window: start start.bat and can.
Linux: start ohup sh.start,sh& / / to detach the current script from the terminal and run it in the background.
two。 Integrate the network bank into the existing system and explain it with the structure of mvc.
2.1 write the unchanged parameter configuration to the configuration file:
$config ['interfaceVersion'] = "1.0.0.0"; # Interface version $config [' tranType'] = 0; # transaction category 0:B:C$config ['curType'] =' CNY'; # transaction currency $config ['notifyType'] = 1; # 0 = No Notification 1 = Notification 2 = crawling $config [' merURL'] = "/ pay/notify"; # proactive Notification url$config ['goodsURL'] =' / goods/1.html'; # pickup url$config ['jumpSeconds'] = 3 # Jump time $config ['payBatchNo'] =''; # Merchant batch number $config ['proxyMerName'] =''; # Agent merchant name $config ['proxyMerType'] =''; # Agent type $config ['proxyMerCredentials'] =''; # Agent vendor batch number $config ['netType'] = 0; # Channel number / below is the parameter required for the new interface $config [' socketUrl'] = "tcp://127.0.0.1:8891" # socket url$config ['merID'] =' 301310063009501; # merchant id 3013100630095012
2.2 Model
/ * Bank of Communications payment class * / class Bocom extends CI_Model {private $arrReturn=array (); private $socket; public function _ construct () {parent::__construct (); / / load Bank of Communications configuration file $this- > config- > load ('bocom'); $this- > socket=$this- > config- > item (' socketUrl') } / * payment method * * @ param unknown $arr_data=array (* 'bill_no'= > *) * / public function pay ($arr_data) {/ / get the data passed from the form $this- > arrReturn [' interfaceVersion'] = $this- > config- > item ('interfaceVersion'); $this- > arrReturn [' merID'] = $this- > config- > item ('merID') / the merchant number is fixed $this- > arrReturn ['orderid'] = $arr_data [' bill_no']; $this- > arrReturn ['orderDate'] = $arr_data [' bill_date']; $this- > arrReturn ['orderTime'] = $arr_data [' bill_time']; $this- > arrReturn ['tranType'] = $this- > config- > item (' tranType'); $this- > arrReturn ['amount'] = $arr_data [' bill_fee']; $this- > arrReturn ['curType'] = $this- > config- > item (' curType') $this- > arrReturn ['orderContent'] = isset ($arr_data [' bill_title'])? iconv ('utf-8','gb2312',$arr_data ["bill_title"]):'; # order content $this- > arrReturn ['orderMono'] = isset ($arr_data [' bill_mono'])? Iconv ('utf-8','gb2312',$arr_data [' bill_mono']):'; # Merchant remarks $this- > arrReturn ['phdFlag'] = isset ($arr_data [' phpFlag'])? $arr_data ['phpFlag']:''; $this- > arrReturn ['notifyType'] = $this- > config- > item (' notifyType'); $this- > arrReturn ['merURL'] = $this- > config- > item (' merURL'); $this- > arrReturn ['goodsURL'] = $this- > config- > item (' goodsURL') $this- > arrReturn ['jumpSeconds'] = $this- > config- > item (' jumpSeconds'); $this- > arrReturn ['payBatchNo'] = $this- > config- > item (' payBatchNo'); $this- > arrReturn ['proxyMerName'] = $this- > config- > item (' proxyMerName'); $this- > arrReturn ['proxyMerType'] = $this- > config- > item (' proxyMerType'); $this- > arrReturn ['proxyMerCredentials'] = $this- > config- > item (' proxyMerCredentials'); $this- > this- ['arrReturn] = $arrReturn > netType' > netType' (' this-) / / the following parameters do not participate in signing $this- > arrReturn ['issBankNo'] = isset ($arr_data [' code_id'])? Trim ($arr_data ['code_id']):''; $tranCode = "cb2200_sign"; $source=''; $len = count ($this- > arrReturn)-1 arrReturn; foreach ($this- > arrReturn as $v) {if ($jsocket,$errno, $errstr, 30); $retMsg= "; if (! $fp) {log_message (" info "," socket connection failure "); return false;} else {$in ="; $in. = "; $in. =" .$ tranCode. " $in. = "". $source. "; $in. ="; fwrite ($fp, $in); while (! feof ($fp)) {$retMsg = $retMsg.fgets ($fp, 1024);} fclose ($fp);} if (falsehood caused by falsehood) (is_array ($xml_arr)) {foreach ($xml_arr as $k = > $v) {$this- > arrReturn [$k] = $v;} else {return false }} else {return false;} return $this- > arrReturn;} / * * parsing XML * / public function xmlParse ($retMsg) {$arr=array (); / / parsing returns xml $dom = new DOMDocument; $dom- > loadXML ($retMsg); $retCode = $dom- > getElementsByTagName ('retCode'); $retCode_value = $retCode- > item (0)-> nodeValue; $errMsg = $dom- > getElementsByTagName (' errMsg'); $errMsg_value = $errMsg- > item (0)-> nodeValue; $signMsg = $dom- > getElementsByTagName ('signMsg') $signMsg_value = $signMsg- > item (0)-> nodeValue; $orderUrl = $dom- > getElementsByTagName ('orderUrl'); $orderUrl_value = $orderUrl- > item (0)-> nodeValue; $MerchID = $dom- > getElementsByTagName (' MerchID'); $merID = $MerchID- > item (0)-> nodeValue; if ($retCode_value! = "0") {log_message ("info", "transaction return code:". $retCode_value); log_message ("info", "transaction error message:. $errMsg_value); return false" } $arr ['merSignMsg'] = $signMsg_value; $arr [' merID'] = $merID; $arr ['orderUrl'] = $orderUrl_value; return $arr;} / * * Bank of Communications payment Notification * @ return boolean | unknown * / public function notify () {$tranCode = "cb2200_verify"; if (! isset ($_ REQUEST [' notifyMsg']) {log_message ("error", "illegal request for online Bank payment Notification"); return false } $notifyMsg = $_ REQUEST ["notifyMsg"]; log_message ("error", $notifyMsg. " Callback. "); $lastIndex = strripos ($notifyMsg," | "); $signMsg = substr ($notifyMsg,$lastIndex+1); / / signature information $srcMsg = substr ($notifyMsg,0,$lastIndex+1); / / original $merID = $this- > config- > item ('merID'); $fp = stream_socket_client ($this- > socket, $errno, $errstr, 30); $retMsg="; / / if (! $fp) {echo "$errstr ($errno)\ n"; log_message ("error", "$errstr ($errno)\ n") } else {$in = ""; $in. = ""; $in. = ". $tranCode."; $in. = ". $merID."; $in. = ". $notifyMsg."; $in. = ""; fwrite ($fp, $in); while (! feof ($fp)) {$retMsg = $retMsg.fgets ($fp, 1024);} fclose ($fp);} / / parsing returns xml $dom = new DOMDocument; $dom- > loadXML ($retMsg); $retCode = $dom- > getElementsByTagName ('retCode') $retCode_value = $retCode- > item (0)-> nodeValue; $errMsg = $dom- > getElementsByTagName ('errMsg'); $errMsg_value = $errMsg- > item (0)-> nodeValue; if ($retCode_value! =' 0') {log_message ("error", "transaction error message:. $errMsg_value."
); return false;} else {$arr = preg_split ("/\ | {1,} /", $srcMsg); if ($arr [9] = = "1") {return $this- > updateBill ($arr [1]);} log_message ("error", "deal failed:". $arr [13]. "); return false;} private function updateBill ($billNo) {/ / update order status} / / end class}
2.3 Controller
$this- > load- > model ("Bocom")
Method of payment:
$this- > arrData = $this- > Bocom- > pay ($this- > data)
Notification:
$this- > arrData = $this- > Bocom- > notify (); the above is how to get started with the php version of Bank of Communications online bank payment interface development. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.