页面代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ICBCBankPay.aspx.cs" Inherits="ICBCBankPay" %>
页面方法:
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("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
strSet.Append("
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银行都会提供,在这就不上传了。