| | |
| | | using Aop.Api.Domain; |
| | | using ApiTools.Core; |
| | | using Furion; |
| | | using Furion.HttpRemote; |
| | | using log4net.Core; |
| | | using MediatR; |
| | | using Microsoft.AspNetCore.Http; |
| | |
| | | public class WxmpSubscribMessageCommandHandler( |
| | | ILogger<WxmpSubscribMessageCommandHandler> logger, |
| | | WxmpUtils utils, |
| | | IHttpContextAccessor httpContextAccessor |
| | | IHttpRemoteService httpRemoteService |
| | | ) : |
| | | IRequestHandler<SendWxmpSubscribMessageCommand, Guid>, |
| | | IRequestHandler<WxmpSubscribMessageNotifyCommand, bool> |
| | | { |
| | | private readonly ILogger<WxmpSubscribMessageCommandHandler> logger = logger; |
| | | private readonly WxmpUtils utils = utils; |
| | | private readonly IHttpContextAccessor httpContextAccessor = httpContextAccessor; |
| | | private readonly IHttpRemoteService httpRemoteService = httpRemoteService; |
| | | |
| | | /// <summary> |
| | | /// 微信小程序发送订阅消息 |
| | |
| | | /// <returns></returns> |
| | | public async Task<bool> Handle(WxmpSubscribMessageNotifyCommand request, CancellationToken cancellationToken) |
| | | { |
| | | var req = httpContextAccessor.HttpContext.Request; |
| | | logger.LogInformation($"微信小程序订阅消息通知query:{req.QueryString.Value}"); |
| | | var env = App.GetConfig<string>("Environment"); |
| | | if (env == "Product") |
| | | { |
| | | try |
| | | { |
| | | var json = request.ToJson(); |
| | | await httpRemoteService.PostAsStringAsync("http://118.178.252.28:8780/api/common/wxmp/wxmpSubscribMessageNotify", |
| | | builder => builder.SetJsonContent(json)); |
| | | } |
| | | catch |
| | | { |
| | | |
| | | req.EnableBuffering(); |
| | | req.Body.Position = 0; |
| | | using var reader = new StreamReader(req.Body, Encoding.UTF8, leaveOpen: true); |
| | | var body = await reader.ReadToEndAsync(); |
| | | logger.LogInformation($"微信小程序订阅消息通知body:{body}"); |
| | | req.Body.Position = 0; |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | } |