.NET CORE3.1实现微信小程序发送订阅消息(5)

using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using WXERP.Services; namespace WXERP.Controllers {   /// <summary>   /// 消息控制器   /// </summary>   [Route("api/[controller]")]   [ApiController]   public class MessageController : ControllerBase   {     private readonly MessageContext _context;     /// <summary>     /// 初始化消息     /// </summary>     public MessageController()     {       _context = new MessageContext();     }     /// <summary>微信消息</summary>     /// <remarks>驗證消息來自於微信服務器</remarks>     /// <param>微信加密簽名,signature結合了開發者填寫的token、timestamp、nonce</param>     /// <param>時間戳</param>     /// <param>隨機數</param>     /// <param>隨機字符串</param>     /// <returns></returns>     [HttpGet("checkSignature")]     [AllowAnonymous]     public async void CheckSignature(string signature,string timestamp,string nonce,string echostr)     {       bool result = await _context.CheckSignature(signature, timestamp, nonce);       if (result)       {         HttpContext.Response.ContentType = "text/plain; charset=utf-8";         await HttpContext.Response.WriteAsync(echostr);       }       else       {         HttpContext.Response.StatusCode = 409;         HttpContext.Response.ContentType = "text/plain; charset=utf-8";         await HttpContext.Response.WriteAsync("error");       }     }   } }

九、调用小程序订阅消息,需要自己实现其他逻辑

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/4fcdba8fbd80227d9ab75d0286a96833.html