zoukankan      html  css  js  c++  java
  • 工行支付api查询asp.net C# 实现

    工行的测试环境真是非常地烂,给的api查询居然是c++的,还写着dotnet的名字,这里我给出一个asp.net c#的实现

    public class ICBC_API
    {
        
    static string apiUrl = "https://corporbank3.dccnet.com.cn/servlet/ICBCINBSEBusinessServlet";
        
    static string cerPath = ConfigurationManager.AppSettings["CertPath"];
        
    static string cerPwd = ConfigurationManager.AppSettings["CertPwd"];
        
    public ICBC_API()
        {
        }

        
    /// <summary>
        
    /// 订单查询
        
    /// </summary>
        
    /// <param name="orderNum">订单号</param>
        
    /// <param name="tradeDate">订单日期(yyyyMMdd)</param>
        
    /// <param name="shopCode">商户代码</param>
        
    /// <param name="shopAccount">商户帐号</param>
        
    /// <returns></returns>
        public static string B2C(string orderNum,string tradeDate,string shopCode,string shopAccount)
        {
            
    //gen post data
            string postParams = "APIName=EAPI&APIVersion=001.001.002.001&MerReqData={0}";
            StringBuilder sb 
    = new StringBuilder();
            sb.Append(
    "<?xml version=\"1.0\" encoding=\"GBK\" standalone=\"no\" ?><ICBCAPI><in><orderNum>");
            sb.Append(orderNum);
            sb.Append(
    "</orderNum><tranDate>");
            sb.Append(tradeDate);
            sb.Append(
    "</tranDate><ShopCode>");
            sb.Append(shopCode);
            sb.Append(
    "</ShopCode><ShopAccount>");
            sb.Append(shopAccount);
            sb.Append(
    "</ShopAccount></in></ICBCAPI>");
            
    string postData = string.Format(postParams, sb.ToString());

            
    //验证证书,默认有效
            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);

            
    //配置请求参数
            HttpWebRequest wReq = (HttpWebRequest)WebRequest.Create(apiUrl);
            wReq.ContentType 
    = "application/x-www-form-urlencoded";
            wReq.Method 
    = "POST";
            wReq.ClientCertificates.Add(
    new X509Certificate2(HttpContext.Current.Server.MapPath(cerPath), cerPwd));
            ASCIIEncoding encoding 
    = new ASCIIEncoding();
            
    byte[] data = encoding.GetBytes(postData);
            wReq.ContentLength 
    = data.Length;
            Stream reqStream 
    = wReq.GetRequestStream();
            reqStream.Write(data, 
    0, data.Length);
            reqStream.Close();

            
    //获取结果
            WebResponse wResp = wReq.GetResponse();
            Stream respStream 
    = wResp.GetResponseStream();
            
    string stringResp = string.Empty;
            
    if (respStream != null)
            {
                
    using (StreamReader respReader = new StreamReader(respStream,Encoding.GetEncoding("GBK")))
                {
                    stringResp 
    = respReader.ReadToEnd();
                }
                respStream.Close();
            }

            
    return stringResp;
        }
    }
  • 相关阅读:
    linux read的用法[转]
    1>/dev/null 2>&1的含义
    文件的权限
    【原创】server 10.192.242.184 not responding, still trying
    git使用中遇到的错误及解决方法
    linux中mmu作用的简单总结(未完)
    python版本设置
    【转】buntu TELNET服务安装配置
    【转】进程上下文和中断上下文、原子上下文的区别
    【转】【Linux】理解bitops中的__set_bit及其应用
  • 原文地址:https://www.cnblogs.com/Death/p/1992229.html
Copyright © 2011-2022 走看看