|
@@ -1,6 +1,9 @@
|
|
-using Hotline.Share.Dtos.Push;
|
|
|
|
|
|
+using Hotline.Push.Notifies;
|
|
|
|
+using Hotline.Share.Dtos.Push;
|
|
using Hotline.Share.Enums.Push;
|
|
using Hotline.Share.Enums.Push;
|
|
using MapsterMapper;
|
|
using MapsterMapper;
|
|
|
|
+using MediatR;
|
|
|
|
+using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Logging;
|
|
@@ -24,6 +27,7 @@ public class PushDomainService : IPushDomainService, IScopeDependency
|
|
private readonly ILogger<PushDomainService> _logger;
|
|
private readonly ILogger<PushDomainService> _logger;
|
|
private readonly IConfiguration _config;
|
|
private readonly IConfiguration _config;
|
|
private readonly SmsAccountInfo accountInfo = null;
|
|
private readonly SmsAccountInfo accountInfo = null;
|
|
|
|
+ private readonly IMediator _mediator;
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
///
|
|
///
|
|
@@ -33,7 +37,9 @@ public class PushDomainService : IPushDomainService, IScopeDependency
|
|
/// <param name="logger"></param>
|
|
/// <param name="logger"></param>
|
|
/// <param name="mapper"></param>
|
|
/// <param name="mapper"></param>
|
|
/// <param name="config"></param>
|
|
/// <param name="config"></param>
|
|
- public PushDomainService(IMessageRepository messageRepository, IHttpClientFactory httpClientFactory, ILogger<PushDomainService> logger, IMapper mapper, IConfiguration config)
|
|
|
|
|
|
+ /// <param name="mediator"></param>
|
|
|
|
+ public PushDomainService(IMessageRepository messageRepository, IHttpClientFactory httpClientFactory, ILogger<PushDomainService> logger
|
|
|
|
+ , IMapper mapper, IConfiguration config, IMediator mediator)
|
|
{
|
|
{
|
|
_messageRepository = messageRepository;
|
|
_messageRepository = messageRepository;
|
|
_httpClientFactory = httpClientFactory;
|
|
_httpClientFactory = httpClientFactory;
|
|
@@ -41,6 +47,7 @@ public class PushDomainService : IPushDomainService, IScopeDependency
|
|
_mapper = mapper;
|
|
_mapper = mapper;
|
|
_config = config;
|
|
_config = config;
|
|
accountInfo = _config.GetSection("SmsAccountInfo").Get<SmsAccountInfo>();
|
|
accountInfo = _config.GetSection("SmsAccountInfo").Get<SmsAccountInfo>();
|
|
|
|
+ _mediator = mediator;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -137,42 +144,33 @@ public class PushDomainService : IPushDomainService, IScopeDependency
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 短信发送状态回调接口
|
|
/// 短信发送状态回调接口
|
|
/// </summary>
|
|
/// </summary>
|
|
- /// <param name="account">短信回传账号</param>
|
|
|
|
- /// <param name="pswd">短信回传密码</param>
|
|
|
|
- /// <param name="msgid">短信中心短信待发送ID,同短信发送接口返回值ID</param>
|
|
|
|
- /// <param name="sendtime">短信发送时间</param>
|
|
|
|
- /// <param name="msgcount">发送短信使用的数量</param>
|
|
|
|
- /// <param name="state">发送状态:0:未发送 1:发送中 2:发送失败 3:发送成功</param>
|
|
|
|
- /// <param name="errormsg">错误消息</param>
|
|
|
|
- /// <param name="sfid">短信中心短信已发送ID</param>
|
|
|
|
- /// <param name="telnumall">手机号码</param>
|
|
|
|
- /// <param name="sign">短信签名</param>
|
|
|
|
|
|
+ /// <param name="receiveMessageDto"></param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
- public async Task<string> ReceiveObtain(string account, string pswd, string msgid, string sendtime, int msgcount, int state, string errormsg, int sfid, string telnumall, string sign)
|
|
|
|
|
|
+ public async Task<string> ReceiveObtain(ReceiveMessageDto receiveMessageDto)
|
|
{
|
|
{
|
|
string strResult = "error,缺少参数";
|
|
string strResult = "error,缺少参数";
|
|
- if (account != accountInfo.ReturnAccountUser || pswd != accountInfo.ReturnAccountPwd)
|
|
|
|
|
|
+ if (receiveMessageDto.account != accountInfo.ReturnAccountUser || receiveMessageDto.pswd != accountInfo.ReturnAccountPwd)
|
|
{
|
|
{
|
|
strResult = "error,参数错误";
|
|
strResult = "error,参数错误";
|
|
return strResult;
|
|
return strResult;
|
|
}
|
|
}
|
|
- if (true == string.IsNullOrEmpty(account) || true == string.IsNullOrEmpty(pswd)
|
|
|
|
- || true == string.IsNullOrEmpty(msgid) || true == string.IsNullOrEmpty(sendtime)
|
|
|
|
- || msgcount <= 0 || state < 0)
|
|
|
|
|
|
+ if (true == string.IsNullOrEmpty(receiveMessageDto.account) || true == string.IsNullOrEmpty(receiveMessageDto.pswd)
|
|
|
|
+ || true == string.IsNullOrEmpty(receiveMessageDto.msgid) || true == string.IsNullOrEmpty(receiveMessageDto.sendtime)
|
|
|
|
+ || receiveMessageDto.msgcount <= 0 || receiveMessageDto.state < 0)
|
|
{
|
|
{
|
|
strResult = "error,参数错误";
|
|
strResult = "error,参数错误";
|
|
return strResult;
|
|
return strResult;
|
|
}
|
|
}
|
|
|
|
|
|
//修改数据
|
|
//修改数据
|
|
- var data = await _messageRepository.GetAsync(p => p.SmsWaitSendingId == msgid);
|
|
|
|
|
|
+ var data = await _messageRepository.GetAsync(p => p.SmsWaitSendingId == receiveMessageDto.msgid);
|
|
if (data != null)
|
|
if (data != null)
|
|
{
|
|
{
|
|
- data.SendTime = Convert.ToDateTime(sendtime);
|
|
|
|
- data.MsgCount = msgcount;
|
|
|
|
- data.SendState = (ESendState)state;
|
|
|
|
- data.SmsSendingCompletedId = sfid + "";
|
|
|
|
- data.Remark = errormsg;
|
|
|
|
|
|
+ data.SendTime = Convert.ToDateTime(receiveMessageDto.sendtime);
|
|
|
|
+ data.MsgCount = receiveMessageDto.msgcount;
|
|
|
|
+ data.SendState = (ESendState)receiveMessageDto.state;
|
|
|
|
+ data.SmsSendingCompletedId = receiveMessageDto.sfid + "";
|
|
|
|
+ data.Remark = receiveMessageDto.errormsg;
|
|
await _messageRepository.UpdateAsync(data);
|
|
await _messageRepository.UpdateAsync(data);
|
|
// 成功返回值必须是ok
|
|
// 成功返回值必须是ok
|
|
strResult = "ok";
|
|
strResult = "ok";
|
|
@@ -183,6 +181,47 @@ public class PushDomainService : IPushDomainService, IScopeDependency
|
|
return strResult;
|
|
return strResult;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 短信接收
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="receiveMessageDto"></param>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ public async Task<string> ReceiveSms(ReceiveMessageDto receiveMessageDto)
|
|
|
|
+ {
|
|
|
|
+ string strResult = "error,缺少参数";
|
|
|
|
+ if (receiveMessageDto.account != accountInfo.ReturnAccountUser || receiveMessageDto.pswd != accountInfo.ReturnAccountPwd)
|
|
|
|
+ {
|
|
|
|
+ strResult = "error,参数错误";
|
|
|
|
+ return strResult;
|
|
|
|
+ }
|
|
|
|
+ if (true == string.IsNullOrEmpty(receiveMessageDto.account) || true == string.IsNullOrEmpty(receiveMessageDto.pswd)
|
|
|
|
+ || true == string.IsNullOrEmpty(receiveMessageDto.msg) || true == string.IsNullOrEmpty(receiveMessageDto.mobile)
|
|
|
|
+ || true == string.IsNullOrEmpty(receiveMessageDto.motime))
|
|
|
|
+ {
|
|
|
|
+ strResult = "error,参数错误";
|
|
|
|
+ return strResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var data = await _messageRepository.GetAsync(p => p.TelNumber == receiveMessageDto.mobile && p.IsSmsReply == false && p.SmsReplyTime == null);
|
|
|
|
+ if (data != null)
|
|
|
|
+ {
|
|
|
|
+ data.IsSmsReply = true;
|
|
|
|
+ data.SmsReplyTime = Convert.ToDateTime(receiveMessageDto.motime);
|
|
|
|
+ data.SmsReplyContent = receiveMessageDto.msg;
|
|
|
|
+ await _messageRepository.UpdateAsync(data);
|
|
|
|
+
|
|
|
|
+ //消息处理
|
|
|
|
+ await _mediator.Publish(new PushMessageNotify(_mapper.Map<PushMessageNotifyDto>(data)));
|
|
|
|
+ // 成功返回值必须是ok
|
|
|
|
+ strResult = "ok";
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ strResult = "error,调用失败";
|
|
|
|
+
|
|
|
|
+ return strResult;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
#region 私有方法
|
|
#region 私有方法
|
|
|
|
|
|
#region 短信发送
|
|
#region 短信发送
|