From 6396dac27ca99e84a2e3c772fb079bceddf67ff8 Mon Sep 17 00:00:00 2001
From: sunpengfei <i@angelzzz.com>
Date: 星期一, 01 十二月 2025 18:17:45 +0800
Subject: [PATCH] feat:开发
---
ApiTools.Web.Entry/Controllers/WxmpController.cs | 49 +++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 41 insertions(+), 8 deletions(-)
diff --git a/ApiTools.Web.Entry/Controllers/WxmpController.cs b/ApiTools.Web.Entry/Controllers/WxmpController.cs
index 102d943..a3711b4 100644
--- a/ApiTools.Web.Entry/Controllers/WxmpController.cs
+++ b/ApiTools.Web.Entry/Controllers/WxmpController.cs
@@ -1,39 +1,72 @@
-锘縰sing ApiTools.Core;
+锘縰sing Aop.Api.Domain;
+using ApiTools.Core;
using Furion.DataEncryption;
+using Furion.DynamicApiController;
+using Furion.FriendlyException;
+using MediatR;
+using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
+using Newtonsoft.Json;
+using Org.BouncyCastle.Ocsp;
+using System.Buffers.Binary;
+using System.Security.Cryptography;
+using System.Text;
+using System.Threading.Tasks;
namespace ApiTools.Web.Entry.Controllers
{
[Route("api/common/wxmp")]
public class WxmpController(
WxmpUtils utils,
- IOptions<WxmpOptions> options
+ IOptions<WxmpOptions> options,
+ IMediator mediator
) : ControllerBase
{
private readonly WxmpUtils utils = utils;
private readonly IOptions<WxmpOptions> options = options;
+ private readonly IMediator mediator = mediator;
- [HttpGet("subscribMessageNotify")]
- public IActionResult SubscribMessageNotify([FromQuery] WxmpSubscribMessageNotifyRequestQuery request)
+ [HttpGet("subscribMessageNotify/{code}")]
+ [AllowAnonymous]
+ [NonUnify]
+ public IActionResult SubscribMessageNotify([FromRoute] string code, [FromQuery] WxmpSubscribMessageNotifyRequestQuery query)
{
var @params = new[]
{
options.Value.SubscribMessage.Token,
- request.Timestamp,
- request.Nonce
+ query.timestamp,
+ query.nonce
}
.OrderBy(p => p)
.ToArray();
var text = string.Concat(@params);
- if (SHA1Encryption.Compare(text, request.Signature, true))
+ if (SHA1Encryption.Compare(text, query.signature, true))
{
- return Content(request.Echostr);
+ return Content(query.echostr);
}
else
{
return Unauthorized("楠岀澶辫触");
}
}
+
+ [HttpPost("subscribMessageNotify/{code}")]
+ [AllowAnonymous]
+ [NonUnify]
+ public async Task<IActionResult> SubscribMessageNotify([FromRoute] string code, [FromQuery] WxmpSubscribMessageNotifyRequestQuery query, [FromBody] WxmpSubscribMessageNotifyRequestBody body)
+ {
+ var appId = options.Value.Items.FirstOrDefault(it => it.Code == code).AppId;
+ Tencent.WXBizMsgCrypt wxcpt = new Tencent.WXBizMsgCrypt(options.Value.SubscribMessage.Token, options.Value.SubscribMessage.EncodingAESKey, appId);
+ var data = $"<xml><ToUserName><![CDATA[{body.ToUserName}]]></ToUserName><Encrypt><![CDATA[{body.Encrypt}]]></Encrypt></xml>";
+ var content = "";
+ var error = wxcpt.DecryptMsg(query.msg_signature, query.timestamp, query.nonce, data, ref content);
+ if (error != 0) return Unauthorized("楠岀澶辫触");
+ var command = content.JsonTo<WxmpSubscribMessageNotifyCommand>();
+ command.Code = code;
+ command.OpenId = query.openid;
+ await mediator.Send(command);
+ return Content("success");
+ }
}
}
--
Gitblit v1.9.1