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"; /// /// 发送短信 /// /// /// 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; } } } }