Skip to content

Commit

Permalink
Merge pull request #107 from EasyAbp/wechatpay-v3-jspayment
Browse files Browse the repository at this point in the history
Preparing to push a new preview version.
  • Loading branch information
real-zony committed Jan 15, 2024
2 parents 9679db8 + d0c5db3 commit 6b03c89
Show file tree
Hide file tree
Showing 19 changed files with 126 additions and 31 deletions.
2 changes: 1 addition & 1 deletion common.props
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<Version>3.0.0-preview.9</Version>
<Version>3.0.0-preview.10</Version>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>EasyAbp Team</Authors>
Expand Down
75 changes: 75 additions & 0 deletions docs/WeChatPay.md
@@ -1,3 +1,78 @@
## 零、支持情况

### 0.0 如何直接调用微信支付 V3 的接口?

由于精力有限,在项目初期没有完成所有微信支付 V3 接口的封装,这个时候你可以自己继承 `WeChatPayServiceBase` 基类,并直接使用基类提供的 `ApiRequester` 属性发起微信支付 V3 接口的请求。

所有的证书管理和签名验证都已经实现,你只需要自己编写对应的请求体对象和响应对象的类型定义。

你可以参考以下代码:

```csharp
using System.Net.Http;
using System.Threading.Tasks;
using EasyAbp.Abp.WeChat.Pay.Options;
using EasyAbp.Abp.WeChat.Pay.Services.MarketingTools.VoucherService.ParametersModel;
using Volo.Abp.DependencyInjection;

namespace EasyAbp.Abp.WeChat.Pay.Services.MarketingTools.VoucherService;

/// <summary>
/// 代金券服务。
/// </summary>
public class VoucherWeService : WeChatPayServiceBase
{
public const string CreateCouponBatchUrl = "https://api.mch.weixin.qq.com/v3/marketing/favor/coupon-stocks";

public VoucherWeService(AbpWeChatPayOptions options,
IAbpLazyServiceProvider lazyServiceProvider) : base(options,
lazyServiceProvider)
{
}

public Task<CreateCouponBatchResponse> CreateCouponBatchAsync(CreateCouponBatchRequest request)
{
return ApiRequester.RequestAsync<CreateCouponBatchResponse>(HttpMethod.Post, CreateCouponBatchUrl, request, MchId);
}
}
```

### 0.1 基础支付

| 服务 | 支持情况 | 备注 |
| ----------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| JSAPI 支付 | ![Support](https://img.shields.io/badge/-支持-bright_green.svg) | |
| APP 支付 | ![Support](https://img.shields.io/badge/-支持-bright_green.svg) | |
| H5 支付 | ![Support](https://img.shields.io/badge/-支持-bright_green.svg) | |
| Native 支付 | ![Support](https://img.shields.io/badge/-支持-bright_green.svg) | |
| 小程序支付 | ![Support](https://img.shields.io/badge/-支持-bright_green.svg) | |
| 合单支付 | ![Support](https://img.shields.io/badge/-未实现-red.svg) | |
| 付款码支付 | ![Support](https://img.shields.io/badge/-未实现-red.svg) | 付款码支付仍然使用的是 微信支付 V2 版本的 API。<br />目前不考虑再支持此支付方式,请考虑使用 Native 支付替代。 |

### 0.2 经营能力

TODO

### 0.3 行业方案

TODO

### 0.4 营销工具

TODO

### 0.5 资金应用

TODO

### 0.6 风险合规

TODO

### 0.7 其他能力

TODO

## 一、基本模块配置

### 1.1 模块的引用
Expand Down
Expand Up @@ -2,6 +2,6 @@

namespace EasyAbp.Abp.WeChat.Pay;

public class AbpWeChatPayAbstractionsModule : AbpModule
public class AbpWeChatPayAbstractionsModule : AbpModule
{
}
Expand Up @@ -7,12 +7,9 @@ namespace EasyAbp.Abp.WeChat.Pay.RequestHandling.Dtos;
[Serializable]
public class GetJsSdkWeChatPayParametersInput
{
[CanBeNull]
public string MchId { get; set; }
[CanBeNull] public string MchId { get; set; }

[Required]
public string AppId { get; set; }
[Required] public string AppId { get; set; }

[Required]
public string PrepayId { get; set; }
[Required] public string PrepayId { get; set; }
}
4 changes: 1 addition & 3 deletions src/Pay/EasyAbp.Abp.WeChat.Pay/AbpWeChatPayModule.cs
@@ -1,16 +1,14 @@
using EasyAbp.Abp.WeChat.Common;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.BlobStoring;
using Volo.Abp.Json.Newtonsoft;
using Volo.Abp.Modularity;

namespace EasyAbp.Abp.WeChat.Pay
{
[DependsOn(
typeof(AbpWeChatCommonModule),
typeof(AbpBlobStoringModule),
typeof(AbpWeChatPayAbstractionsModule),
typeof(AbpJsonNewtonsoftModule)
typeof(AbpWeChatPayAbstractionsModule)
)]
public class AbpWeChatPayModule : AbpModule
{
Expand Down
Expand Up @@ -12,7 +12,7 @@ public interface IWeChatPayApiRequester
Task<string> RequestAsync(HttpMethod method, string url, [CanBeNull] string body = null, [CanBeNull] string mchId = null);

Task<TResponse> RequestAsync<TResponse>(HttpMethod method, string url, [CanBeNull] string body = null, [CanBeNull] string mchId = null);

Task<HttpResponseMessage> RequestRawAsync(HttpMethod method, string url, [CanBeNull] string body = null, [CanBeNull] string mchId = null);

Task<string> RequestAsync(HttpMethod method, string url, [NotNull] object body, [CanBeNull] string mchId = null);
Expand Down
Expand Up @@ -27,9 +27,9 @@ public class WeChatPayApiRequestModel
RandomString = randomString;
Url = url;
Body = body;

if (method != HttpMethod.Get) return;

Body = null;
if (!string.IsNullOrEmpty(body))
{
Expand Down
Expand Up @@ -17,7 +17,6 @@
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
<PackageReference Include="Volo.Abp.BlobStoring" Version="$(AbpVersion)" />
<PackageReference Include="Volo.Abp.BackgroundWorkers" Version="$(AbpVersion)" />
<PackageReference Include="Volo.Abp.Json.Newtonsoft" Version="8.0.1" />
</ItemGroup>

</Project>
Expand Up @@ -54,7 +54,7 @@ public virtual async Task<PlatformCertificateEntity> GetPlatformCertificateAsync
certificate.EncryptCertificateData.Nonce,
certificate.EncryptCertificateData.Ciphertext);

_certificatesCache.TryAdd(certificate.SerialNo,new Lazy<PlatformCertificateEntity>(() =>
_certificatesCache.TryAdd(certificate.SerialNo, new Lazy<PlatformCertificateEntity>(() =>
new PlatformCertificateEntity(certificate.SerialNo, certificateString,
certificate.EffectiveTime, certificate.ExpireTime)));
}
Expand Down
Expand Up @@ -9,7 +9,7 @@ public static class PromotionTypeEnum
/// 代金券,需要走结算资金的充值型代金券。
/// </summary>
public const string Coupon = "COUPON";

/// <summary>
/// 优惠券,不走结算资金的免充值型优惠券。
/// </summary>
Expand Down
Expand Up @@ -9,17 +9,17 @@ public static class RefundChannelEnum
/// 原路退款。
/// </summary>
public const string Original = "ORIGINAL";

/// <summary>
/// 退回到余额。
/// </summary>
public const string Balance = "BALANCE";

/// <summary>
/// 原账户异常退到其他余额账户。
/// </summary>
public const string OtherBalance = "OTHER_BALANCE";

/// <summary>
/// 原银行卡异常退到其他银行卡。
/// </summary>
Expand Down
Expand Up @@ -9,7 +9,7 @@ public static class RefundFundsAccountEnum
/// 可用余额账户。
/// </summary>
public const string Available = "AVAILABLE";

/// <summary>
/// 不可用余额账户。
/// </summary>
Expand All @@ -24,9 +24,9 @@ public static class RefundFundsAccountEnum
/// 运营账户。
/// </summary>
public const string Operation = "OPERATION";

/// <summary>
/// 基本账户。
/// </summary>
public const string Basic= "BASIC";
public const string Basic = "BASIC";
}
Expand Up @@ -9,17 +9,17 @@ public static class RefundStatusEnum
/// 退款成功。
/// </summary>
public const string Success = "SUCCESS";

/// <summary>
/// 退款关闭。
/// </summary>
public const string Closed = "CLOSED";

/// <summary>
/// 退款处理中。
/// </summary>
public const string Processing = "PROCESSING";

/// <summary>
/// 退款异常。
/// </summary>
Expand Down
Expand Up @@ -9,7 +9,7 @@ public static class TradeStateEnum
/// 支付成功。
/// </summary>
public const string Success = "SUCCESS";

/// <summary>
/// 转入退款。
/// </summary>
Expand All @@ -19,7 +19,7 @@ public static class TradeStateEnum
/// 未支付。
/// </summary>
public const string NotPay = "NOTPAY";

/// <summary>
/// 已关闭。
/// </summary>
Expand Down
Expand Up @@ -13,7 +13,7 @@ public class CreateOrderRequest : BasicPayment.Models.CreateOrderRequest
[NotNull]
[JsonProperty("payer")]
public CreateOrderPayerModel Payer { get; set; }

public class CreateOrderPayerModel
{
/// <summary>
Expand Down
Expand Up @@ -29,7 +29,7 @@ public class CloseOrderRequest
/// 示例值: 1217752501201407033233368018
/// </example>
[Required]
[StringLength(32,MinimumLength = 6)]
[StringLength(32, MinimumLength = 6)]
[JsonProperty("out_trade_no")]
[JsonIgnore]
public string OutTradeNo { get; set; }
Expand Down
Expand Up @@ -418,7 +418,9 @@ public class QueryOrderPromotionDetailGoodsDetail
/// <example>
/// 示例值: 1
/// </example>
[Required] [JsonProperty("quantity")] public int Quantity { get; set; }
[Required]
[JsonProperty("quantity")]
public int Quantity { get; set; }

/// <summary>
/// 商品单价。
Expand Down
@@ -0,0 +1,23 @@
using EasyAbp.Abp.WeChat.Pay.Services.ParametersModel;
using Newtonsoft.Json;

namespace EasyAbp.Abp.WeChat.Pay.Services.BasicPayment.NativePayment.Models;

/// <summary>
/// Native 支付 - 统一下单 - 返回结果。
/// </summary>
public class CreateOrderResponse : WeChatPayCommonErrorResponse
{
/// <summary>
/// 二维码链接。
/// </summary>
/// <remarks>
/// 此URL用于生成支付二维码,然后提供给用户扫码支付。
/// 注意: code_url 并非固定值,使用时按照 URL 格式转成二维码即可。
/// </remarks>
/// <example>
/// 示例值: weixin://wxpay/bizpayurl/up?pr=NwY5Mz9&groupid=00
/// </example>
[JsonProperty("code_url")]
public string CodeUrl { get; set; }
}
Expand Up @@ -3,6 +3,7 @@
using EasyAbp.Abp.WeChat.Pay.Options;
using EasyAbp.Abp.WeChat.Pay.Services.BasicPayment.Models;
using Volo.Abp.DependencyInjection;
using CreateOrderResponse = EasyAbp.Abp.WeChat.Pay.Services.BasicPayment.NativePayment.Models.CreateOrderResponse;

namespace EasyAbp.Abp.WeChat.Pay.Services.BasicPayment.NativePayment;

Expand Down

0 comments on commit 6b03c89

Please sign in to comment.