接口文件
This commit is contained in:
46
Infrastructure/Hncore.Infrastructure/SMS/AliSmsService.cs
Normal file
46
Infrastructure/Hncore.Infrastructure/SMS/AliSmsService.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using Aliyun.Acs.Core;
|
||||
using Aliyun.Acs.Core.Exceptions;
|
||||
using Aliyun.Acs.Core.Http;
|
||||
using Aliyun.Acs.Core.Profile;
|
||||
using Hncore.Infrastructure.Serializer;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
namespace Hncore.Infrastructure.SMS
|
||||
{
|
||||
/// <summary>
|
||||
/// 发送短信
|
||||
/// </summary>
|
||||
public class AliSmsService
|
||||
{
|
||||
public static bool Send(string TemplateCode,object TemplateParam, string SignName="", params string[] PhoneNumbers)
|
||||
{
|
||||
IClientProfile profile = DefaultProfile.GetProfile("cn-hangzhou", "LTAI4FmSkDSwFuXeLxsDB3jB", "r8FfRmoeWcCJyZSqqkQP2G3dKPPl2N");
|
||||
DefaultAcsClient client = new DefaultAcsClient(profile);
|
||||
CommonRequest request = new CommonRequest();
|
||||
request.Method = MethodType.POST;
|
||||
request.Domain = "dysmsapi.aliyuncs.com";
|
||||
request.Version = "2017-05-25";
|
||||
request.Action = "SendSms";
|
||||
// request.Protocol = ProtocolType.HTTP;
|
||||
request.AddQueryParameters("PhoneNumbers", string.Join(",", PhoneNumbers));
|
||||
request.AddQueryParameters("SignName", SignName);
|
||||
request.AddQueryParameters("TemplateCode", TemplateCode);
|
||||
request.AddQueryParameters("TemplateParam", TemplateParam.ToJson());
|
||||
try
|
||||
{
|
||||
CommonResponse response = client.GetCommonResponse(request);
|
||||
Console.WriteLine(System.Text.Encoding.Default.GetString(response.HttpResponse.Content));
|
||||
return true;
|
||||
}
|
||||
catch (ServerException e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
catch (ClientException e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user