一、引用阿里云短信官方的包
二、调用下面的方法
public bool AliMessageCode(string phone, string val)
{
var msg = "";
MessageCodeDto strJson = new MessageCodeDto();
//注意刚刚下载的AccessKey的excel中的accessKeyId和accessSecret填入
IClientProfile profile = DefaultProfile.GetProfile("default", "accesskey", "accesssecret");
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", phone);
request.AddQueryParameters("SignName", "你的模板名称");
request.AddQueryParameters("TemplateCode", "模板id");
MessageCodeRequest messageCode = new MessageCodeRequest()
{
code = val
};
var code = JsonHelper.SerializeObject(messageCode);
request.AddQueryParameters("TemplateParam", code); //需为json格式
// request.Protocol = ProtocolType.HTTP;
try
{
CommonResponse response = client.GetCommonResponse(request);
msg = Encoding.Default.GetString(response.HttpResponse.Content);
strJson = JsonHelper.DeserializeJsonToObject(msg);
}
catch (ServerException e)
{
msg = e.ErrorMessage;
}
catch (ClientException e)
{
msg = e.ErrorMessage;
}
if (strJson.Code == "OK")
{
return true;
}
else
{
return false;
}
}
三、调用
///
/// 短信推送
///
///
手机号/支持多个(阿里云文档写最多1000条,用","隔开)
///
验证码(自定义)
///
if (!_msg.AliMessageCode(phone, code)
{
/*获取验证码失败*/
sysCode = SysCode.GetCodeErr;
}
内容出处:,
声明:本网站所收集的部分公开资料来源于互联网,转载的目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。如果您发现网站上有侵犯您的知识产权的作品,请与我们取得联系,我们会及时修改或删除。文章链接:http://www.yixao.com/procedure/13527.html