sunpengfei
2025-10-09 a209b2ed87bc2a564ef58de4eccc879df5bf337b
ApiTools.Application/SmsUtils/Commands/SmsAliyunNotifyCommandHandler.cs
@@ -1,8 +1,12 @@
using ApiTools.Core;
using Baidu.Aip.BodyAnalysis;
using Furion;
using Furion.DatabaseAccessor;
using Furion.HttpRemote;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
@@ -18,13 +22,15 @@
    public class SmsAliyunNotifyCommandHandler(
            IRepository<SmsSetting> repSmsSetting,
            IRepository<SmsLog> repSmsLog,
            ApiTools.Core.SmsUtils smsUtils
            ApiTools.Core.SmsUtils smsUtils,
            IHttpRemoteService httpRemoteService
        )
        : IRequestHandler<SmsAliyunNotifyCommand, SmsAliyunNotifyCommandResult>
    {
        private readonly IRepository<SmsSetting> repSmsSetting = repSmsSetting;
        private readonly IRepository<SmsLog> repSmsLog = repSmsLog;
        private readonly Core.SmsUtils smsUtils = smsUtils;
        private readonly IHttpRemoteService httpRemoteService = httpRemoteService;
        /// <summary>
        /// 阿里云短信平台回传通知
@@ -34,6 +40,21 @@
        /// <returns></returns>
        public async Task<SmsAliyunNotifyCommandResult> Handle(SmsAliyunNotifyCommand 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/sms/smsAliyunNotify",
                        builder => builder.SetJsonContent(json));
                }
                catch
                {
                }
            }
            var templateCodes = await EnumUtils.GetModel<EnumSmsTemplateCode>();
            var msgIds = request.DistinctSelect(it => it.BizId.ToString());
            var entities = await repSmsLog.AsQueryable()