Exemple #1
0
        public async void SendMessageTest()
        {
            var message = new WeimiSmsMessage {
                PhoneNumbers = new List <string> {
                    ""
                },
                Content = "无名英雄"
            };

            var response = await _client.SendAsync(message);

            Assert.NotNull(response);
            Assert.True(response.IsSuccess(), $"{JsonConvert.SerializeObject(response)},{_messageIfError}");
        }
Exemple #2
0
        public async Task <WeimiSmsResult> SendAsync(WeimiSmsMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }
            if (string.IsNullOrWhiteSpace(_weimiSmsAccount.Uid))
            {
                throw new ArgumentNullException(nameof(_weimiSmsAccount.Uid));
            }
            if (string.IsNullOrWhiteSpace(_weimiSmsAccount.Pas))
            {
                throw new ArgumentNullException(nameof(_weimiSmsAccount.Pas));
            }

            message.CheckParameters();

            var bizParams = new Dictionary <string, string> {
                { "uid", _weimiSmsAccount.Uid },
                { "pas", _weimiSmsAccount.Pas },
                { "mob", message.GetPhoneString() },
                { "con", message.Content },
                { "type", "json" }
            };

            if (!string.IsNullOrWhiteSpace(message.Timing))
            {
                bizParams.Add("timing", message.Timing);
            }

            var content = new FormUrlEncodedContent(bizParams);

            return(await _proxy.SendMessageAsync(content)
                   .Retry(_config.RetryTimes)
                   .Handle().WhenCatch <Exception>(e =>
            {
                _exceptionHandler?.Invoke(e);
                return ReturnAsDefaultResponse();
            }));
        }