From 4cad69d6c12c679eaffe22fc19e042d7cf66fd9b Mon Sep 17 00:00:00 2001 From: varorbc Date: Mon, 30 Apr 2018 10:36:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9F=A5=E8=AF=A2=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PaySharp.Unionpay/Domain/QueryModel.cs | 46 ++++++++ src/PaySharp.Unionpay/Request/QueryRequest.cs | 34 ++++++ .../Response/QueryResponse.cs | 108 ++++++++++++++++++ src/PaySharp.Unionpay/SubmitProcess.cs | 2 +- 4 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 src/PaySharp.Unionpay/Domain/QueryModel.cs create mode 100644 src/PaySharp.Unionpay/Request/QueryRequest.cs create mode 100644 src/PaySharp.Unionpay/Response/QueryResponse.cs diff --git a/src/PaySharp.Unionpay/Domain/QueryModel.cs b/src/PaySharp.Unionpay/Domain/QueryModel.cs new file mode 100644 index 0000000..2455e9c --- /dev/null +++ b/src/PaySharp.Unionpay/Domain/QueryModel.cs @@ -0,0 +1,46 @@ +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; + +namespace PaySharp.Unionpay.Domain +{ + public class QueryModel : BaseModel, IValidatableObject + { + public QueryModel() + { + BizType = "000000"; + TxnType = "00"; + } + + /// + /// 查询流水号 + /// + public string QueryId { get; set; } + + /// + /// 商户订单号,不应含“-”或“_” + /// + [StringLength(40, MinimumLength = 8, ErrorMessage = "商户订单号最小长度为8位,最大长度为40位")] + public string OrderId { get; set; } + + /// + /// 保留域 + /// + [StringLength(2048, ErrorMessage = "保留域最大长度为2048位")] + public string Reserved { get; set; } + + /// + /// 控制规则 + /// + public string CtrlRule { get; set; } + + public IEnumerable Validate(ValidationContext validationContext) + { + if (string.IsNullOrEmpty(OrderId) && string.IsNullOrEmpty(QueryId)) + { + yield return new ValidationResult("商户订单号和查询流水号不能同时为空"); + } + + yield return ValidationResult.Success; + } + } +} diff --git a/src/PaySharp.Unionpay/Request/QueryRequest.cs b/src/PaySharp.Unionpay/Request/QueryRequest.cs new file mode 100644 index 0000000..8f3c286 --- /dev/null +++ b/src/PaySharp.Unionpay/Request/QueryRequest.cs @@ -0,0 +1,34 @@ +using PaySharp.Unionpay.Domain; +using PaySharp.Unionpay.Response; + +namespace PaySharp.Unionpay.Request +{ + public class QueryRequest : BaseRequest + { + public QueryRequest() + { + RequestUrl = "/gateway/api/queryTrans.do"; + } + + public override void AddGatewayData(QueryModel model) + { + if (!string.IsNullOrEmpty(model.OrderId)) + { + model.TxnSubType = "00"; + } + + if (!string.IsNullOrEmpty(model.QueryId)) + { + model.TxnSubType = "02"; + } + + base.AddGatewayData(model); + } + + internal override void Execute(Merchant merchant) + { + GatewayData.Remove("backUrl"); + GatewayData.Remove("frontUrl"); + } + } +} diff --git a/src/PaySharp.Unionpay/Response/QueryResponse.cs b/src/PaySharp.Unionpay/Response/QueryResponse.cs new file mode 100644 index 0000000..2767039 --- /dev/null +++ b/src/PaySharp.Unionpay/Response/QueryResponse.cs @@ -0,0 +1,108 @@ +using PaySharp.Core; +using PaySharp.Core.Request; + +namespace PaySharp.Unionpay.Response +{ + public class QueryResponse : BaseResponse + { + /// + /// 查询交易为退货或者消费撤销时返回,表示原消费交易的商户订单号 + /// + public string OrigOrderId { get; set; } + + /// + /// 查询交易为退货或者消费撤销时返回,表示原消费交易的商户发送交易时间 + /// + public string OrigTxnTime { get; set; } + + /// + /// 查询流水号 + /// + public string QueryId { get; set; } + + /// + /// 清算日期 (月月日日) + /// + public string SettleDate { get; set; } + + /// + /// 清算币种 + /// + public string SettleCurrencyCode { get; set; } + + /// + /// 清算金额 + /// + [ReName(Name = "settleAmt")] + public string SettleAmount { get; set; } + + /// + /// 兑换日期 + /// + public string ExchangeDate { get; set; } + + /// + /// 交易币种 + /// + public string CurrencyCode { get; set; } + + /// + /// 交易金额 + /// + [ReName(Name = "txnAmt")] + public int TotalAmount { get; set; } + + /// + /// 清算汇率 + /// + public string ExchangeRate { get; set; } + + /// + /// 支付方式 + /// 默认不返回此域,如需要返此域,需要提交申请,视商户配置返回,可在消费类交易中返回以下中的一种: + /// 0001:认证支付 + /// 0002:快捷支付 + /// 0004:储值卡支付 + /// 0005:IC卡支付 + /// 0201:网银支付 + /// 1001:牡丹畅通卡支付 + /// 1002:中铁银通卡支付 + /// 0401:信用卡支付——暂定 + /// 0402:小额临时支付 + /// 0403:认证支付 2.0 + /// 0404:互联网订单手机支付 + /// 9000:其他无卡支付(如手机客户端支付) + /// + public string PayType { get; set; } + + /// + /// 交易账号。请求时使用加密公钥对交易账号加密,并做 Base64 编码后上送; + /// 应答时如需返回,则使用签名私钥 进行解密。 + /// 前台交易可由银联页面采集,也可由商户上送并返显。 + /// 如需锁定返显卡号,应通过保留域(reserved)上送卡 号锁定标识。 + /// + public string AccNo { get; set; } + + /// + /// 支付卡类型 + /// 消费交易,视商户配置返回。该域取值为: + /// 00:未知 + /// 01:借记账户 + /// 02:贷记账户 + /// 03:准贷记账户 + /// 04:借贷合一账户 + /// 05:预付费账户 + /// 06:半开放预付费账户 + /// + public string PayCardType { get; set; } + + /// + /// 支付卡名称 + /// + public string PayCardIssueName { get; set; } + + internal override void Execute(Merchant merchant, Request request) + { + } + } +} diff --git a/src/PaySharp.Unionpay/SubmitProcess.cs b/src/PaySharp.Unionpay/SubmitProcess.cs index 90bd528..a0a7f41 100644 --- a/src/PaySharp.Unionpay/SubmitProcess.cs +++ b/src/PaySharp.Unionpay/SubmitProcess.cs @@ -28,7 +28,7 @@ namespace PaySharp.Unionpay .GetAwaiter() .GetResult(); - var gatewayData = new GatewayData(); + var gatewayData = new GatewayData(StringComparer.Ordinal); gatewayData.FromUrl(result, false); var baseResponse = (BaseResponse)(object)gatewayData.ToObject(StringCase.Camel);