Recently, a project called for online payment by Bank of Communications. ecshop itself does not have this interface, so it developed a plug-in through some time research. There are good things to share, of course, I would like to share them here, I hope to help people who have the same needs as me, big... recently, a project called for online payment by Bank of Communications. ecshop itself does not have this interface, so it developed a plug-in through some time research. If there are good things to share, I would like to share them here, hoping to help people who have the same needs as me and relieve the development burden for everyone, please also point out some good methods and suggestions for mutual learning and progress!
Before using the plug-in, configure the online payment environment of the Bank of Communications. (for the installation method, the demo provided by the Bank of Communications is not very difficult. just pay attention to the details ). After the installation, copy the packages folder and ages folder to the root directory of the ecshop site to overwrite (the source code is downloaded at the bottom), and install the payment module in the background.
The following is an example of a call:
Include_once (ROOT_PATH. 'regiondes/modules/payment/bankcomm. php '); $ order _ ['orderid'] = $ order ['Order _ sn']; $ order _ ['amount '] = $ order ['yd _ price']; $ order _ ['ordermono'] = 'test '; // merchant remarks $ order _ ['goodsurl'] = "http ://". $ _ SERVER ['http _ host']. '/respond. php? Code = bankcomm '; // The pick-up URL $ pay_code = new bankcomm; $ pay_button = $ pay_code-> get_code ($ order _); $ order ['pay _ click'] = $ pay_button; // A payment button is generated.
Source code (des/modules/payment/bankcomm. php ):
Bankcomm ();}/*** submit function */function get_code ($ order) {// obtain the data transmitted from the form $ param ['interfaceversion'] = '1. 0.0.0 '; // message version * $ param ['merid'] = '000000'; // merchant ID (Test number, which can be changed later) $ param ['orderid'] = $ order ['orderid']; // order number * $ param ['orderdate'] = local_date ("Ymd", gmtime ()); // merchant Order Date * yyyyMMdd $ param ['ordertime'] = local_date ("His", gmtime ()); // merchant order time * HHmmss $ param ['trantype'] = 0; // transaction type * 0: B2C $ par Am ['amount '] = $ order ['amount']; // order amount * $ param ['curtype'] = 'cny '; // transaction currency * the default value is CNY $ param ['ordercontent'] = ''; $ param ['ordermono'] = $ order ['ordermono']; // merchant remarks $ param ['phdflag'] = ''; // logistics delivery Mark $ param ['policytype'] = 1; // notification method * 1 notification $ param ['merurl'] = ''; $ param ['goodsurl'] = $ order ['goodsurl']; // pickup URL $ param ['jumyun conds '] = ''; $ param ['paybatchno'] =''; $ param ['proxymername'] = ''; $ param ['pro XyMerType '] = ''; $ param ['proxymercredentials'] =''; $ param ['nettype'] = 0; // channel number * 0: html channel $ param ['issbankno'] = ''; $ tranCode =" cb2200_sign "; htmlentities ($ param ['ordermono']," ENT_QUOTES "," UTF-8 "); // connection string $ source = ''; foreach ($ param as $ key => $ val) {if ($ key! = 'Issbankno') $ source. = $ val. '|';} $ source = substr ($ source, 0, strlen ($ source)-1); // connection address http://www.phprm.com $ SocketUrl = "tcp: // 127.0.0.1: 8080"; // the port here is configured according to your own situation $ fp = stream_socket_client ($ socketUrl, $ errno, $ errstr, 30 ); $ retMsg = ""; // if (! $ Fp) {echo "$ errstr ($ errno)
";} Else {$ in ="
"; $ In. ="
"; $ In. ="
". $ TranCode ."
"; $ In. ="
". $ Source ."
"; $ In. ="
"; Fwrite ($ fp, $ in); while (! Feof ($ fp) {$ retMsg = $ retMsg. fgets ($ fp, 1024);} fclose ($ fp);} // Parse the returned 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; // echo "retMsg = ". $ retMsg; // echo $ retCode_value. "". $ errMsg_value. "". $ signMsg_value. "". $ orderUrl_value; if ($ retCode_value! = "0") {// echo "transaction return code:". $ retCode_value ."
"; // Echo" transaction error message: ". $ errMsg_value ."
"; Return" transaction error message: ". $ errMsg_value ."
";} Else {$ param ['signmsg _ value'] = $ signMsg_value; $ param ['orderurl _ value'] = $ orderUrl_value; $ form_code = $ this-> create_html ($ param); // Create a submission form return $ form_code ;}/ *** create a submission form */function create_html ($ param) {$ pay_html = ''; return $ pay_html;}/*** processing function */function respond () {$ tranCode =" cb2200_verify "; $ policymsg = $ _ REQUEST ["policymsg"]; $ lastIndex = strripos ($ policymsg, "|"); $ signM Sg = substr ($ notifyMsg, $ lastIndex + 1); // signature information $ srcMsg = substr ($ notifyMsg, 0, $ lastIndex + 1 ); // original // connection address $ socketUrl = "tcp: // 127.0.0.1: 8080"; $ fp = stream_socket_client ($ socketUrl, $ errno, $ errstr, 30 ); $ retMsg = ""; if (! $ Fp) {// echo "$ errstr ($ errno)
"; Return false;} else {$ in ="
"; $ In. ="
"; $ In. ="
". $ TranCode ."
"; $ In. ="
". $ Policymsg ."
"; $ In. ="
"; Fwrite ($ fp, $ in); while (! Feof ($ fp) {$ retMsg = $ retMsg. fgets ($ fp, 1024);} fclose ($ fp);} // Parse the returned 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; if ($ retCode_value! = '') {// Echo" transaction return code: ". $ retCode_value ."
"; // Echo" transaction error message: ". $ errMsg_value ."
"; Return false;} else {$ arr = preg_split ("/| {1,}/", $ srcMsg); $ pay_id = $ arr [1]; $ action_note = base64_decode ($ arr [16]); // complete the order. Order_paid ($ pay_id, PS_PAYED, $ action_note); // tell the user to return true after the transaction is completed ;} /// // respond END //}?>
Source code (ages/zh_cn/payment/bankcomm. php ):
: 13962827995368.zip
Tutorial URL:
You are welcome to add your _ favorites to the Favorites folder, but please keep the link for this article.