/// <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); } }
public bool Send2(string phoneNum, List <string> content, int tmplId = 0) { string accessKeyId = "LTAI4FxGHAc7TgPndH9gF21g"; string accessKeySecret = "SG2DN4aMWCsmTDoiE595Oz0JzZ8itE"; IDictionary <string, string> data = new Dictionary <string, string>(); data.Add("Code", content[0]); var sms = new SmsObject { Mobile = phoneNum, Signature = "LTAIBgdZ9URrwgz3", TempletKey = "SMS_162197307", Data = data, //OutId = "OutId" }; var res = new AliyunSmsSender(accessKeyId, accessKeySecret).Send(sms).Result; return(true); }