2 qq 22782705 qq_22782705 于 2015.07.22 16:05 提问

中国银行接口后台POST提交

中国银行退款接口,在后台POST提交不走页面。在请求是报错请求被中止: 未能创建 SSL/TLS 安全通道。代码如下
string Number = CreateRandomCode(30);
posturl = "https://ebspay.boc.cn/PGWPortal/RefundOrder.do";

        pastData = ChinaBlankConfig.merchantNo + "|" + Number + "|" + "001" + "|" + 0.01 + "|" + "20121206SHKF000004";
        byte[] _bytedata = System.Text.Encoding.UTF8.GetBytes(pastData);
        string _strSignData = PKCS7Tool.SignatureMessage(cerPath, cerWord, _bytedata, string.Empty);
        string _singDate = "merchantNo=" + ChinaBlankConfig.merchantNo + "&mRefundSeq=" + Number + "&curCode=001" + "&refundAmount=" + 0.01 + "&orderNo=20121206SHKF000004" + "&signData=" + _strSignData;
        string str = RequestAndResponse(posturl, _singDate);
                     //初始化请求对象
    var request = WebRequest.Create(url) as HttpWebRequest;
    //X509证书
    //X509Certificate2 cert = new System.Security.Cryptography.X509Certificates.X509Certificate2(cerPath, "111111", X509KeyStorageFlags.MachineKeySet);
    //request.ClientCertificates.Add(cert);
    X509Certificate cert = new System.Security.Cryptography.X509Certificates.X509Certificate(cerPath, "111111");
    X509Certificate cert2 = new System.Security.Cryptography.X509Certificates.X509Certificate(keyStorePath);
    request.ClientCertificates.Add(cert2);
    request.ClientCertificates.Add(cert);
    request.ImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

    //设定验证回调(总是同意)
    ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
    request.Method = "POST";
    request.ContentType = "application/x-www-form-urlencoded";
    request.ContentLength = Encoding.UTF8.GetByteCount(postData);
    request.Timeout = 300000;
    request.ReadWriteTimeout = 300000;
    //将来数据内容写入传输数据流中,并传输
    using (var requestStream = request.GetRequestStream())
    {
        using (var streamWriter = new StreamWriter(requestStream))
        {
            streamWriter.Write(postData);
        }
    }

    //初始化响应对象
    var response = request.GetResponse() as HttpWebResponse;

    //从传输流中对象返回的数据
    using (var responseStream = response.GetResponseStream())
    {
        using (var streamReader = new StreamReader(responseStream))
        {
            return streamReader.ReadToEnd();
        }
    }

1个回答

oyljerry
oyljerry   Ds   Rxr 2015.07.22 16:20

对应的HTTPS接口可以直接请求吗,你可以用Chrome的postman等模拟提交一下测试一下,看服务器是否HTTPS接口有问题

oyljerry
oyljerry 回复qq_22782705: 如果有时候成功,那更看上去是网络等问题
2 年多之前 回复
qq_22782705
qq_22782705 奇怪的是,有时候请求成功了,有时候失败。还有就是参数什么的我都传对了,可就是报签名错误。
2 年多之前 回复
qq_22782705
qq_22782705 回复oyljerry: 银行给的公钥和私钥
2 年多之前 回复
oyljerry
oyljerry 回复qq_22782705: 你添加的几个证书,是否正确
2 年多之前 回复
qq_22782705
qq_22782705 前台提交过去没问题,后台POST不行
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片