PHP implementation of the Bank of Communications network Silver Online payment interface Ecshop plug-ins and use examples _php instance

Source: Internet
Author: User
Tags pack

Recently, a project required to do Bank of communications online payment, Ecshop itself does not have this interface, so through some time of the specialized research, made a plug-in out. There are good things, of course, to share, in this special to share out, hope to be able to help the same as I have the needs of people, for everyone to reduce the burden of development, but also more please point out some good methods and suggestions, mutual learning, progress!


Before using Plug-ins, please configure the Bank of Communications online payment environment (specific installation methods, delivery of the demo will have, it is not difficult to pay attention to the good details on the line). After installation, please put the following plug-in source code and language pack source code according to the path to the corresponding file, and finally into the Backstage Payment module installation can be.


Plugin source code (includes/modules/payment/bankcomm.php):

Copy Code code as follows:

<?php

/**
* Bank of Communications online payment plugin for Ecshop
* Author:reson
* DATE:2014/03/31
*/

if (!defined (' in_ecs '))
{
Die (' Hacking attempt ');
}

$payment _lang = Root_path. ' languages/'. $GLOBALS [' _cfg '] [' Lang ']. '/payment/bankcomm.php ';

if (file_exists ($payment _lang))
{
Global $_lang;
Include_once ($payment _lang);
}

/* The basic information of the module * *
if (Isset ($set _modules) && $set _modules = = TRUE)
{
$i = Isset ($modules)? Count ($modules): 0;

/* Code * *
$modules [$i] [' code '] = basename (__file__, '. php ');

/* Describe the corresponding language item * *
$modules [$i] [' desc '] = ' bankcomm_desc ';

/* Whether to support the payment of goods/
$modules [$i] [' is_cod '] = ' 0 ';

/* Whether to support online payment * *
$modules [$i] [' is_online '] = ' 1 ';

* * Payment fee, by the distribution decision * *
$modules [$i] [' pay_fee '] = ' 0 ';

/* Author * *
$modules [$i] [' author '] = ' reson ';

/* URL * *
$modules [$i] [' website '] = ' http://www.jb51.net ';

/* Version Number * *
$modules [$i] [' version '] = ' 1.0.0.0 ';

/* Configuration Information * *
$modules [$i] [' config '] = array ();

Return
}

/**
* Class
*/
Class Bankcomm
{
/**
* Constructor
*
* @return void
*/
function Bankcomm ()
{
}

function __construct ()
{
$this->bankcomm ();
}

/**
* Submit function
*/
function Get_code ($order)
{
Get the data from the table conveys.
$param [' interfaceversion '] = ' 1.0.0.0 '; Message Version number *
$param [' merid '] = ' 301310063009501 '; Merchant Number (test number, 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
$param [' amount '] = $order [' Amount ']; Order Amount *
$param [' curtype '] = ' CNY '; Transaction currency * Default CNY
$param [' ordercontent '] = ';
$param [' ordermono '] = $order [' Ordermono ']; Merchant notes
$param [' phdflag '] = '; Logistics and distribution signs
$param [' notifytype '] = 1; Notification Mode * 1 notice
$param [' merurl '] = ';
$param [' goodsurl '] = $order [' Goodsurl ']; Picking URL
$param [' jumpseconds '] = ';
$param [' paybatchno '] = ';
$param [' proxymername '] = ';
$param [' proxymertype '] = ';
$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
$SOCKETURL = "tcp://127.0.0.1:8080"; The ports here are based on their own configuration
$fp = Stream_socket_client ($socketUrl, $errno, $errstr, 30);
$RETMSG = "";
//
if (! $fp) {
echo "$errstr ($errno) <br/>\n";
} else
{
$in = "<?xml version= ' 1.0 ' encoding= ' UTF-8 '?> '";
$in. = "<Message>";
$in. = "<TranCode>". $tranCode. " </TranCode> ";
$in. = "<MsgContent>". $source. " </MsgContent> ";
$in. = "</Message>";
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;

$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. " <br> ";
echo "Transaction error message:". $ERRMSG _value. " <br> ";
Return "Transaction error message:". $ERRMSG _value. " <br> ";
}else{
$param [' signmsg_value '] = $SIGNMSG _value;
$param [' orderurl_value '] = $ORDERURL _value;
$form _code = $this->create_html ($param); Create a Submit form
return $form _code;
}

}

/**
* Create Submit Form
*/
function create_html ($param) {
$pay _html = ' <form name = ' Form1 ' method = ' post ' action = '. $param [' Orderurl_value ']. ' >
<input type = "hidden" name = "Interfaceversion" value = "'. $param [' interfaceversion ']. '" >
<input type = "hidden" name = "Merid" value = "'. $param [' Merid ']. '" >
<input type = "hidden" name = "OrderID" value = "'. $param [' OrderID ']. '" >
<input type = "hidden" name = "OrderDate" value = "'. $param [' orderDate ']. '" >
<input type = "hidden" name = "Ordertime" value = "'. $param [' Ordertime ']. '" >
<input type = "hidden" name = "Trantype" value = "'. $param [' Trantype ']. '" >
<input type = "hidden" name = "Amount" value = "'. $param [' Amount ']. '" >
<input type = "hidden" name = "Curtype" value = "'. $param [' Curtype ']. '" >
<input type = "hidden" name = "Ordercontent" value = "'. $param [' ordercontent ']. '" >
<input type = "hidden" name = "Ordermono" value = "'. $param [' Ordermono ']. '" >
<input type = "hidden" name = "Phdflag" value = "'. $param [' Phdflag ']. '" >
<input type = "hidden" name = "Notifytype" value = "'. $param [' Notifytype ']. '" >
<input type = "hidden" name = "Merurl" value = "'. $param [' Merurl ']. '" >
<input type = "hidden" name = "Goodsurl" value = "'. $param [' Goodsurl ']. '" >
<input type = "hidden" name = "Jumpseconds" value = "'. $param [' jumpseconds ']. '" >
<input type = "hidden" name = "Paybatchno" value = "'. $param [' Paybatchno ']. '" >
<input type = "hidden" name = "Proxymername" value = "'. $param [' Proxymername ']. '" >
<input type = "hidden" name = "Proxymertype" value = "'. $param [' Proxymertype ']. '" >
<input type = "hidden" name = "Proxymercredentials" value = "'. $param [' proxymercredentials ']. '" >
<input type = "hidden" name = "NetType" value = "'. $param [' NetType ']. '" >
<input type = "hidden" name = "Mersignmsg" value = "'. $param [' Signmsg_value ']. '" >
<input type = "hidden" name = "Issbankno" value = "'. $param [' Issbankno ']. '" >

<input type= "Submit" value= "" class= "Pay_button"/>
</form> ';
return $pay _html;
}

/**
* Processing functions
*/
function respond ()
{
$tranCode = "Cb2200_verify";
$NOTIFYMSG = $_request["Notifymsg"];
$lastIndex = Strripos ($NOTIFYMSG, "|");
$SIGNMSG = 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) <br/>\n";
return false;
}else{
$in = "<?xml version= ' 1.0 ' encoding= ' UTF-8 '?> '";
$in. = "<Message>";
$in. = "<TranCode>". $tranCode. " </TranCode> ";
$in. = "<MsgContent>". $notifyMsg. " </MsgContent> ";
$in. = "</Message>";
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;

$SIGNMSG = $dom->getelementsbytagname (' signmsg ');
$SIGNMSG _value = $signMsg->item (0)->nodevalue;

if ($retCode _value!= ') {
echo "Transaction return code:". $retCode _value. " <br> ";
echo "Transaction error message:". $ERRMSG _value. " <br> ";
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 that the transaction is complete
return true;
}

Respond End///////////////
}

}

?>


Language Pack source code (languages/zh_cn/payment/bankcomm.php):
Copy Code code as follows:

<?php

/**
* Bank of communications Language document
* By:reson
* 2014/03/31
*/

Global $_lang;

$_lang[' bankcomm '] = ' Bank of communications online payment ';
$_lang[' bankcomm_desc '] = ' Bank of communications online payment ';
$_lang[' Pay_button '] = ' Bank of communications ' payment ';

?>

The following is an example of a call:

Copy Code code as follows:

Include_once (Root_path. ' includes/modules/payment/bankcomm.php ');
$order _[' orderid '] = $order [' order_sn '];
$order _[' amount '] = $order [' Yd_price '];
$order _[' ordermono '] = ' test '; Merchant notes
$order _[' goodsurl '] = "http://". $_server[' Http_host ']. ' /respond.php?code=bankcomm '; Picking URL
$pay _code = new Bankcomm;
$pay _button = $pay _code->get_code ($order _);
$order [' pay_button '] = $pay _button; That is, a pay button has been generated at this time

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.