You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/Areas/MvcShipping/Comm/AliMessageTools.cs

56 lines
2.8 KiB
C#

3 years ago
using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Dysmsapi.Model.V20170525;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
namespace DSWeb.MvcShipping.Comm
{
public class AliMessageTools
{
static String product = "Dysmsapi";//短信API产品名称
static String domain = "dysmsapi.aliyuncs.com";//短信API产品域名
private static String accessId = MsSysParamSetDAL.GetData("PARAMNAME='ALIYUNNAME'").PARAMVALUE;
private static String accessSecret = MsSysParamSetDAL.GetData("PARAMNAME='ALIYUNPASS'").PARAMVALUE;
private static String accesssSign = MsSysParamSetDAL.GetData("PARAMNAME='ALIYUNSIGN'").PARAMVALUE;
private static String accesssModel = MsSysParamSetDAL.GetData("PARAMNAME='ALIYUNModel'").PARAMVALUE;
static String regionIdForPop = "cn-hangzhou";
/// <summary>
/// 发送短信
/// </summary>
/// <param name="phoneNum"></param>
/// <param name="code"></param>
public static string SendSignCodeMsg(string phoneNum,string msg)
{
IClientProfile profile = DefaultProfile.GetProfile(regionIdForPop, accessId, accessSecret);
DefaultProfile.AddEndpoint(regionIdForPop, regionIdForPop, product, domain);
IAcsClient acsClient = new DefaultAcsClient(profile);
SendSmsRequest request = new SendSmsRequest();
try
{
//request.SignName = "上云预发测试";//"管理控制台中配置的短信签名(状态必须是验证通过)"
//request.TemplateCode = "SMS_71130001";//管理控制台中配置的审核通过的短信模板的模板CODE状态必须是验证通过"
//request.RecNum = "13567939485";//"接收号码,多个号码可以逗号分隔"
//request.ParamString = "{\"name\":\"123\"}";//短信模板中的变量数字需要转换为字符串个人用户每个变量长度必须小于15个字符。"
//SingleSendSmsResponse httpResponse = client.GetAcsResponse(request);
request.PhoneNumbers = phoneNum;
request.SignName = accesssSign;//短信签名
request.TemplateCode = accesssModel;//短信模板
request.TemplateParam = "{\"code\":\""+msg+"\"}";//模板中的变量
request.OutId = "001";//扩展字段-返回值
//请求失败这里会抛ClientException异常
SendSmsResponse sendSmsResponse = acsClient.GetAcsResponse(request);
return sendSmsResponse.Message;
}
catch (ServerException e)
{
return e.Message;
}
catch (ClientException e)
{
return e.Message;
}
}
}
}