diff --git a/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/JSPayment/JsPaymentService.cs b/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/JSPayment/JsPaymentService.cs index 6dddcf6..c37b334 100644 --- a/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/JSPayment/JsPaymentService.cs +++ b/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/JSPayment/JsPaymentService.cs @@ -11,7 +11,12 @@ namespace EasyAbp.Abp.WeChat.Pay.Services.BasicPayment.JSPayment; public class JsPaymentService : WeChatPayServiceBase { public const string CreateOrderUrl = "https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi"; - public const string QueryOrderUrl = "https://api.mch.weixin.qq.com/v3/pay/transactions/id"; + + public const string QueryOrderByWechatNumberUrl = + "https://api.mch.weixin.qq.com/v3/pay/transactions/{transaction_id}"; + + public const string QueryOrderByOutTradeNumberUrl = + "https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/{out_trade_no}"; public JsPaymentService(AbpWeChatPayOptions options, IAbpLazyServiceProvider lazyServiceProvider) : base(options, @@ -24,8 +29,15 @@ public Task CreateOrderAsync(CreateOrderRequest request) return ApiRequester.RequestAsync(HttpMethod.Post, CreateOrderUrl, request); } - public Task QueryOrderAsync(QueryOrderRequest request) + public Task QueryOrderByWechatNumberAsync(QueryOrderByWechatNumberRequest request) + { + var requestUrl = QueryOrderByWechatNumberUrl.Replace("{transaction_id}", request.TransactionId); + return ApiRequester.RequestAsync(HttpMethod.Get, requestUrl, request); + } + + public Task QueryOrderByOutTradeNumberAsync(QueryOrderByOutTradeNumberRequest request) { - return Task.CompletedTask; + var requestUrl = QueryOrderByOutTradeNumberUrl.Replace("{out_trade_no}", request.OutTradeNo); + return ApiRequester.RequestAsync(HttpMethod.Get, requestUrl, request); } } \ No newline at end of file diff --git a/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/JSPayment/Models/QueryOrderByOutTradeNumberRequest.cs b/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/JSPayment/Models/QueryOrderByOutTradeNumberRequest.cs new file mode 100644 index 0000000..0ac8375 --- /dev/null +++ b/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/JSPayment/Models/QueryOrderByOutTradeNumberRequest.cs @@ -0,0 +1,31 @@ +using System.ComponentModel.DataAnnotations; +using Newtonsoft.Json; + +namespace EasyAbp.Abp.WeChat.Pay.Services.BasicPayment.JSPayment.Models; + +public class QueryOrderByOutTradeNumberRequest +{ + /// + /// 直连商户号。 + /// + /// + /// 直连商户的商户号,由微信支付生成并下发。 + /// + /// 示例值: 1230000109。 + [JsonProperty("mchid")] + [Required] + [StringLength(32, MinimumLength = 1)] + public string MchId { get; set; } + + /// + /// 商户订单号。 + /// + /// + /// 商户系统内部订单号,要求32个字符内,只能是数字、大小写字母_-|*@ ,且在同一个商户号下唯一。 + /// + /// 示例值: 1217752501201407033233368018。 + [JsonProperty("out_trade_no")] + [Required] + [StringLength(32, MinimumLength = 6)] + public string OutTradeNo { get; set; } +} \ No newline at end of file diff --git a/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/JSPayment/Models/QueryOrderRequest.cs b/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/JSPayment/Models/QueryOrderByWechatNumberRequest.cs similarity index 85% rename from src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/JSPayment/Models/QueryOrderRequest.cs rename to src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/JSPayment/Models/QueryOrderByWechatNumberRequest.cs index 5e3c560..144b55a 100644 --- a/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/JSPayment/Models/QueryOrderRequest.cs +++ b/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/JSPayment/Models/QueryOrderByWechatNumberRequest.cs @@ -1,8 +1,9 @@ using System.ComponentModel.DataAnnotations; +using Newtonsoft.Json; namespace EasyAbp.Abp.WeChat.Pay.Services.BasicPayment.JSPayment.Models; -public class QueryOrderRequest +public class QueryOrderByWechatNumberRequest { /// /// 直连商户号。 @@ -11,6 +12,7 @@ public class QueryOrderRequest /// 直连商户的商户号,由微信支付生成并下发。 /// /// 示例值: 1230000109。 + [JsonProperty("mchid")] [Required] [StringLength(32, MinimumLength = 1)] public string MchId { get; set; } @@ -22,6 +24,7 @@ public class QueryOrderRequest /// 微信支付系统生成的订单号。 /// /// 示例值: 1217752501201407033233368018。 + [JsonProperty("transaction_id")] [Required] [StringLength(32, MinimumLength = 1)] public string TransactionId { get; set; } diff --git a/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/Models/CreateOrderRequest.cs b/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/Models/CreateOrderRequest.cs index e7e2f19..1008cee 100644 --- a/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/Models/CreateOrderRequest.cs +++ b/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/Models/CreateOrderRequest.cs @@ -291,8 +291,6 @@ public class CreateOrderAmountModel public string Currency { get; set; } = "CNY"; } - - public class CreateOrderDetailModel { /// diff --git a/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/Models/QueryOrderResponse.cs b/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/Models/QueryOrderResponse.cs index c4205ef..ef64071 100644 --- a/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/Models/QueryOrderResponse.cs +++ b/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/Models/QueryOrderResponse.cs @@ -1,5 +1,455 @@ -namespace EasyAbp.Abp.WeChat.Pay.Services.BasicPayment.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using EasyAbp.Abp.WeChat.Pay.Services.ParametersModel; +using Newtonsoft.Json; -public class QueryOrderResponse +namespace EasyAbp.Abp.WeChat.Pay.Services.BasicPayment.Models; + +public class QueryOrderResponse : WeChatPayCommonErrorResponse { + /// + /// 应用 ID。 + /// + /// + /// 直连商户申请的公众号或移动应用 appid。 + /// + /// + /// 示例值: wxd678efh567hg6787。 + /// + [Required] + [StringLength(32, MinimumLength = 1)] + [JsonProperty("appid")] + public string AppId { get; set; } + + /// + /// 直连商户号。 + /// + /// + /// 直连商户的商户号,由微信支付生成并下发。 + /// + /// + /// 示例值: 1230000109。 + /// + [Required] + [StringLength(32, MinimumLength = 1)] + [JsonProperty("mchid")] + public string MchId { get; set; } + + /// + /// 商户订单号。 + /// + /// + /// 商户系统内部订单号,只能是数字、大小写字母_-*且在同一个商户号下唯一,详见【商户订单号】。 + /// + /// + /// 示例值: 1217752501201407033233368018。 + /// + [Required] + [StringLength(32, MinimumLength = 6)] + [JsonProperty("out_trade_no")] + public string OutTradeNo { get; set; } + + /// + /// 微信支付订单号。 + /// + /// + /// 微信支付系统生成的订单号。 + /// + /// + /// 示例值: 1217752501201407033233368018。 + /// + [StringLength(32)] + [JsonProperty("transaction_id")] + public string TransactionId { get; set; } + + /// + /// 交易类型。 + /// + /// + /// 交易类型为美剧值,具体值可参考 中找到对应的定义。 + /// + /// + /// 示例值: MICROPAY。()。 + /// + [StringLength(16)] + [JsonProperty("trade_type")] + public string TradeType { get; set; } + + /// + /// 交易状态。 + /// + /// + /// 交易状态为枚举值,具体值可以参考 中找到对应的定义。 + /// + /// + /// 示例值: SUCCESS()。 + /// + [Required] + [StringLength(32)] + [JsonProperty("trade_state")] + public string TradeState { get; set; } + + /// + /// 交易状态描述。 + /// + /// + /// 交易状态描述。 + /// + /// + /// 示例值: 支付成功。 + /// + [Required] + [StringLength(256)] + [JsonProperty("trade_state_desc")] + public string TradeStateDesc { get; set; } + + /// + /// 付款银行。 + /// + /// + /// 银行类型,采用字符串类型的银行标识。银行标识请参考 《银行类型对照表》。 + /// + /// + /// 示例值: CMC。 + /// + [StringLength(32)] + [JsonProperty("bank_type")] + public string BankType { get; set; } + + /// + /// 附加数据。 + /// + /// + /// 附加数据,在查询API和支付通知中原样返回,可作为自定义参数使用,实际情况下只有支付完成状态才会返回该字段。 + /// + /// + /// 示例值: 自定义数据。 + /// + [StringLength(128)] + [JsonProperty("attach")] + public string Attach { get; set; } + + /// + /// 支付完成时间。 + /// + /// + /// 遵循rfc3339标准格式,格式为YYYY-MM-DDTHH:mm:ss+TIMEZONE。
+ /// 开发人员只需要传递 DateTime 对象,底层的 Newtonsoft.Json 库会自动将其转换为符合微信支付要求的格式。 + ///
+ /// + /// 示例值: 2018-06-08T10:34:56+08:00。 + /// + [StringLength(64)] + [JsonProperty("success_time")] + public DateTime? SuccessTime { get; set; } + + /// + /// 支付者。 + /// + /// + /// 支付者信息。 + /// + [Required] + [JsonProperty("payer")] + public QueryOrderPayerModel Payer { get; set; } + + /// + /// 订单金额。 + /// + /// + /// 订单金额信息,当支付成功时返回该字段。 + /// + [JsonProperty("amount")] + public QueryOrderAmountModel Amount { get; set; } + + /// + /// 场景信息。 + /// + /// + /// 支付场景描述。 + /// + [JsonProperty("scene_info")] + public QueryOrderSceneInfoModel SceneInfo { get; set; } + + /// + /// 优惠功能。 + /// + /// + /// 优惠功能,享受优惠时返回该字段。 + /// + [JsonProperty("promotion_detail")] + public List PromotionDetails { get; set; } + + public class QueryOrderPayerModel + { + /// + /// 用户标识。 + /// + /// + /// 用户在直连商户 appid 下的唯一标识。 + /// + /// + /// 示例值: oUpF8uMuAJO_M2pxb1Q9zNjWeS6o。 + /// + [Required] + [StringLength(128, MinimumLength = 1)] + [JsonProperty("openid")] + public string OpenId { get; set; } + } + + public class QueryOrderAmountModel + { + /// + /// 总金额。 + /// + /// + /// 订单总金额,单位为分。 + /// + /// + /// 示例值: 100。 + /// + [JsonProperty("total")] + public int Total { get; set; } + + /// + /// 用户支付金额。 + /// + /// + /// 用户支付金额,单位为分。(指使用优惠券的情况下,这里等于总金额-优惠券金额) + /// + /// + /// 示例值: 100。 + /// + [JsonProperty("payer_total")] + public int PayerTotal { get; set; } + + /// + /// 货币类型。 + /// + /// + /// CNY: 人民币,境内商户号仅支持人民币。 + /// + /// + /// 示例值: CNY。 + /// + [StringLength(16)] + [JsonProperty("currency")] + public string Currency { get; set; } + + /// + /// 用户支付币种。 + /// + /// + /// 用户支付币种。 + /// + /// + /// 示例值: CNY。 + /// + [StringLength(16)] + [JsonProperty("payer_currency")] + public string PayerCurrency { get; set; } + } + + public class QueryOrderSceneInfoModel + { + /// + /// 商户端设备号。 + /// + /// + /// 商户端设备号 (发起扣款请求的商户服务器设备号)。 + /// + /// + /// 示例值: 013467007045764。 + /// + [StringLength(32)] + [JsonProperty("device_id")] + public string DeviceId { get; set; } + } +} + +public class QueryOrderPromotionDetailModel +{ + /// + /// 券 ID。 + /// + /// + /// 示例值: 109519。 + /// + [Required] + [StringLength(32)] + [JsonProperty("coupon_id")] + public string CouponId { get; set; } + + /// + /// 优惠名称。 + /// + /// + /// 示例值: 单品惠-6。 + /// + [StringLength(64)] + [JsonProperty("name")] + public string Name { get; set; } + + /// + /// 优惠范围。 + /// + /// + /// 枚举值,取值范围请参考 。 + /// + /// + /// 示例值: GLOBAL。() + /// + [StringLength(32)] + [JsonProperty("scope")] + public string Scope { get; set; } + + /// + /// 优惠类型。 + /// + /// + /// 枚举值,取值范围请参考 。 + /// + /// + /// 示例值: CASH。() + /// + [StringLength(32)] + [JsonProperty("type")] + public string Type { get; set; } + + /// + /// 优惠券面额。 + /// + /// + /// 示例值: 100。 + /// + [Required] + [JsonProperty("amount")] + public int Amount { get; set; } + + /// + /// 活动 ID。 + /// + /// + /// 示例值: 931386。 + /// + [StringLength(32)] + [JsonProperty("stock_id")] + public string StockId { get; set; } + + /// + /// 微信出资。 + /// + /// + /// 微信出资,单位为分。 + /// + /// + /// 示例值: 0 + /// + [JsonProperty("wechatpay_contribute")] + public int WechatpayContribute { get; set; } + + /// + /// 商户出资。 + /// + /// + /// 商户出资,单位为分。 + /// + /// + /// 示例值: 0 + /// + [JsonProperty("merchant_contribute")] + public int MerchantContribute { get; set; } + + /// + /// 其他出资。 + /// + /// + /// 其他出资,单位为分。 + /// + /// + /// 示例值: 0 + /// + [JsonProperty("other_contribute")] + public int OtherContribute { get; set; } + + /// + /// 优惠币种。 + /// + /// + /// CNY: 人民币,境内商户号仅支持人民币。 + /// + /// + /// 示例值: CNY + /// + [StringLength(16)] + [JsonProperty("currency")] + public string Currency { get; set; } + + /// + /// 单品列表。 + /// + /// + /// 单品列表信息。 + /// + [JsonProperty("goods_detail")] + public List GoodsDetails { get; set; } + + public class QueryOrderPromotionDetailGoodsDetail + { + /// + /// 商品编码。 + /// + /// + /// 示例值: M1006 + /// + [Required] + [StringLength(32)] + [JsonProperty("goods_id")] + public string GoodsId { get; set; } + + /// + /// 商品数量。 + /// + /// + /// 用户购买的数量。 + /// + /// + /// 示例值: 1 + /// + [Required] [JsonProperty("quantity")] public int Quantity { get; set; } + + /// + /// 商品单价。 + /// + /// + /// 商品单价,单位为分。 + /// + /// + /// 示例值: 100 + /// + [Required] + [JsonProperty("unit_price")] + public int UnitPrice { get; set; } + + /// + /// 商品优惠金额。 + /// + /// + /// 示例值: 0 + /// + [Required] + [JsonProperty("discount_amount")] + public int DiscountAmount { get; set; } + + /// + /// 商品备注。 + /// + /// + /// 示例值: 商品备注信息 + /// + [StringLength(128)] + [JsonProperty("goods_remark")] + public string GoodsRemark { get; set; } + } } \ No newline at end of file diff --git a/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/PromotionScopeEnum.cs b/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/PromotionScopeEnum.cs new file mode 100644 index 0000000..b469f9c --- /dev/null +++ b/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/PromotionScopeEnum.cs @@ -0,0 +1,17 @@ +namespace EasyAbp.Abp.WeChat.Pay.Services.BasicPayment; + +/// +/// 优惠范围的枚举值定义。 +/// +public static class PromotionScopeEnum +{ + /// + /// 全场代金券。 + /// + public const string Global = "GLOBAL"; + + /// + /// 单品优惠。 + /// + public const string Single = "SINGLE"; +} \ No newline at end of file diff --git a/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/PromotionTypeEnum.cs b/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/PromotionTypeEnum.cs new file mode 100644 index 0000000..0dac064 --- /dev/null +++ b/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/PromotionTypeEnum.cs @@ -0,0 +1,17 @@ +namespace EasyAbp.Abp.WeChat.Pay.Services.BasicPayment; + +/// +/// 优惠类型的枚举值定义。 +/// +public static class PromotionTypeEnum +{ + /// + /// 充值型代金券。 + /// + public const string Cash = "CASH"; + + /// + /// 免充值型代金券。 + /// + public const string NoCash = "NOCASH"; +} \ No newline at end of file diff --git a/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/TradeStateEnum.cs b/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/TradeStateEnum.cs new file mode 100644 index 0000000..e7a1d51 --- /dev/null +++ b/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/TradeStateEnum.cs @@ -0,0 +1,42 @@ +namespace EasyAbp.Abp.WeChat.Pay.Services.BasicPayment; + +/// +/// 交易状态的枚举值定义。 +/// +public static class TradeStateEnum +{ + /// + /// 支付成功。 + /// + public const string Success = "SUCCESS"; + + /// + /// 转入退款。 + /// + public const string Refund = "REFUND"; + + /// + /// 未支付。 + /// + public const string NotPay = "NOTPAY"; + + /// + /// 已关闭。 + /// + public const string Closed = "CLOSED"; + + /// + /// 已撤销 (仅付款码支付会返回)。 + /// + public const string Revoked = "REVOKED"; + + /// + /// 用户支付中 (仅付款码支付会返回)。 + /// + public const string UserPaying = "USERPAYING"; + + /// + /// 支付失败 (仅付款码支付会返回)。 + /// + public const string PayError = "PAYERROR"; +} \ No newline at end of file diff --git a/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/TradeTypeEnum.cs b/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/TradeTypeEnum.cs new file mode 100644 index 0000000..353246c --- /dev/null +++ b/src/Pay/EasyAbp.Abp.WeChat.Pay/Services/BasicPayment/TradeTypeEnum.cs @@ -0,0 +1,37 @@ +namespace EasyAbp.Abp.WeChat.Pay.Services.BasicPayment; + +/// +/// 交易类型的枚举值定义。 +/// +public static class TradeTypeEnum +{ + /// + /// 公众号支付。 + /// + public const string JsApi = "JSAPI"; + + /// + /// 扫码支付。 + /// + public const string Native = "NATIVE"; + + /// + /// APP 支付。 + /// + public const string App = "APP"; + + /// + /// 付款码支付。 + /// + public const string MicroPay = "MICROPAY"; + + /// + /// H5 支付。 + /// + public const string MWeb = "MWEB"; + + /// + /// 刷脸支付。 + /// + public const string FacePay = "FACEPAY"; +} \ No newline at end of file