public async Task <AliyunDysmsResult> SendCodeAsync(AliyunDysmsCode code) { if (code == null) { throw new ArgumentNullException(nameof(code)); } if (string.IsNullOrWhiteSpace(_aliyunDysmsAccount.AccessKeyId)) { throw new ArgumentNullException(nameof(_aliyunDysmsAccount.AccessKeyId)); } if (string.IsNullOrWhiteSpace(_aliyunDysmsAccount.AccessKeySecret)) { throw new ArgumentNullException(nameof(_aliyunDysmsAccount.AccessKeySecret)); } if (string.IsNullOrWhiteSpace(_config.SignName)) { throw new ArgumentNullException(nameof(_config.SignName)); } code.FixParameters(_config); code.CheckParameters(); var bizParams = new Dictionary <string, string> { { "RegionId", "cn-hangzhou" }, { "Action", "SendSms" }, { "Version", "2017-05-25" }, { "AccessKeyId", _aliyunDysmsAccount.AccessKeyId }, { "PhoneNumbers", code.GetPhoneString() }, { "SignName", _config.SignName }, { "TemplateCode", code.TemplateCode }, { "TemplateParam", code.GetTemplateParamsString() }, { "SignatureMethod", "HMAC-SHA1" }, { "SignatureNonce", Guid.NewGuid().ToString() }, { "SignatureVersion", "1.0" }, { "Timestamp", DateTime.Now.ToIso8601DateString() }, { "Format", "JSON" } }; if (!string.IsNullOrWhiteSpace(code.OutId)) { bizParams.Add("OutId", code.OutId); } var signature = SignatureHelper.GetApiSignature(bizParams, _aliyunDysmsAccount.AccessKeySecret); bizParams.Add("Signature", signature); var content = new FormUrlEncodedContent(bizParams); return(await _proxy.SendCodeAsync(content) .Retry(_config.RetryTimes) .Handle() .WhenCatch <Exception>(e => { _exceptionHandler?.Invoke(e); return ReturnAsDefautlResponse(); })); }
public async void SendCodeTest() { var code = new AliyunDysmsCode { TemplateCode = "", Phone = new List <string> { "" }, Code = "311920" }; var response = await _client.SendCodeAsync(code); Assert.NotNull(response); Assert.True(response.IsSuccess(), $"{JsonConvert.SerializeObject(response)},{_messageIfError}"); //Assert.True(string.IsNullOrWhiteSpace(response), response); }