日期:2014-05-18 浏览次数:20399 次
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Runtime.InteropServices; using System.Security.Cryptography.X509Certificates; using System.Net; using System.Security.Cryptography; using System.Web; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Response.Clear(); String xml = System.Web.HttpContext.Current.Server.UrlDecode(CheckOrder()); Response.Write(xml); Response.End(); } String CheckOrder() { ServicePointManager.CertificatePolicy = new AcceptAllCertificatePolicy(); string Url = "https://corporbank.icbc.com.cn/servlet/ICBCINBSEBusinessServlet"; HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(Url); String crtFile = @"D:\ICBC\mybank.crt"; X509Certificate C509 = X509Certificate.CreateFromCertFile(crtFile); req.ClientCertificates.Add(C509); ICBCEBANKUTILLib.B2CUtilClass obj = new ICBCEBANKUTILLib.B2CUtilClass(); obj.init(@"D:\ICBC\WebPayebb2cpublic.crt", @"D:\ICBC\mybank.crt", @"D:\ICBC\mybank.key", "abcdefgh"); //string APIName = "EAPI";ICBC_PERBANK_B2C string APIName = "EAPI"; //APIName = obj.signC(APIName, APIName.Length); // 接口版本号 string APIVersion = "001.001.002.001"; // APIVersion = obj.signC(APIVersion, APIVersion.Length); // 订单号 string orderNum = "0812100002-20081211153520"; //string orderNum = ""; // 交易日期 string tranDate = DateTime.Now.ToString("yyyyMMdd"); //string tranDate = ""; // 商家号码 string ShopCode = "1001EC200012121"; // 商城帐号 string ShopAccount = "10023420719016132421"; string PostData = "APIName=" + APIName + "&APIVersion=" + APIVersion + "&MerReqData=" + System.Web.HttpUtility.UrlEncode("<?xml version=\"1.0\" encoding=\"GBK\" standalone=\"no\" ?><ICBCAPI><in><orderNum>" + orderNum + "</orderNum><tranDate>" + tranDate + "</tranDate><ShopCode>" + ShopCode + "</ShopCode><ShopAccount>" + ShopAccount + "</ShopAccount></in></ICBCAPI>", System.Text.Encoding.Default); byte[] buffer = Encoding.GetEncoding("GBK").GetBytes(PostData); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; req.KeepAlive = true; req.ContentLength = buffer.Length; System.IO.Stream strmRequet = req.GetRequestStream(); if (strmRequet.CanWrite) { strmRequet.Write(buffer, 0, buffer.Length); strmRequet.Close(); strmRequet = null; } HttpWebResponse res = (HttpWebResponse)req.GetResponse(); System.IO.Stream stream = res.GetResponseStream(); //DataSet ds = new DataSet(); //ds.ReadXml(stream); System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); //doc.Load(stream); System.IO.StreamReader sr = new System.IO.StreamReader(stream, System.Text.Encoding.Default); string str = sr.ReadToEnd(); sr.Close(); res.Close(); return str; } internal class AcceptAllCertificatePolicy : ICertificatePolicy { public AcceptAllCertificatePolicy() {