From 00aa1cdc930aee96c1b5b93100cfcb925bbcb3ee Mon Sep 17 00:00:00 2001 From: varorbc Date: Thu, 19 Apr 2018 20:59:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=80=80=E6=AC=BE=E9=80=9A?= =?UTF-8?q?=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ICanPay.Alipay/Merchant.cs | 7 - src/ICanPay.Alipay/Notify.cs | 14 +- .../ServiceCollectionExtensions.cs | 5 +- src/ICanPay.Core/Utils/EncryptUtil.cs | 26 +++ src/ICanPay.Wechatpay/Notify.cs | 191 +++++++----------- .../Request/RefundRequest.cs | 1 - src/ICanPay.Wechatpay/WechatpayGateway.cs | 13 +- 7 files changed, 127 insertions(+), 130 deletions(-) diff --git a/src/ICanPay.Alipay/Merchant.cs b/src/ICanPay.Alipay/Merchant.cs index f9e81b7..fbf5e9f 100644 --- a/src/ICanPay.Alipay/Merchant.cs +++ b/src/ICanPay.Alipay/Merchant.cs @@ -39,13 +39,6 @@ namespace ICanPay.Alipay /// public string Charset => "UTF-8"; - /// - /// 应用授权 - /// //TODO:有些不添加 - /// - [StringLength(40, ErrorMessage = "应用授权最大长度为40位")] - public string AppAuthToken { get; set; } - /// /// 参数集合 /// diff --git a/src/ICanPay.Alipay/Notify.cs b/src/ICanPay.Alipay/Notify.cs index 25b3761..62e9c57 100644 --- a/src/ICanPay.Alipay/Notify.cs +++ b/src/ICanPay.Alipay/Notify.cs @@ -45,6 +45,11 @@ namespace ICanPay.Alipay /// public string Sign { get; set; } + /// + /// 授权方的app_id + /// + public string AuthAppId { get; set; } + /// /// 支付宝交易号 /// @@ -113,7 +118,14 @@ namespace ICanPay.Alipay /// /// 总退款金额 /// - public double RefundFee { get; set; } + [ReName(Name = "refund_fee")] + public double RefundAmount { get; set; } + + /// + /// 实际退款金额 + /// + [ReName(Name = "send_back_fee")] + public double SendBackAmount { get; set; } /// /// 订单标题 diff --git a/src/ICanPay.Core/ServiceCollectionExtensions.cs b/src/ICanPay.Core/ServiceCollectionExtensions.cs index 9884774..ea2f785 100644 --- a/src/ICanPay.Core/ServiceCollectionExtensions.cs +++ b/src/ICanPay.Core/ServiceCollectionExtensions.cs @@ -20,7 +20,10 @@ namespace Microsoft.Extensions.DependencyInjection var gateways = new Gateways(); setupAction(gateways); - services.AddSingleton(gateways); + services.AddScoped(a => + { + return gateways; + }); } /// diff --git a/src/ICanPay.Core/Utils/EncryptUtil.cs b/src/ICanPay.Core/Utils/EncryptUtil.cs index b728fd6..56514fb 100644 --- a/src/ICanPay.Core/Utils/EncryptUtil.cs +++ b/src/ICanPay.Core/Utils/EncryptUtil.cs @@ -525,5 +525,31 @@ namespace ICanPay.Core.Utils } #endregion + + #region AES解密 + + /// + /// AES解密 + /// + /// 待解密数据 + /// 密钥 + /// + public static string AESDecrypt(string data, string key) + { + var keyArray = Encoding.UTF8.GetBytes(key); + var toEncryptArray = Convert.FromBase64String(data); + var rDel = new RijndaelManaged + { + Key = keyArray, + Mode = CipherMode.ECB, + Padding = PaddingMode.PKCS7 + }; + + var cTransform = rDel.CreateDecryptor(); + var resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length); + return Encoding.UTF8.GetString(resultArray); + } + + #endregion } } diff --git a/src/ICanPay.Wechatpay/Notify.cs b/src/ICanPay.Wechatpay/Notify.cs index b1bf029..fbf88f9 100644 --- a/src/ICanPay.Wechatpay/Notify.cs +++ b/src/ICanPay.Wechatpay/Notify.cs @@ -1,9 +1,22 @@ using ICanPay.Core; +using System; +using System.Collections.Generic; +using static ICanPay.Wechatpay.Response.QueryResponse; namespace ICanPay.Wechatpay { public class Notify : INotify { + /// + /// 返回状态码 + /// + public string ReturnCode { get; set; } + + /// + /// 返回信息 + /// + public string ReturnMsg { get; set; } + /// /// 应用ID /// @@ -25,11 +38,21 @@ namespace ICanPay.Wechatpay /// public string NonceStr { get; set; } + /// + /// 加密信息 + /// + public string ReqInfo { get; set; } + /// /// 签名 /// public string Sign { get; set; } + /// + /// 签名类型 + /// + public string SignType { get; set; } + /// /// 业务结果 /// @@ -45,38 +68,6 @@ namespace ICanPay.Wechatpay /// public string ErrCodeDes { get; set; } - /// - /// 交易类型 - /// - public string TradeType { get; set; } - - /// - /// 微信生成的预支付回话标识,用于后续接口调用中使用,该值有效期为2小时 - /// - public string PrepayId { get; set; } - - /// - /// 返回状态码 - /// - public string ReturnCode { get; set; } - - /// - /// 返回信息 - /// - public string ReturnMsg { get; set; } - - /// - /// 支付跳转链接 - /// mweb_url为拉起微信支付收银台的中间页面,可通过访问该url来拉起微信客户端,完成支付,mweb_url的有效期为5分钟。 - /// - public string MWebUrl { get; set; } - - /// - /// 二维码链接 - /// trade_type为NATIVE时有返回,用于生成二维码,展示给用户进行扫码支付 - /// - public string CodeUrl { get; set; } - /// /// 用户标识 /// 用户在商户appid 下的唯一标识 @@ -90,22 +81,57 @@ namespace ICanPay.Wechatpay /// public string IsSubscribe { get; set; } + /// + /// 交易类型 + /// + public string TradeType { get; set; } + /// /// 银行类型,采用字符串类型的银行标识,详见银行类型 /// public string BankType { get; set; } + /// + /// 订单金额 + /// 订单总金额,单位为分 + /// + [ReName(Name = "total_fee")] + public double TotalAmount { get; set; } + /// /// 应结订单金额 /// 当订单使用了免充值型优惠券后返回该参数,应结订单金额=订单金额-免充值优惠券金额。 /// - public double SettlementTotalFee { get; set; } + [ReName(Name = "settlement_total_fee")] + public double SettlementTotalAmount { get; set; } + + /// + /// 货币类型 + /// 符合ISO 4217标准的三位字母代码,默认人民币:CNY,详见货币类型 + /// + [ReName(Name = "fee_type")] + public string AmountType { get; set; } + + /// + /// 现金支付金额 + /// 订单现金支付金额,详见支付金额 + /// + [ReName(Name = "cash_fee")] + public double CashAmount { get; set; } + + /// + /// 现金支付货币类型 + /// 符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型 + /// + [ReName(Name = "cash_fee_type")] + public string CashAmountType { get; set; } /// /// 代金券金额 /// “代金券”金额小于等于订单金额,订单金额-“代金券”金额=现金支付金额,详见支付金额 /// - public double CouponFee { get; set; } + [ReName(Name = "coupon_fee")] + public double CouponAmount { get; set; } /// /// 代金券使用数量 @@ -113,38 +139,16 @@ namespace ICanPay.Wechatpay public int CouponCount { get; set; } /// - /// 货币类型 - /// 符合ISO 4217标准的三位字母代码,默认人民币:CNY,详见货币类型 + /// 退款代金券 + /// TODO:特殊代金券 /// - public string FeeType { get; set; } - - /// - /// 订单金额 - /// 订单总金额,单位为元 - /// - public double TotalFee - { - get => _totalFee; - set => _totalFee = value / 100; - } - private double _totalFee; - - /// - /// 现金支付货币类型 - /// 符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型 - /// - public string CashFeeType { get; set; } - - /// - /// 现金支付金额 - /// 订单现金支付金额,详见支付金额 - /// - public double CashFee { get; set; } + public List Coupons { get; set; } /// /// 微信支付订单号 /// - public string TransactionId { get; set; } + [ReName(Name = "transaction_id")] + public string TradeNo { get; set; } /// /// 商户订单号 @@ -162,76 +166,27 @@ namespace ICanPay.Wechatpay public string TimeEnd { get; set; } /// - /// 营销详情 - /// 新增返回,单品优惠功能字段,需要接入请见详细说明 - /// - public string PromotionDetail { get; set; } - - /// - /// 交易状态描述 - /// 对当前查询订单状态的描述和下一步操作的指引 - /// - public string TradeStateDesc { get; set; } - - /// - /// 交易状态 - /// SUCCESS—支付成功 - /// REFUND—转入退款 - /// NOTPAY—未支付 - /// CLOSED—已关闭 - /// REVOKED—已撤销(刷卡支付) - /// USERPAYING--用户支付中 - /// PAYERROR--支付失败(其他原因,如银行返回失败) - /// 支付状态机请见下单API页面 - /// - public string TradeState { get; set; } - - /// - /// 是否重调 - /// 是否需要继续调用撤销,Y-需要,N-不需要 - /// - public string Recall { get; set; } - - /// - /// 是否重调 - /// 是否需要继续调用撤销,Y-需要,N-不需要 + /// 商户退款单号 /// public string OutRefundNo { get; set; } /// /// 微信退款单号 /// - public string RefundId { get; set; } + [ReName(Name = "refund_id")] + public string RefundNo { get; set; } /// /// 退款金额 /// - public string RefundFee { get; set; } + [ReName(Name = "refund_fee")] + public string RefundAmount { get; set; } /// /// 应结退款金额 /// - public string SettlementRefundFee { get; set; } - - /// - /// 现金退款金额 - /// - public string CashRefundFee { get; set; } - - /// - /// 代金券退款总金额 - /// - public string CouponRefundFee { get; set; } - - /// - /// 订单总退款次数 - /// - public string TotalRefundCount { get; set; } - - /// - /// 退款笔数 - /// - public string RefundCount { get; set; } + [ReName(Name = "settlement_refund_fee")] + public string SettlementRefundAmount { get; set; } /// /// 退款状态 @@ -241,7 +196,7 @@ namespace ICanPay.Wechatpay /// /// 退款成功时间 /// - public string SuccessTime { get; set; } + public DateTime SuccessTime { get; set; } /// /// 退款入账账户 diff --git a/src/ICanPay.Wechatpay/Request/RefundRequest.cs b/src/ICanPay.Wechatpay/Request/RefundRequest.cs index 60d385a..b0f420b 100644 --- a/src/ICanPay.Wechatpay/Request/RefundRequest.cs +++ b/src/ICanPay.Wechatpay/Request/RefundRequest.cs @@ -13,7 +13,6 @@ namespace ICanPay.Wechatpay.Request internal override void Execute(Merchant merchant) { - GatewayData.Remove("notify_url"); } } } diff --git a/src/ICanPay.Wechatpay/WechatpayGateway.cs b/src/ICanPay.Wechatpay/WechatpayGateway.cs index 5f7b4d8..ebe692c 100644 --- a/src/ICanPay.Wechatpay/WechatpayGateway.cs +++ b/src/ICanPay.Wechatpay/WechatpayGateway.cs @@ -59,9 +59,18 @@ namespace ICanPay.Wechatpay throw new GatewayException("不是成功的返回码"); } - if (Notify.Sign != SubmitProcess.BuildSign(GatewayData, _merchant.Key)) + if (string.IsNullOrEmpty(Notify.ReqInfo)) { - throw new GatewayException("签名不一致"); + if (Notify.Sign != SubmitProcess.BuildSign(GatewayData, _merchant.Key)) + { + throw new GatewayException("签名不一致"); + } + } + else + { + //TODO:解密 + var key = EncryptUtil.MD5(_merchant.Key).ToLower(); + var data = EncryptUtil.AESDecrypt(Notify.ReqInfo, key); } return true;