using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Dysmsapi.Model.V20170525;
using DTO;
using System;
using System.Collections.Generic;
using System.Text;
namespace CommonToolsCore
{
public class SMSHelper
{
static String product = "Dysmsapi";//短信API产品名称(短信产品名固定,无需修改)
static String domain = "dysmsapi.aliyuncs.com";//短信API产品域名(接口地址固定,无需修改)
static String accessKeyId = "LTAIZL9hStjo3whT";//你的accessKeyId,参考本文档步骤2
static String accessKeySecret = "fTrKqgHprJGwfyJW5qIO0JHFJ7JVRW";//你的accessKeySecret,参考本文档步骤2
public static ResultEntity SendSMS(string phone, string templateCode, string templateParmJson)
{
ResultEntity resultEntity = new ResultEntity();
IClientProfile profile = DefaultProfile.GetProfile("cn-hangzhou", accessKeyId, accessKeySecret);
//IAcsClient client = new DefaultAcsClient(profile);
// SingleSendSmsRequest request = new SingleSendSmsRequest();
//初始化ascClient,暂时不支持多region(请勿修改)
profile.AddEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
IAcsClient acsClient = new DefaultAcsClient(profile);
SendSmsRequest request = new SendSmsRequest();
try
{
//必填:待发送手机号。支持以逗号分隔的形式进行批量调用,批量上限为1000个手机号码,批量调用相对于单条调用及时性稍有延迟,验证码类型的短信推荐使用单条调用的方式
request.PhoneNumbers = phone;
//必填:短信签名-可在短信控制台中找到
request.SignName = "政采招投标";//坤德岩土
//必填:短信模板-可在短信控制台中找到
request.TemplateCode = templateCode;
//可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
request.TemplateParam = templateParmJson;
//可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
request.OutId = "";
//请求失败这里会抛ClientException异常
SendSmsResponse sendSmsResponse = acsClient.GetAcsResponse(request);
if(sendSmsResponse.Code == "OK")
{
resultEntity.Result = true;
}
else
{
resultEntity.Result = false;
resultEntity.Message = sendSmsResponse.Message;
}
}
catch (ServerException e)
{
resultEntity.Result = true;
resultEntity.Message = "发送失败" + e.Message;
return resultEntity;
}
catch (ClientException e)
{
resultEntity.Result = true;
resultEntity.Message = "发送失败" + e.Message;
return resultEntity;
}
return resultEntity;
}
///
/// 短信实例
///
///
///
///
public static ResultEntity PushWToUserBySMS(string phone, string date)
{
//if (string.IsNullOrEmpty(phone) || string.IsNullOrEmpty(date))
// return "";
string codeno = "SMS_156282130";
return SMSHelper.SendSMS(phone, codeno, "{\"date\":\"" + date + "\"}");
}
///
/// 短信实例
///
///
///
///
public static string PushWToUserMES(string phone, string conment)
{
string url = "https://mb345.com/ws/BatchSend2.aspx";
string data = "CorpID=XP010534&Pwd=123321&Mobile="+ phone + "&Content="+ conment + " 退订回N【政采咨询网】&SendTime=";
string ssss = HttpClientRequest.HttpClientPostGB2312(url, "POST", data);
return ssss;
}
///
/// 发送验证码
///
///
///
///
public static string PushWToUserMESYanZhengMa(string phone, string conment)
{
string url = "https://mb345.com/ws/BatchSend2.aspx";
string data = "CorpID=XP010534&Pwd=123321&Mobile=" + phone + "&Content=您好,您的验证码是:" + conment + "【政采咨询网】&SendTime=";
string ssss = HttpClientRequest.HttpClientPostGB2312(url, "POST", data);
return ssss;
}
}
}