You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

169 lines
5.2 KiB

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
{
/// <summary>
/// 网付通,在线付款
/// </summary>
public class OnlineRemitRequest:OnlineRemitBaseRequest
{
/// <summary>
/// 总笔数
/// </summary>
public int TotalCount { get; set; }
/// <summary>
/// 总金额
/// </summary>
public double TotalAmount { get; set; }
/// <summary>
/// 序号
/// </summary>
public string SerialNumber { get; set; }
/// <summary>
/// 备注
/// </summary>
public string Remark { get; set; }
/// <summary>
/// 0:无需操作员确认直接付款;1:需要操作员在商户服务系统确认后付款
/// </summary>
public int CheckType { get; set; }
List<OnlineRemitRequest_Detail> mDetails = new List<OnlineRemitRequest_Detail>();
public List<OnlineRemitRequest_Detail> 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("<TrxRequest>").Append("<TrxType>").Append("OnlineRemit").Append("</TrxType>")
.Append("<CheckType>").Append(CheckType).Append("</CheckType>")
.Append("<SerialNumber>").Append(SerialNumber).Append("</SerialNumber>")
.Append("<TotalCount>").Append(TotalCount).Append("</TotalCount>")
.Append("<TotalAmount>").Append(TotalAmount).Append("</TotalAmount>")
.Append("<Remark>").Append(Remark).Append("</Remark>");
builder.Append("<RemitData>");
foreach (var detail in this.Details)
{
builder.Append("<RemitDetail>")
.Append("<NO>").Append(detail.NO).Append("</NO>")
.Append("<CardNo>").Append(detail.CardNo).Append("</CardNo>")
.Append("<CardName>").Append(detail.CardName).Append("</CardName>")
.Append("<RemitAmount>").Append(detail.Amount).Append("</RemitAmount>")
.Append("<Purpose>").Append(detail.Purpose).Append("</Purpose>")
.Append("</RemitDetail>");
}
builder.Append("</RemitData>").Append("</TrxRequest>");
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<int, int>();
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);
}
}
}
}
}