sunpengfei
2025-12-01 c87d61d03b48a6f55c0a0819b9be522f77e3c9a0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using Aop.Api.Domain;
using ApiTools.Core;
using Furion;
using Furion.HttpRemote;
using log4net.Core;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ApiTools.Application
{
    public class WxmpSubscribMessageCommandHandler(
            ILogger<WxmpSubscribMessageCommandHandler> logger,
            WxmpUtils utils,
            IHttpRemoteService httpRemoteService
        ) :
        IRequestHandler<SendWxmpSubscribMessageCommand, Guid>,
        IRequestHandler<WxmpSubscribMessageNotifyCommand, bool>
    {
        private readonly ILogger<WxmpSubscribMessageCommandHandler> logger = logger;
        private readonly WxmpUtils utils = utils;
        private readonly IHttpRemoteService httpRemoteService = httpRemoteService;
 
        /// <summary>
        /// 微信小程序发送订阅消息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Guid> Handle(SendWxmpSubscribMessageCommand request, CancellationToken cancellationToken)
        {
            await utils.WxmpSendSubscribMessage(new WxmpSendSubscribMessageRequest
            {
                Data = request.Data,
                TemplateId = request.TemplateId,
                Page = request.Page,
                WxmpCode = request.WxmpCode,
                Touser = request.Touser,
            });
            return Guid.Empty;
        }
 
        /// <summary>
        /// 微信小程序订阅消息通知
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<bool> Handle(WxmpSubscribMessageNotifyCommand request, CancellationToken cancellationToken)
        {
            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
                {
 
                }
            }
            return true;
        }
    }
}