【优化】调整短信发送回调xml到json格式,并直接返回发送失败后的异常提示。

This commit is contained in:
jianweie
2023-04-03 16:28:12 +08:00
parent f1a72ac922
commit 5c3e63593f
4 changed files with 98 additions and 15 deletions

View File

@@ -26,6 +26,7 @@ using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SqlSugar;
using static SKIT.FlurlHttpClient.Wechat.Api.Models.WxaApiUserLogSearchResponse.Types.Data.Types.RealtimeLog.Types;
namespace CoreCms.Net.Services
@@ -108,10 +109,10 @@ namespace CoreCms.Net.Services
await _dal.InsertAsync(oldLog);
}
var str = await SendSms(oldLog.mobile, oldLog.contentBody, smsOptions);
jm.status = true;
//jm.data = str;
jm.msg = "短信发送成功";
var result = await SendSms(oldLog.mobile, oldLog.contentBody, smsOptions);
jm.status = result.IsSuccess;
jm.msg = result.IsSuccess ? "发送成功" : result.Message;
return jm;
}
@@ -155,24 +156,34 @@ namespace CoreCms.Net.Services
/// <param name="mobile"></param>
/// <param name="contentBody"></param>
/// <param name="smsOptions">配置文件</param>
public async Task<string> SendSms(string mobile, string contentBody, SmsOptions smsOptions)
public async Task<SMSReturnData> SendSms(string mobile, string contentBody, SmsOptions smsOptions)
{
if (smsOptions.Enabled)
{
var str = await smsOptions.ApiUrl.PostUrlEncodedAsync(new
var result = await smsOptions.ApiUrl.PostUrlEncodedAsync(new
{
action = "send",
userid = smsOptions.UserId,
account = smsOptions.Account,
password = smsOptions.Password,
mobile = mobile,
mobile,
content = "【" + smsOptions.Signature + "】" + contentBody,
}).ReceiveString();
return str;
rt = "json"
}).ReceiveJson<SMSReturnData>();
result.IsSuccess = result.ReturnStatus == "success";
return result;
}
else
{
return "短信接口未开启";
var result = new SMSReturnData()
{
ReturnStatus = "faild",
Message = "短信功能未开启",
RemainPoint = 0,
TaskID = 0,
SuccessCounts = 0
};
return result;
}
}
#endregion
@@ -354,11 +365,10 @@ namespace CoreCms.Net.Services
await _dal.InsertAsync(oldLog);
var result = SendSms(oldLog.mobile, oldLog.contentBody, smsOptions);
var result = await SendSms(oldLog.mobile, oldLog.contentBody, smsOptions);
jm.status = true;
jm.msg = "发送成功";
//jm.data = result;
jm.status = result.IsSuccess;
jm.msg = result.IsSuccess ? "发送成功" : result.Message;
return jm;
}