Example #1
0
        /// <summary>
        ///     发送单条 使用异步方法发送短信
        /// </summary>
        /// <param name="queue"></param>
        private ServiceResult SendRawAsync(MessageQueue queue)
        {
            if (string.IsNullOrWhiteSpace(queue.Mobile))
            {
                throw new ArgumentNullException(nameof(queue.Mobile));
            }

            if (string.IsNullOrWhiteSpace(queue.Content))
            {
                throw new ArgumentNullException(nameof(queue.Content));
            }

            RegexHelper.CheckMobile(queue.Mobile);

            var result = Ioc.Resolve <ISmsService>().SendRaw(queue.Mobile, queue.Content);

            return(result);
        }
Example #2
0
        private async Task <MessageResult> SendTemplateAsync(MessageQueue queue)
        {
            if (string.IsNullOrWhiteSpace(queue.Mobile))
            {
                throw new ArgumentNullException(nameof(queue.Mobile));
            }

            if (queue.TemplateCode <= 0)
            {
                throw new ArgumentNullException(nameof(queue.TemplateCode));
            }

            var template = GetTemplate(queue.TemplateCode);

            if (template == null)
            {
                throw new ArgumentNullException(nameof(template));
            }

            if (template.Status != MessageTemplateStatus.Verified)
            {
                throw new ArgumentNullException(nameof(template));
            }

            RegexHelper.CheckMobile(queue.Mobile);
            var parameters = JsonConvert.DeserializeObject <IDictionary <string, string> >(queue.Parameters);
            var result     = await _messageApiClient.SendTemplateAsync(Token.Token,
                                                                       queue.Mobile, template.Id, queue.IpAdress, parameters);

            if (result.Status != ResultStatus.Success)
            {
                throw new ServerApiException(result.Status, result.MessageCode, result.Message);
            }

            return(ParseResult(result));
        }
Example #3
0
        /// <summary>
        ///     发送单条 使用异步方法发送短信
        /// </summary>
        /// <param name="queue"></param>
        private async Task <MessageResult> SendRawAsync(MessageQueue queue)
        {
            if (string.IsNullOrWhiteSpace(queue.Mobile))
            {
                throw new ArgumentNullException(nameof(queue.Mobile));
            }

            if (string.IsNullOrWhiteSpace(queue.Content))
            {
                throw new ArgumentNullException(nameof(queue.Content));
            }

            RegexHelper.CheckMobile(queue.Mobile);
            var result = await _messageApiClient.SendRawAsync(Token.Token,
                                                              queue.Mobile,
                                                              queue.Content, queue.IpAdress);

            if (result.Status != ResultStatus.Success)
            {
                throw new ServerApiException(result.Status, result.MessageCode, result.Message);
            }

            return(ParseResult(result));
        }