日期:2014-05-18  浏览次数:20399 次

|zyciis| 超急 网站添加工商银行网上支付的工能,在用代码去取数据的时候如果在文件系统中是OK的,但是如果是在IIS中就出错 快帮帮忙 谢谢
以下是慕白兄提供 在文件系统中是可以用的,但是在IIS中不行
那IIS要怎么设置呢
C# code

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()
        {