• 工行支付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;
        }
    }
  • 相关阅读:
    如何在EasyDSS内调用的iframe地址设置自动播放?
    雏鹰训练营第一次作业
    211806152 蔡钰玲 http://www.cnblogs.com/211806152Erika/ https://github.com/ErikaSakii
    Python05:while循环
    Python04:简单if逻辑判断
    Python03:用户交互输入格式输出
    Python02:变量
    Python01:HelloWorld
    课后作业(一)
    软工假期预先作业
  • 原文地址:https://www.cnblogs.com/Death/p/1992229.html
Copyright © 2020-2023  润新知