/// <summary> /// 建设银行个人网银二维码接口 /// </summary> /// <param name="construnctionData">提交的参数</param> /// <param name="timeOut">超时时间</param> /// <returns></returns> public static ConstructionData RQCode(ConstructionData construnctionData, int timeOut = 6) { //第三方商户提交给网银的网关地址:注意用post方式提交参数 string url = "https://ibsbjstar.ccb.com.cn/CCBIS/ccbMain?CCB_IBSVersion=V6"; //判断必传参数 if (!construnctionData.IsSet("ORDERID"))//订单号 { throw new ConstructionException("提交二维码接口中,缺少必填参数订单号【ORDERID】!"); } if (!construnctionData.IsSet("PAYMENT"))//付款金额 { throw new ConstructionException("提交二维码接口中,缺少必填参数付款金额【PAYMENT】!"); } if (!construnctionData.IsSet("MERCHANTID"))//商户代码 { construnctionData.SetValue("MERCHANTID", ConstructionConfig.Initialize().GetMerchantId()); } if (!construnctionData.IsSet("POSID"))//商户柜台代码 { construnctionData.SetValue("POSID", ConstructionConfig.Initialize().GetPosId()); } if (!construnctionData.IsSet("BRANCHID"))//分行代码 { construnctionData.SetValue("BRANCHID", ConstructionConfig.Initialize().GetBranchId()); } if (!construnctionData.IsSet("CURCODE"))//币种 { construnctionData.SetValue("CURCODE", "01"); } if (!construnctionData.IsSet("TXCODE"))//交易码 { construnctionData.SetValue("TXCODE", "530550"); } if (!construnctionData.IsSet("RETURNTYPE"))//返回类型 { construnctionData.SetValue("RETURNTYPE", "3"); } construnctionData.SetValue("MAC", construnctionData.MACCheck());//MAC校验域 string param = construnctionData.Joint(); string response = Post(param, url, timeOut);//调用HTTP通信接口以提交数据到API ConstructionData data = new ConstructionData(); data.Dictionary(response); return(data); }
/// <summary> /// MAC校验 /// MAC字段参与摘要运算的字符串及其顺序: /// 注意:PUB字段为对应柜台的公钥后30位 /// MERCHANTID = 123456789 & POSID = 000000000 & BRANCHID = 110000000 & ORDERID = 19991101234 & PAYMENT = 0.01 & CURCODE = 01 & TXCODE = 530550 & REMARK1 = &REMARK2 = &RETURNTYPE = 3 & TIMEOUT = &PUB = 30819d300d06092a864886f70d0108 /// </summary> /// <returns>返回加密字符串</returns> public string MACCheck() { try { //获取对应柜台的公钥后30位 string pub = ConstructionConfig.Initialize().GetPub(); string REMARK1, REMARK2, TIMEOUT, RETURNTYPE; //判断是否存在REMARK1 if (keyValuePairs.Keys.Contains("REMARK1")) { REMARK1 = keyValuePairs["REMARK1"].ToString(); } else { REMARK1 = ""; } //判断是否存在REMARK2 if (keyValuePairs.Keys.Contains("REMARK2")) { REMARK2 = keyValuePairs["REMARK2"].ToString(); } else { REMARK2 = ""; } //判断是否存在TIMEOUT if (keyValuePairs.Keys.Contains("TIMEOUT")) { TIMEOUT = keyValuePairs["TIMEOUT"].ToString(); } else { TIMEOUT = ""; } //判断是否存在RETURNTYPE if (keyValuePairs.Keys.Contains("RETURNTYPE")) { RETURNTYPE = keyValuePairs["RETURNTYPE"].ToString(); } else { RETURNTYPE = "3"; } //拼接加密字符串 string str = "MERCHANTID=" + keyValuePairs["MERCHANTID"].ToString() + "&POSID=" + keyValuePairs["POSID"].ToString() + "&BRANCHID=" + keyValuePairs["BRANCHID"] + "&ORDERID=" + keyValuePairs["ORDERID"] + "&PAYMENT=" + keyValuePairs["PAYMENT"] + "&CURCODE=" + keyValuePairs["CURCODE"].ToString() + "&TXCODE=" + keyValuePairs["TXCODE"] + "&REMARK1=" + REMARK1 + "&REMARK2=" + REMARK2 + "&RETURNTYPE=" + RETURNTYPE + "&TIMEOUT=" + TIMEOUT + "&PUB=" + pub + ""; var md5 = MD5.Create(); var bs = md5.ComputeHash(Encoding.UTF8.GetBytes(str)); var sb = new StringBuilder(); foreach (byte b in bs) { sb.Append(b.ToString("x2")); } //所有字符转为大写 return(sb.ToString().ToUpper()); } catch (Exception ex) { LogQueue.Write(LogType.Error, "ConstrunctionData/MACCheck", ex.Message.ToString()); throw new Exception(ex.Message.ToString()); } }