Beispiel #1
0
        /// <summary>
        /// 发送模板消息
        /// </summary>
        /// <param name="input">模板消息</param>
        /// <returns></returns>
        public Task <SmsResult> SendTemplateMessageAsync(SendTemplateMessageInput input)
        {
            if (string.IsNullOrWhiteSpace(input.PhoneNumber))
            {
                throw new SmsException("手机号码不能为空!");
            }
            var client    = new AliyunSmsClient();
            var acsClient = client.AcsClient;
            var request   = new SendSmsRequest();
            var result    = new SmsResult();

            try
            {
                //必填:待发送手机号。支持以逗号分隔的形式进行批量调用,批量上限为1000个手机号码,批量调用相对于单条调用及时性稍有延迟,验证码类型的短信推荐使用单条调用的方式
                request.PhoneNumbers = input.PhoneNumber;
                //必填:短信签名-可在短信控制台中找到
                request.SignName = input.SignName;
                //必填:短信模板-可在短信控制台中找到
                request.TemplateCode = input.TemplateCode;
                //可选:模板中的变量替换JSON串
                if (input.HaveParm)
                {
                    request.TemplateParam = input.ToString();
                }
                ////可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
                //request.OutId = client.AliyunSmsSettting.OutId;
                //请求失败这里会抛ClientException异常
                var sendSmsResponse = acsClient.GetAcsResponse(request);
                //发送成功判断
                if ("OK".Equals(sendSmsResponse.Code, StringComparison.CurrentCultureIgnoreCase))
                {
                    result.Success = true;
                }
                else
                {
                    result.Success      = false;
                    result.ErrorMessage = sendSmsResponse.Message;
                }
            }
            catch (ClientException e)
            {
                AliyunSmsHelper.LoggerAction("Error", e.ToString());
                result.Success      = false;
                result.ErrorMessage = e.ErrorMessage;
            }
            catch (Exception e)
            {
                AliyunSmsHelper.LoggerAction("Error", e.ToString());
                result.Success      = false;
                result.ErrorMessage = e.Message;
            }
            return(Task.FromResult(result));
        }
 /// <summary>
 ///     发送模板消息
 /// </summary>
 /// <param name="message"></param>
 /// <returns></returns>
 public async Task <SmsResult> SendTemplateMessageAsync(SendTemplateMessageInput input)
 {
     return(await SmsService.SendTemplateMessageAsync(input));
 }
 /// <summary>
 ///     发送模板消息
 /// </summary>
 /// <param name="message"></param>
 /// <returns></returns>
 public Task <SendResult> SendTemplateMessageAsync(SendTemplateMessageInput message)
 {
     throw new NotImplementedException();
 }