/// <summary> /// 发送短信 /// </summary> public async Task <(bool success, string response)> Send(SmsObject sms) { var paramers = new Dictionary <string, string>(); paramers.Add("PhoneNumbers", sms.Mobile); paramers.Add("SignName", sms.Signature); paramers.Add("TemplateCode", sms.TempletKey); paramers.Add("TemplateParam", JsonConvert.SerializeObject(sms.Data)); paramers.Add("OutId", sms.OutId); paramers.Add("AccessKeyId", AccessKeyId); try { string url = GetSignUrl(paramers, AccessKeySecret); int retryTimes = 1; var reply = await HttpGetAsync(url); while (500 <= reply.StatusCode && AutoRetry && retryTimes < MaxRetryNumber) { url = GetSignUrl(paramers, AccessKeySecret); reply = await HttpGetAsync(url); retryTimes++; } if (!string.IsNullOrEmpty(reply.response)) { var res = JsonConvert.DeserializeObject <Dictionary <string, string> >(reply.response); if (res != null && res.ContainsKey("Code") && "OK".Equals(res["Code"])) { return(true, response : reply.response); } } return(false, response : reply.response); } catch (Exception ex) { return(false, response : ex.Message); } }
/// <summary> /// 发送短信验证码 /// </summary> /// <returns></returns> public async Task <(bool success, string response)> SendSmsCode(string phone, string code) { try { IDictionary <string, string> data = new Dictionary <string, string>(); data.Add("code", code); var sms = new SmsObject { Mobile = phone, Signature = Configuration.GetItem("Aliyun_SmsSignature"), TempletKey = Configuration.GetItem("Aliyun_SmsTempletKey"), Data = data, OutId = "OutId" }; return(await new AliyunSms(Configuration.GetItem("Aliyun_AccessKeyId"), Configuration.GetItem("Aliyun_AccessKeySecret")).Send(sms)); } catch { return(false, response : ""); } }