页面代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ChinaBank.aspx.cs" Inherits="ChinaBank.ChinaBank" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body onload="javascript:document.frm1.submit();">
<form action="https://ebspay.boc.cn/PGWPortal/RecvOrder.do" method="post" name="frm1" id="frm1">
<div>
<!--01.商户号-->
<INPUT TYPE="HIDDEN" SIZE="25" ID="merchantNo" NAME="merchantNo" VALUE=""><BR/>
<!--02.支付类型-->
<INPUT TYPE="HIDDEN" SIZE="10" ID="payType" NAME="payType" VALUE="1"><BR/>
<!--03.商户订单号-->
<INPUT TYPE="HIDDEN" SIZE="19" ID="orderNo" NAME="orderNo" VALUE="<%=_orderNo %>"><BR/>
<!--04.订单币种-->
<INPUT TYPE="HIDDEN" SIZE="3" ID="curCode" NAME="curCode" VALUE="001"><BR/>
<!--05.订单金额-->
<INPUT TYPE="HIDDEN" SIZE="13" ID="orderAmount" NAME="orderAmount" VALUE="<%=_orderAmount %>"><BR/>
<!--06.订单时间-->
<INPUT TYPE="HIDDEN" SIZE="14" ID="orderTime" NAME="orderTime" VALUE="<%=_orderTime %>"><BR/>
<!--07.订单说明-->
<INPUT TYPE="HIDDEN" SIZE="30" ID="orderNote" NAME="orderNote" VALUE=""><BR/>
<!--08.商户接收通知URL-->
<INPUT TYPE="HIDDEN" SIZE="100" ID="orderUrl" NAME="orderUrl" VALUE="" /><br />
<!--09.商户签名数据-->
<INPUT TYPE="HIDDEN" ID="signData" NAME="signData" VALUE="<%=_signData %>" />
<br />
</div>
</form>
</body>
</html>
页面方法:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography.Pkcs;
using System.Text;
using System.Configuration;
namespace ChinaBank
{
public partial class ChinaBank : System.Web.UI.Page
{
protected string _orderNo;
protected string _orderAmount;
protected string _orderTime;
protected string _signData;
protected void Page_Load(object sender, EventArgs e)
{
//防止刷新
Response.AddHeader("Pragma", "No-Cache");
Response.Buffer = true;
Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1);
Response.Expires = 0;
Response.CacheControl = "no-cache";
string MerchantCertificate = ""//中国银行pfx证书的路径
string MerchantCertificateKey = ""//证书签名
string _merchantNo = "";//商户号
_orderNo = DateTime.Now.ToString("yyyyMMddHHmmss");//商户订单号
_orderAmount = "0.01";//订单金额
_orderTime = DateTime.Now.ToString("yyyyMMddHHmmss");//订单时间
string _curCode = "001";//订单币种
_signData = _orderNo + "|" + _orderTime + "|" + _curCode + "|" + _orderAmount + "|" + _merchantNo;
X509Certificate2 signerCert = new X509Certificate2(MerchantCertificate, MerchantCertificateKey, X509KeyStorageFlags.MachineKeySet);
SignedCms signedCms = new SignedCms(new ContentInfo(Encoding.UTF8.GetBytes(_signData)), false);
CmsSigner cmsSigner = new CmsSigner(signerCert);
cmsSigner.IncludeOption = X509IncludeOption.EndCertOnly;
signedCms.ComputeSignature(cmsSigner);
_signData = Convert.ToBase64String(signedCms.Encode());
}
}
}
支付结果返回页面方法:
接受返回的参数值
string orderNo = Request["orderNo"];
string orderStatus = Request["orderStatus"];
string orderSeq = Request["orderSeq"];
来源:https://www.cnblogs.com/tongshengle/archive/2012/02/02/2335927.html