忽略
This commit is contained in:
@@ -1,71 +1,71 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Serialization;
|
||||
using Hncore.Infrastructure.Common;
|
||||
using Hncore.Infrastructure.Serializer;
|
||||
|
||||
namespace Hncore.Infrastructure.AliYun
|
||||
{
|
||||
public class AliDayu
|
||||
{
|
||||
const string SignName = "";
|
||||
private IHttpClientFactory _httpClientFactory;
|
||||
|
||||
public AliDayu(IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
_httpClientFactory = httpClientFactory;
|
||||
}
|
||||
|
||||
public async Task<bool> SendSms(List<string> PhoneNumbers, string templateCode, object content)
|
||||
{
|
||||
Dictionary<string, string> paramDic = Util.BuildCommonParam();
|
||||
|
||||
paramDic.Add("Action", "SendSms");
|
||||
paramDic.Add("Version", "2017-05-25");
|
||||
paramDic.Add("RegionId", "cn-hangzhou");
|
||||
paramDic.Add("PhoneNumbers", ListHelper<string>.ListToStr(PhoneNumbers));
|
||||
paramDic.Add("SignName", SignName);
|
||||
paramDic.Add("TemplateCode", templateCode);
|
||||
paramDic.Add("TemplateParam", content.ToJson());
|
||||
|
||||
string sign = Util.CreateSign(paramDic);
|
||||
|
||||
paramDic.Add("Signature", sign);
|
||||
|
||||
var httpClient = _httpClientFactory.CreateClient("AliDayu");
|
||||
|
||||
string url = "http://dysmsapi.aliyuncs.com";
|
||||
|
||||
foreach (var keyValuePair in paramDic)
|
||||
{
|
||||
url = UrlHelper.SetUrlParam(keyValuePair.Key, keyValuePair.Value);
|
||||
}
|
||||
|
||||
var res = await httpClient.GetStringAsync(url);
|
||||
|
||||
SendSmsResponse result = XML.XmlDeserialize<SendSmsResponse>(res);
|
||||
|
||||
if (result.Code == "OK")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
LogHelper.Error("阿里大于短信发送失败", res);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[XmlRoot]
|
||||
public class SendSmsResponse
|
||||
{
|
||||
[XmlElement] public string Message { get; set; }
|
||||
|
||||
[XmlElement] public string RequestId { get; set; }
|
||||
|
||||
[XmlElement] public string BizId { get; set; }
|
||||
|
||||
[XmlElement] public string Code { get; set; }
|
||||
}
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Serialization;
|
||||
using Hncore.Infrastructure.Common;
|
||||
using Hncore.Infrastructure.Serializer;
|
||||
|
||||
namespace Hncore.Infrastructure.AliYun
|
||||
{
|
||||
public class AliDayu
|
||||
{
|
||||
const string SignName = "";
|
||||
private IHttpClientFactory _httpClientFactory;
|
||||
|
||||
public AliDayu(IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
_httpClientFactory = httpClientFactory;
|
||||
}
|
||||
|
||||
public async Task<bool> SendSms(List<string> PhoneNumbers, string templateCode, object content)
|
||||
{
|
||||
Dictionary<string, string> paramDic = Util.BuildCommonParam();
|
||||
|
||||
paramDic.Add("Action", "SendSms");
|
||||
paramDic.Add("Version", "2017-05-25");
|
||||
paramDic.Add("RegionId", "cn-hangzhou");
|
||||
paramDic.Add("PhoneNumbers", ListHelper<string>.ListToStr(PhoneNumbers));
|
||||
paramDic.Add("SignName", SignName);
|
||||
paramDic.Add("TemplateCode", templateCode);
|
||||
paramDic.Add("TemplateParam", content.ToJson());
|
||||
|
||||
string sign = Util.CreateSign(paramDic);
|
||||
|
||||
paramDic.Add("Signature", sign);
|
||||
|
||||
var httpClient = _httpClientFactory.CreateClient("AliDayu");
|
||||
|
||||
string url = "http://dysmsapi.aliyuncs.com";
|
||||
|
||||
foreach (var keyValuePair in paramDic)
|
||||
{
|
||||
url = UrlHelper.SetUrlParam(keyValuePair.Key, keyValuePair.Value);
|
||||
}
|
||||
|
||||
var res = await httpClient.GetStringAsync(url);
|
||||
|
||||
SendSmsResponse result = XML.XmlDeserialize<SendSmsResponse>(res);
|
||||
|
||||
if (result.Code == "OK")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
LogHelper.Error("阿里大于短信发送失败", res);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[XmlRoot]
|
||||
public class SendSmsResponse
|
||||
{
|
||||
[XmlElement] public string Message { get; set; }
|
||||
|
||||
[XmlElement] public string RequestId { get; set; }
|
||||
|
||||
[XmlElement] public string BizId { get; set; }
|
||||
|
||||
[XmlElement] public string Code { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user