工商银行在线支付接口代码

页面代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ICBCBankPay.aspx.cs" Inherits="ICBCBankPay" %>




   


   

    name="frm1" id="frm1">
   
   
   
   
   
   
   
   
   


页面方法:

protected void Page_Load(object sender, EventArgs e)
        {
                string src = string.Empty;
                string _ORDERID = ""//订单号
                string _PAYMENT=""//订单金额
              
                    StringBuilder strSet = new StringBuilder();
                    strSet.Append("");
                    strSet.Append("");
                    strSet.Append("ICBC_PERBANK_B2C");
                    strSet.Append("1.0.0.11");
                    strSet.Append("");
                    strSet.Append("" + DateTime.Now.ToString("yyyyMMddHHmmss") + "");
                    strSet.Append("001");//支付币种
                    strSet.Append("1111111111");//商户代码
                    strSet.Append("");
                    strSet.Append("");
                    strSet.Append("" + _ORDERID + "");//订单号
                    strSet.Append("" + _PAYMENT + "");
                    strSet.Append("1");//分期付款期数    
                    strSet.Append("11111111111");//商户账号
                    strSet.Append("001");//商品编号
                    strSet.Append("");//商品名称
                    strSet.Append("1");//商品数量
                    strSet.Append("");//已含运费金额
                    strSet.Append("
");
                    strSet.Append("
");
                    strSet.Append("
");
                    strSet.Append("");
                    strSet.Append("0");//检验联名标志
                    strSet.Append("ZH_CN");//语言版本
                    strSet.Append("
");
                    strSet.Append("");
                    strSet.Append("2");//支持订单支付的银行卡种类    
                    strSet.Append("HS");
                    strSet.Append("0");//结果发送类型
                    strSet.Append("" + merReference.Value + "");//商户reference
                    strSet.Append("" + merCustomIp.Value + "");//客户端IP
                    strSet.Append("1");//虚拟商品/实    
                    strSet.Append("");//买家用户号    
                    strSet.Append("");//买家联系电话    
                    strSet.Append("");//收货地址    
                    strSet.Append("");//订单备注    
                    strSet.Append("");//商城提示    
                    strSet.Append("");
                    strSet.Append("");
                    strSet.Append("" + merURL.Value + "");
                    strSet.Append("icbc");
                    strSet.Append("
");
                    strSet.Append("
");

                    src = strSet.ToString();
                    var icbc = new ICBCEBANKUTILLib.B2CUtilClass();
                    int log = icbc.init("E:\\shyg10.crt", "E:\\shyg10.crt", "E:\\shyg10.key", "11111111");
                    if (log != 0)
                        icbc.getRC();


                    tranData.Value = EncodeBase64(Encoding.Default,src.Trim());
                    string mer = icbc.signC(src, src.Length);
                    merSignMsg.Value = mer;
                    string ff = icbc.verifySignC(src, src.Length, mer, mer.Length).ToString();
                    merCert.Value = icbc.getCert(1);
                    var aa = icbc.getRC();
        }

///


        /// Base64加密
        ///

        /// 加密采用的编码方式
        /// 待加密的明文
        ///
        public static string EncodeBase64(Encoding encode, string source)
        {
            string decode = string.Empty;
            byte[] bytes = encode.GetBytes(source);
            try
            {
                decode = Convert.ToBase64String(bytes);
            }
            catch
            {
                decode = source;
            }
            return decode;
        }

 

 

支付结果返回页面方法:

支付结果接受:

 if (!string.IsNullOrEmpty(Request["merVAR"]) && Request["merVAR"].ToString().Equals("icbc"))
                {
                    string xml = DecodeBase64(Encoding.Default, Request["notifyData"].ToString());
                   
                    XmlDocument xmldoc = new XmlDocument();
                    xmldoc.LoadXml(xml);
                    string paystate = xmldoc.DocumentElement.SelectSingleNode("/B2CRes/bank/tranStat").InnerText;

                    string orderid= xmldoc.DocumentElement.SelectSingleNode("/B2CRes/orderInfo/subOrderInfoList/subOrderInfo/orderid").InnerText;


                }

///


        /// Base64解密
        ///

        /// 解密采用的编码方式,注意和加密时采用的方式一致
        /// 待解密的密文
        /// 解密后的字符串
        public static string DecodeBase64(Encoding encode, string result)
        {
            string decode = "";
            byte[] bytes = Convert.FromBase64String(result);
            try
            {
                decode = encode.GetString(bytes);
            }
            catch
            {
                decode = result;
            }
            return decode;
        }

注意:项目需要引用ICBCEBANKUTILLib.DLL,该DLL银行都会提供,在这就不上传了。

转载于:https://www.cnblogs.com/tongshengle/archive/2012/02/02/2335952.html

你可能感兴趣的:(工商银行在线支付接口代码)