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;
        }
    }
  • 相关阅读:
    SBIT
    Linux 系统中进程5中常见状态
    centos yum command
    About DNS
    【从零开始学BPM,Day1】工作流管理平台架构学习
    打破陈规抓痛点,H3 BPM10.0挑战不可能
    H3 BPM让天下没有难用的流程之产品概述
    《中国BPM品牌竞争力指数》完整版
    H3 BPM的品牌制胜之道
    《中国BPM品牌竞争力指数》报告出炉,H3 BPM持续领跑
  • 原文地址:https://www.cnblogs.com/Death/p/1992229.html
Copyright © 2011-2022 走看看