首页 新闻 赞助 找找看

哪位高人做过工商银行查询接口,看一下此问题请赐教..

0
悬赏园豆:120 [已解决问题] 解决于 2012-03-29 08:41

我导入证书成功也成功了,也添加了可信任站点。但是还是出现证书问题。

点击继续浏览此网页出现这个失败信息,我怀疑是不是我后台写的ssl这里有问题?调试没出现异常错误,期待高人指点

代码如下

View Code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SelectOrderInfo.aspx.cs" Inherits="ICBCBank.SelectOrderInfo" %>

<!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>
<script type="text/javascript">
function selectICBC() {
document.order.submit();
}
</script>
</head>
<body onload="selectICBC()">
<form name="order" id="order" action="https://corporbank3.dccnet.com.cn/servlet/ICBCINBSEBusinessServlet" method="post">
<input type="hidden" name="APIName" value="EAPI" />
<input type="hidden" name="APIVersion" value="001.001.002.001" />
<input type="hidden" name="MerReqData" value="<%=strMerReqData %>" />
</form>
</body>
</html>
View Code
  1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Web;
5 using System.Web.UI;
6 using System.Text;
7 using System.Web.UI.WebControls;
8 using System.Net;
9 using System.IO;
10 using System.Security.Cryptography.X509Certificates;
11 using System.Net.Security;
12
13
14 namespace ICBCBank
15 {
16 public partial class SelectOrderInfo : System.Web.UI.Page
17 {
18 public string strMerReqData = string.Empty;
19 protected void Page_Load(object sender, EventArgs e)
20 {
21 GetOrderInfo();
22 }
23
24 public void GetOrderInfo()
25 {
26
27 StringBuilder strXml = new StringBuilder();
28 strXml.Append("<?xml version=\"1.0\" encoding=\"GBK\" standalone=\"no\"?>");
29 strXml.Append("<ICBCAPI>");
30 strXml.Append("<in>");
31 strXml.Append("<orderNum>2104219229</orderNum>");
32 strXml.Append("<tranDate>20120331</tranDate>");
33 strXml.Append("<ShopCode>XXXXXXX</ShopCode>");
34 strXml.Append("<ShopAccount>XXXXX</ShopAccount>");
35 strXml.Append("</in>");
36 strXml.Append("</ICBCAPI>");
37 string errInfo =string.Empty;
38 CheckOrder("2104219229", "20120331", "XXXXXX", "XXXXXX", out errInfo);
39 strMerReqData = strXml.ToString();
40 }
41
42
43 /**
44 * ''' <summary>
45 ''' 工行专用后台Post
46 ''' </summary>
47 ''' <param name="api_url">工行查询地址</param>
48 ''' <param name="APIName">查询接口名称</param>
49 ''' <param name="APIVersion">查询接口版本号</param>
50 ''' <param name="cert_path">证书路径</param>
51 ''' <param name="icbcKey">证书密码</param>
52 ''' <param name="strOrderNum">银行订单号</param>
53 ''' <param name="strTranDate">交易日期(yyyyMMdd)</param>
54 ''' <param name="strShopCode">商户代码</param>
55 ''' <param name="strShopAccount">商户账号</param>
56 ''' <param name="errInfo">异常时的错误信息</param>
57 ''' <returns>返回工行查询结果1、如果查询成功返回Xml文件,如果失败返回5位错误码</returns>
58 ''' <remarks></remarks>
59 * **/
60 public static string CheckOrder(string strOrderNum, string strTranDate, string strShopCode, string strShopAccount, out string errInfo)
61 {
62
63 errInfo = string.Empty;
64 string api_url = "https://corporbank3.dccnet.com.cn/servlet/ICBCINBSEBusinessServlet";
65 string post_params = "APIName=EAPI&APIVersion=001.001.002.001&MerReqData=";
66 string cert_path = HttpContext.Current.Server.MapPath("~\\bin\\testsz.pfx");
67 string cert_password = "XXXXXXXX";
68
69 StringBuilder sb = new StringBuilder();
70 sb.Append("<?xml version=\"1.0\" encoding=\"GBK\" standalone=\"no\" ?><ICBCAPI><in><orderNum>");
71 sb.Append(strOrderNum);
72 sb.Append("</orderNum><tranDate>");
73 sb.Append(strTranDate);
74 sb.Append("</tranDate><ShopCode>");
75 sb.Append(strShopCode);
76 sb.Append("</ShopCode><ShopAccount>");
77 sb.Append(strShopAccount);
78 sb.Append("</ShopAccount></in></ICBCAPI>");
79
80 string post_data = post_params + sb.ToString();
81 return PostDataBySSL(post_data, api_url, cert_path, cert_password, out errInfo);
82
83 }
84
85 ///<summary>
86 /// SSL
87 ///</summary>
88 ///<param name="post_data"></param>
89 ///<param name="url"></param>
90 ///<param name="cert_path"></param>
91 ///<param name="cert_password"></param>
92 ///<param name="errInfo"></param>
93 ///<returns></returns>
94 private static string PostDataBySSL(string post_data, string url, string cert_path, string cert_password, out string errInfo)
95 {
96 errInfo = string.Empty;
97
98 try
99 {
100 ASCIIEncoding encoding = new ASCIIEncoding();
101 byte[] data = encoding.GetBytes(post_data);
102
103 if (cert_path != string.Empty)
104 //验证证书,默认有效
105 ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);
106
107 //获取结果
108 WebRequest webRequest = WebRequest.Create(url);
109 //配置请求参数
110 HttpWebRequest httpRequest = webRequest as HttpWebRequest;
111
112 if (cert_path.ToLower().EndsWith(".cer"))
113 httpRequest.ClientCertificates.Add(X509Certificate.CreateFromCertFile(cert_path));
114 else
115 httpRequest.ClientCertificates.Add(new X509Certificate2(cert_path, cert_password));
116 //获取或设置一个值,该值指示是否与 Internet 资源建立持久性连接。
117 httpRequest.KeepAlive = true;
118 //获取或设置 User-agentHTTP 标头的值。
119 httpRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)";
120 //获取或设置 Content-typeHTTP 标头的值。
121 httpRequest.ContentType = "application/x-www-form-urlencoded";
122 httpRequest.Method = "POST";
123 // 发送 POST 的 BODY数据 要发送到 Internet 资源的数据的字节数
124 httpRequest.ContentLength = data.Length;
125 Stream requestStream = httpRequest.GetRequestStream(); //获取用于写入请求数据的 Stream 对象
126 requestStream.Write(data, 0, data.Length); //发送带有 HttpWebRequest 的数据
127 requestStream.Close();
128
129 Stream responseStream = null; //从 Internet 资源返回数据流
130 // 获取HTTPs的响应
131 responseStream = httpRequest.GetResponse().GetResponseStream();
132 string stringResponse = string.Empty;
133 if (responseStream != null)
134 {
135 using (StreamReader responseReader =
136 new StreamReader(responseStream, Encoding.GetEncoding("GBK")))
137 {
138 stringResponse = responseReader.ReadToEnd();
139 }
140 responseStream.Close();
141 }
142 return stringResponse;
143 }
144 catch (Exception e)
145 {
146 errInfo = e.Message;
147 return string.Empty;
148 }
149
150
151
152 }
153
154
155 public static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
156 {
157 return true;
158 }
159
160
161 }
162 }
待会起名的主页 待会起名 | 初学一级 | 园豆:96
提问于:2012-03-20 08:57
< >
分享
最佳答案
0

点击“继续浏览此网站”就行了,证书是有IE通过根证书节点验证的。

你的证书的颁发机构必须出现在受信任的证书颁发机构列表里。

你的证书链必须是可被国际根证书节点所验证。

收获园豆:80
Launcher | 高人七级 |园豆:45045 | 2012-03-20 09:09
其他回答(4)
0

期待学习。。。

KivenRo | 园豆:1734 (小虾三级) | 2012-03-20 09:12
0

https

收获园豆:10
jhtchina | 园豆:217 (菜鸟二级) | 2012-03-20 14:29
0

证书不正确或已经过期

收获园豆:30
--宁静以致远-- | 园豆:364 (菜鸟二级) | 2012-03-23 13:50
0

把查询的明文和订单给工行人员看了,工行人员多少天了说没什么问题,也不知道什么原因。证书等都是加过的调试没问题。 上面那两张图是因为我采用了后台提交表单的方式提交了前台又提交了造成安全证书有问题。我这种做法是有点问题的

待会起名 | 园豆:96 (初学一级) | 2012-03-29 08:39
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册