Skip to content

Commit

Permalink
Merge pull request #103 from EasyAbp/wechatpay-v3-jspayment
Browse files Browse the repository at this point in the history
WeChat Pay Notification Callback
  • Loading branch information
real-zony authored Jan 9, 2024
2 parents 4d422e5 + da17872 commit c30acff
Show file tree
Hide file tree
Showing 24 changed files with 353 additions and 286 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
using System;
using System.ComponentModel.DataAnnotations;
using JetBrains.Annotations;

namespace EasyAbp.Abp.WeChat.Pay.RequestHandling.Dtos;

[Serializable]
public class PaidNotifyInput
{
public string MchId { get; set; }
[CanBeNull] public string MchId { get; set; }

[Required]
public string Xml { get; set; }
public PaymentNotifyCallbackRequest RequestBody { get; set; }

public string SerialNumber { get; set; }

public string Timestamp { get; set; }

public string Nonce { get; set; }

public string RequestBodyString { get; set; }

public string Signature { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using System.Text.Json.Serialization;

namespace EasyAbp.Abp.WeChat.Pay.RequestHandling.Dtos;

public class PaymentNotifyCallbackRequest
{
/// <summary>
/// 通知 ID。
/// </summary>
[JsonPropertyName("id")]
public string Id { get; set; }

/// <summary>
/// 通知创建时间。
/// </summary>
[JsonPropertyName("create_time")]
public DateTime CreateTime { get; set; }

/// <summary>
/// 通知类型。
/// </summary>
[JsonPropertyName("event_type")]
public string EventType { get; set; }

/// <summary>
/// 通知数据类型。
/// </summary>
[JsonPropertyName("resource_type")]
public string ResourceType { get; set; }

/// <summary>
/// 回调摘要。
/// </summary>
[JsonPropertyName("summary")]
public string Summary { get; set; }

/// <summary>
/// 通知数据。
/// </summary>
[JsonPropertyName("resource")]
public ResourceModel Resource { get; set; }

public class ResourceModel
{
/// <summary>
/// 加密算法类型。
/// </summary>
[JsonPropertyName("algorithm")]
public string Algorithm { get; set; }

/// <summary>
/// 数据密文。
/// </summary>
[JsonPropertyName("ciphertext")]
public string Ciphertext { get; set; }

/// <summary>
/// 附加数据。
/// </summary>
[JsonPropertyName("associated_data")]
public string AssociatedData { get; set; }

/// <summary>
/// 原始类型。
/// </summary>
[JsonPropertyName("original_type")]
public string OriginalType { get; set; }

/// <summary>
/// 随机串。
/// </summary>
[JsonPropertyName("nonce")]
public string Nonce { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Text.Json.Serialization;

namespace EasyAbp.Abp.WeChat.Pay.RequestHandling.Dtos;

public class PaymentNotifyCallbackResponse
{
/// <summary>
/// 返回状态码。
/// </summary>
[JsonPropertyName("code")]
public string Code { get; set; }

/// <summary>
/// 返回信息。
/// </summary>
[JsonPropertyName("message")]
public string Message { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using JetBrains.Annotations;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc;

Expand Down Expand Up @@ -34,22 +35,33 @@ public WeChatPayController(
/// </summary>
[HttpPost]
[Route("notify")]
public virtual async Task<ActionResult> NotifyAsync([CanBeNull] string tenantId, [CanBeNull] string mchId)
public virtual async Task<ActionResult> NotifyAsync([CanBeNull] [FromQuery] string tenantId,
[CanBeNull] [FromQuery] string mchId)
{
using var changeTenant = CurrentTenant.Change(tenantId.IsNullOrWhiteSpace() ? null : Guid.Parse(tenantId!));

var result = await _eventRequestHandlingService.PaidNotifyAsync(new PaidNotifyInput
{
MchId = mchId,
Xml = await GetPostDataAsync()
});

if (!result.Success)
{
return BadRequest(BuildFailedXml(result.FailureReason));
}

return Ok(BuildSuccessXml());
var body = await GetPostDataAsync();
// var result = await _eventRequestHandlingService.PaidNotifyAsync(new PaidNotifyInput
// {
// MchId = mchId,
// RequestBodyString = body,
// RequestBody = JsonConvert.DeserializeObject<PaymentNotifyCallbackRequest>(body),
// SerialNumber = Request.Headers["Wechatpay-Serial"],
// Timestamp = Request.Headers["Wechatpay-TimeStamp"],
// Nonce = Request.Headers["Wechatpay-Nonce"],
// Signature = Request.Headers["Wechatpay-Signature"]
// });
//
// if (!result.Success)
// {
// return BadRequest(new PaymentNotifyCallbackResponse
// {
// Code = "FAIL",
// Message = "处理失败"
// });
// }

return Ok();
}

/// <summary>
Expand Down Expand Up @@ -107,7 +119,7 @@ public virtual async Task<ActionResult> RefundNotifyAsync([CanBeNull] string ten

return Ok(BuildSuccessXml());
}

/// <summary>
/// 本方法是为了避免多 Route 导致 ABP ApiDescription 报 Warning。
/// 见 <see cref="RefundNotifyAsync"/>
Expand All @@ -118,7 +130,7 @@ public virtual Task<ActionResult> RefundNotify2Async([CanBeNull] string tenantId
{
return RefundNotifyAsync(tenantId, mchId);
}

/// <summary>
/// 本方法是为了避免多 Route 导致 ABP ApiDescription 报 Warning。
/// 见 <see cref="RefundNotifyAsync"/>
Expand All @@ -129,7 +141,7 @@ public virtual Task<ActionResult> RefundNotify3Async([CanBeNull] string tenantId
{
return RefundNotifyAsync(tenantId, mchId);
}

/// <summary>
/// 本方法是为了避免多 Route 导致 ABP ApiDescription 报 Warning。
/// 见 <see cref="RefundNotifyAsync"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<ItemGroup>
<ProjectReference Include="..\EasyAbp.Abp.WeChat.Pay.Abstractions\EasyAbp.Abp.WeChat.Pay.Abstractions.csproj" />
<ProjectReference Include="..\EasyAbp.Abp.WeChat.Pay\EasyAbp.Abp.WeChat.Pay.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion src/Pay/EasyAbp.Abp.WeChat.Pay/AbpWeChatPayModule.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using EasyAbp.Abp.WeChat.Common;
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(AbpWeChatPayAbstractionsModule),
typeof(AbpJsonNewtonsoftModule)
)]
public class AbpWeChatPayModule : AbpModule
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<PackageReference Include="Volo.Abp.BlobStoring" Version="$(AbpVersion)" />
<PackageReference Include="Volo.Abp.BackgroundWorkers" Version="$(AbpVersion)" />
<PackageReference Include="Volo.Abp.DistributedLocking.Abstractions" Version="$(AbpVersion)" />
<PackageReference Include="Volo.Abp.Json.Newtonsoft" Version="8.0.1" />
</ItemGroup>

</Project>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
using System.Xml;
using EasyAbp.Abp.WeChat.Pay.Options;
using JetBrains.Annotations;

namespace EasyAbp.Abp.WeChat.Pay.RequestHandling;

public class WeChatPayEventModel
{
public AbpWeChatPayOptions Options { get; set; }

public XmlDocument WeChatRequestXmlData { get; set; }

[CanBeNull]
public XmlDocument DecryptedXmlData { get; set; }
}
Loading

0 comments on commit c30acff

Please sign in to comment.