Beispiel #1
0
        public async Task <HuyiResult> SendAsync(HuyiMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }
            if (string.IsNullOrWhiteSpace(_account.ApiKey))
            {
                throw new ArgumentNullException(nameof(_account.ApiKey));
            }
            if (string.IsNullOrWhiteSpace(_account.AppId))
            {
                throw new ArgumentNullException(nameof(_account.AppId));
            }

            message.CheckParameters();

            var bizParams = new Dictionary <string, string>();

            bizParams.Add("account", _account.AppId);
            bizParams.Add("password", _account.ApiKey);
            bizParams.Add("mobile", message.PhoneNumber);
            bizParams.Add("content", message.Message);
            bizParams.Add("format", "json");

            var content = new FormUrlEncodedContent(bizParams);

            return(await _proxy.SendAsync(content)
                   .Retry(_config.RetryTimes)
                   .Handle().WhenCatch <Exception>(e =>
            {
                _exceptionHandler?.Invoke(e);
                return ReturnAsDefautlResponse();
            }));
        }
Beispiel #2
0
        public async void SendCodeTest()
        {
            var message = new HuyiMessage {
                PhoneNumber = "",
                Message     = "您的验证码是:12345。请不要把验证码泄露给其他人。"
            };

            var response = await _client.SendAsync(message);

            Assert.NotNull(response);
            Assert.True(response.Code == 2, $"{JsonConvert.SerializeObject(response)},{_messageIfError}");
            //Assert.True(string.IsNullOrWhiteSpace(response), response);
        }