mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-07-17 10:41:58 +08:00
docs: 完善微信商户平台模块的示例项目
This commit is contained in:
parent
e68661493c
commit
9fcf4ab1d2
@ -15,15 +15,26 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Sample_Net5.Controllers
|
||||
public class WxpayNotifyController : ControllerBase
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly Services.HttpClients.IWechatTenpayHttpClientFactory _wechatTenpayHttpClientFactory;
|
||||
|
||||
public WxpayNotifyController(
|
||||
ILoggerFactory loggerFactory)
|
||||
ILoggerFactory loggerFactory,
|
||||
Services.HttpClients.IWechatTenpayHttpClientFactory wechatTenpayHttpClientFactory)
|
||||
{
|
||||
_logger = loggerFactory.CreateLogger(GetType());
|
||||
_wechatTenpayHttpClientFactory = wechatTenpayHttpClientFactory;
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> ReceiveMessage()
|
||||
[Route("m-{merchant_id}/message-push")]
|
||||
public async Task<IActionResult> ReceiveMessage(
|
||||
[FromRoute(Name = "merchant_id")] string merchantId,
|
||||
[FromHeader(Name = "Wechatpay-Timestamp")] string timestamp,
|
||||
[FromHeader(Name = "Wechatpay-Nonce")] string nonce,
|
||||
[FromHeader(Name = "Wechatpay-Signature")] string signature,
|
||||
[FromHeader(Name = "Wechatpay-Serial")] string serialNumber)
|
||||
{
|
||||
// 接收服务器推送
|
||||
// 文档:https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay4_2.shtml
|
||||
@ -32,6 +43,19 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Sample_Net5.Controllers
|
||||
string content = await reader.ReadToEndAsync();
|
||||
_logger.LogInformation("接收到微信支付推送的数据:{0}", content);
|
||||
|
||||
var client = _wechatTenpayHttpClientFactory.Create(merchantId);
|
||||
bool valid = client.VerifyEventSignature(
|
||||
callbackTimestamp: timestamp,
|
||||
callbackNonce: nonce,
|
||||
callbackBody: content,
|
||||
callbackSignature: signature,
|
||||
callbackSerialNumber: serialNumber
|
||||
);
|
||||
if (!valid)
|
||||
{
|
||||
return new JsonResult(new { code = "FAIL", message = "验签失败" });
|
||||
}
|
||||
|
||||
return new JsonResult(new { code = "SUCCESS", message = "成功" });
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user