|
@@ -1,4 +1,5 @@
|
|
|
-using DotNetCore.CAP;
|
|
|
+using Amazon.Runtime.Internal.Transform;
|
|
|
+using DotNetCore.CAP;
|
|
|
using Hotline.Permissions;
|
|
|
using Hotline.Push;
|
|
|
using Hotline.Push.FWMessage;
|
|
@@ -8,10 +9,15 @@ using Hotline.Share.Dtos.Push;
|
|
|
using Hotline.Share.Dtos.Push.FWMessage;
|
|
|
using Hotline.Share.Enums.Push;
|
|
|
using Hotline.Share.Mq;
|
|
|
+using Hotline.Share.Tools;
|
|
|
+using Hotline.Users;
|
|
|
+using J2N.Text;
|
|
|
using MapsterMapper;
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using Microsoft.IdentityModel.Tokens;
|
|
|
+using Swashbuckle.AspNetCore.SwaggerGen;
|
|
|
+using System.Text;
|
|
|
using XF.Domain.Exceptions;
|
|
|
using XF.Domain.Repository;
|
|
|
using XF.Utility.EnumExtensions;
|
|
@@ -29,6 +35,7 @@ namespace Hotline.Api.Controllers
|
|
|
private readonly IRepository<BatchSmsTask> _batchSmsTaskRepository;
|
|
|
private readonly IRepository<BatchSmsTaskDetail> _batchSmsTaskDetailRepository;
|
|
|
private readonly ICapPublisher _capPublisher;
|
|
|
+ private readonly IRepository<User> _userRepository;
|
|
|
|
|
|
/// <summary>
|
|
|
///
|
|
@@ -43,7 +50,8 @@ namespace Hotline.Api.Controllers
|
|
|
IMessageCodeDomainService messageCodeDomainService,
|
|
|
IRepository<BatchSmsTask> batchSmsTaskRepository,
|
|
|
IRepository<BatchSmsTaskDetail> batchSmsTaskDetailRepository,
|
|
|
- ICapPublisher capPublisher)
|
|
|
+ ICapPublisher capPublisher,
|
|
|
+ IRepository<User> userRepository)
|
|
|
{
|
|
|
_messageRepository = messageRepository;
|
|
|
_mapper = mapper;
|
|
@@ -52,6 +60,7 @@ namespace Hotline.Api.Controllers
|
|
|
_batchSmsTaskRepository = batchSmsTaskRepository;
|
|
|
_batchSmsTaskDetailRepository = batchSmsTaskDetailRepository;
|
|
|
_capPublisher = capPublisher;
|
|
|
+ _userRepository = userRepository;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
@@ -114,6 +123,61 @@ namespace Hotline.Api.Controllers
|
|
|
await _pushDomainService.PushMsgAsync(dto, HttpContext.RequestAborted);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 发送短信
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost("send")]
|
|
|
+ public async Task<string> SendMessage([FromBody] MessageInDto dto)
|
|
|
+ {
|
|
|
+ var telNumbers = dto.TelNumbers.Split(",");
|
|
|
+ var count = 0;
|
|
|
+ var errorSB = new StringBuilder("失败原因: ");
|
|
|
+ var errorCount = 0;
|
|
|
+ for (int i = 0;i < telNumbers.Length;i++)
|
|
|
+ {
|
|
|
+ var telNumber = telNumbers[i];
|
|
|
+ if (telNumber.IsPhoneNumber() == false)
|
|
|
+ {
|
|
|
+ errorCount++;
|
|
|
+ errorSB.Append($" {telNumber}不是合法的手机号码.");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ var inDto = new MessageDto
|
|
|
+ {
|
|
|
+ TelNumber = telNumber,
|
|
|
+ Content = dto.Content,
|
|
|
+ PushBusiness = EPushBusiness.ManualSms,
|
|
|
+ Name = "",
|
|
|
+ };
|
|
|
+ try
|
|
|
+ {
|
|
|
+ await _pushDomainService.PushMsgAsync(inDto, HttpContext.RequestAborted);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ errorSB.Append(e.Message);
|
|
|
+ errorCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ return $"成功发送: {count}, 失败: {errorCount}. " + (errorCount != 0 ? "" : errorSB.ToString());
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 手动发送短信页面基础数据
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpGet("send/basedata")]
|
|
|
+ public async Task<dynamic> SendMessageBaseDataAsync()
|
|
|
+ {
|
|
|
+ var users = await _userRepository.Queryable()
|
|
|
+ .Select(m => new {m.Id, m.PhoneNo, m.Name }).ToListAsync();
|
|
|
+ return new Dictionary<string, dynamic>() { { "contacts", users } };
|
|
|
+ }
|
|
|
|
|
|
#endregion
|
|
|
|