using System; using System.Collections.Generic; using System.Linq; using System.Text; using BWP.ABCClient.Businesses; using System.Security.Cryptography; using System.Net; using System.IO; using System.Security; using System.Security.Cryptography.X509Certificates; namespace BWP.ABCClient.B2C.OnlineRemits { /// /// 网付通,在线付款 /// public class OnlineRemitRequest:OnlineRemitBaseRequest { /// /// 总笔数 /// public int TotalCount { get; set; } /// /// 总金额 /// public double TotalAmount { get; set; } /// /// 序号 /// public string SerialNumber { get; set; } /// /// 备注 /// public string Remark { get; set; } /// /// 0:无需操作员确认直接付款;1:需要操作员在商户服务系统确认后付款 /// public int CheckType { get; set; } List mDetails = new List(); public List Details { get { return mDetails; } } public OnlineRemitResponse GetResponse() { var message = base.Send(); OnlineRemitResponse response = new OnlineRemitResponse(message); return response; } protected override XmlDocument createMessage() { StringBuilder builder = new StringBuilder("").Append("").Append("").Append("OnlineRemit").Append("") .Append("").Append(CheckType).Append("") .Append("").Append(SerialNumber).Append("") .Append("").Append(TotalCount).Append("") .Append("").Append(TotalAmount).Append("") .Append("").Append(Remark).Append(""); builder.Append(""); foreach (var detail in this.Details) { builder.Append("") .Append("").Append(detail.NO).Append("") .Append("").Append(detail.CardNo).Append("") .Append("").Append(detail.CardName).Append("") .Append("").Append(detail.Amount).Append("") .Append("").Append(detail.Purpose).Append("") .Append(""); } builder.Append("").Append(""); return new XmlDocument(builder.ToString()); } public static bool isValidAmount(double aAmount, int aExp) { bool flag = false; if (aExp >= 0) { string str = aAmount.ToString(); int index = str.IndexOf('.'); if (index == -1) { return true; } if (index >= ((str.Length - aExp) - 1)) { flag = true; } } return flag; } protected override void checkRequest() { if (TotalCount != Details.Count) { throw new OnlineRemitException("1101", "商户提交的交易资料不合法", "付款总笔数与明细笔数不一致!"); } if (SerialNumber.Trim().Equals("")) { throw new OnlineRemitException("1101", "商户提交的交易资料不合法", "付款流水号不能为空!"); } if (TotalCount <= 0) { throw new OnlineRemitException("1101", "商户提交的交易资料不合法", "付款交易总笔数不能小于1笔"); } if (TotalCount > 100) { throw new OnlineRemitException("1101", "商户提交的交易资料不合法", "付款交易总笔数不能大于100笔"); } if (TotalAmount <= 0.0) { throw new OnlineRemitException("1101", "商户提交的交易资料不合法", "付款交易总金额不合法!"); } if (!(isValidAmount(TotalAmount, 2) && (TotalAmount > 0.0))) { throw new OnlineRemitException("1101", "商户提交的交易资料不合法", "付款交易总金额不合法!"); } var noDic = new Dictionary(); foreach (var detail in this.Details) { if (noDic.ContainsKey(detail.NO)) { throw new OnlineRemitException("1101", "商户提交的交易资料不合法", "批次内序号重复"); } else { noDic.Add(detail.NO, detail.NO); } if (detail.NO < 0 || detail.NO > 99999) { throw new OnlineRemitException("1101", "商户提交的交易资料不合法", "批次内序号需要在1至5位之间:" + detail.NO); } if (string.IsNullOrEmpty(detail.CardNo)) { throw new OnlineRemitException("1101", "商户提交的交易资料不合法", "付款明细卡号不能为空!"); } if (string.IsNullOrEmpty(detail.CardName)) { throw new OnlineRemitException("1101", "商户提交的交易资料不合法", "付款明细收款人信息不能为空!"); } if (!(isValidAmount(detail.Amount, 2) && (detail.Amount > 0.0))) { throw new OnlineRemitException("1101", "商户提交的交易资料不合法", "付款交易明细金额不合法:" + detail.Amount.ToString()); } if (detail.Purpose.Length > 30) { throw new OnlineRemitException("1101", "商户提交的交易资料不合法", "明细内容不能超过30个字:" + detail.Purpose); } } } } }