/// <summary> /// Sends the specified short code. /// </summary> /// <param name="shortCode">The short code.</param> /// <param name="accessToken">The access token.</param> /// <param name="payload">The payload.</param> /// <returns></returns> public SmsResult Send(string shortCode, string accessToken, SmsPayload payload) { string url = string.Format(Config.SMS_ENDPOINT, Config.API_VERSION, shortCode, accessToken); var dict = new Dictionary<string, object>(); dict.Add("senderAddress", shortCode); dict.Add("outboundSMSTextMessage", new { message = payload.Message }); dict.Add("address", payload.Numbers); var payloadObject = new { outboundSMSMessageRequest = dict }; string jsonData = JsonConvert.SerializeObject(payloadObject); var result = new SmsResult(); string data = this.Post(url, Config.CONTENT_TYPE_JSON, jsonData); if (data.Contains(Config.ERROR)) { var jsonResponse = JsonConvert.DeserializeObject<ErrorResponse>(data); result.Result = null; result.Status = this.ResponseStatus; result.Status.StatusDescription = jsonResponse.Error; result.Status.StatusCode = (int)HttpStatusCode.BadRequest; } else { var jsonSms = string.IsNullOrEmpty(data) ? null : JsonConvert.DeserializeObject<SmsResponse>(data); result.Result = jsonSms; result.Status = this.ResponseStatus; } return result; }
/// <summary> /// 发送一条短信 /// 调用网关发送短信(不保存到数据库) /// </summary> /// <param name="sysNo">后台管理员编号</param> /// <param name="msg">70字(包含签名)一条短信,超出则按此规则分割成多条短信</param> /// <param name="sendTime">定时发送(精确到秒),为空不需要定时</param> /// <returns>返回受影响行数</returns> /// <remarks> /// 2014-10-03 余勇 创建 /// </remarks> public SmsResult Send(int sysNo, string msg, DateTime?sendTime) { var user = Hyt.BLL.Sys.SyUserBo.Instance.GetSyUser(sysNo); var result = new SmsResult { Status = SmsResultStatus.Success }; if (user != null && !string.IsNullOrEmpty(user.MobilePhoneNumber) && !string.IsNullOrEmpty(msg) && VHelper.ValidatorRule(new Rule_Mobile(user.MobilePhoneNumber)).IsPass && user.MobilePhoneNumber.Length >= 11) { System.Threading.Tasks.Task.Factory.StartNew(() => { try { result = SmsProviderFactory.CreateProvider().Send(user.MobilePhoneNumber, msg + "【】", sendTime); SysLog.Instance.Info(LogStatus.系统日志来源.后台, msg + "(" + user.MobilePhoneNumber + ")", LogStatus.系统日志目标类型.短信咨询, 0, null, "", 0); } catch (Exception ex) { Hyt.BLL.Log.SysLog.Instance.Error(Model.WorkflowStatus.LogStatus.系统日志来源.外部应用, "短信发送异常", ex); } }); } else { return(new SmsResult { RowCount = 0, Status = SmsResultStatus.Failue }); } return(result); }
private async Task UpdateAsync(string to, SmsResult result, UserNotification notification) { if (!notification.Channels.TryGetValue(Name, out var channel)) { return; } if (channel.Status.TryGetValue(to, out var status) && status.Status == ProcessStatus.Attempt) { switch (result) { case SmsResult.Delivered: await UpdateAsync(notification, to, ProcessStatus.Handled); break; case SmsResult.Failed: await UpdateAsync(notification, to, ProcessStatus.Failed); break; } } }
/// <summary> /// 删除短信模板。 /// </summary> /// <param name="input"></param> /// <returns></returns> public Task <SmsResult> DeleteSmsTemplateAsync(DeleteSmsTemplateInput input) { var client = new AliyunSmsClient(); var acsClient = client.AcsClient; var request = new DeleteSmsTemplateRequest(); var result = new SmsResult(); try { request.TemplateCode = input.TemplateCode; //请求失败这里会抛ClientException异常 var DeleteSmsTemplateResponse = acsClient.GetAcsResponse(request); //发送成功判断 if ("OK".Equals(DeleteSmsTemplateResponse.Code, StringComparison.CurrentCultureIgnoreCase)) { result.Success = true; } else { result.Success = false; result.ErrorMessage = DeleteSmsTemplateResponse.Message; } } catch (ClientException e) { AliyunSmsHelper.LoggerAction("Error", e.ToString()); result.Success = false; result.ErrorMessage = e.ErrorMessage; } catch (Exception e) { AliyunSmsHelper.LoggerAction("Error", e.ToString()); result.Success = false; result.ErrorMessage = e.Message; } return(Task.FromResult(result)); }
/// <summary> /// 发送一条短信 /// 先调用网关发送短信,然后将短信记录到数据库,如果发送失败,则由后台进程重发。 /// </summary> /// <param name="mobile">号码</param> /// <param name="msg">70字(包含签名)一条短信,超出则按此规则分割成多条短信</param> /// <param name="sendTime">定时发送(精确到秒),为空不需要定时</param> /// <returns>返回受影响行数</returns> /// <remarks> /// 2013-02-26 罗雄伟 创建 /// 2014-07-30 黄波 修改 将短信发送放在TASK中执行 /// </remarks> private SmsResult Send(string mobile, string msg, DateTime?sendTime) { var user = Hyt.BLL.CRM.CrCustomerBo.Instance.GetCrCustomer(mobile); if (user != null && user.IsReceiveShortMessage == (int)Hyt.Model.WorkflowStatus.CustomerStatus.是否接收短信.否) { return new SmsResult { RowCount = 0, Status = SmsResultStatus.Failue } } ; var result = new SmsResult { Status = SmsResultStatus.Success }; //添加判断是否为手机号 余勇 2014-06-18 if (!string.IsNullOrEmpty(mobile) && !string.IsNullOrEmpty(msg) && VHelper.ValidatorRule(new Rule_Mobile(mobile)).IsPass&& mobile.Length >= 11) { System.Threading.Tasks.Task.Factory.StartNew(() => { try { result = SmsProviderFactory.CreateProvider().Send(mobile, msg, sendTime); SaveToDb(mobile, msg, result); } catch (Exception ex) { Hyt.BLL.Log.SysLog.Instance.Error(Model.WorkflowStatus.LogStatus.系统日志来源.外部应用, "短信发送异常", ex); } }); } return(result); }
/// <summary> /// 指令结果解析适配器. /// </summary> /// <param name="Msg">指令结果集合.</param> /// <returns></returns> protected override ASyncResult ResultAdapter(string Msg) { SmsResult Result = new SmsResult(); Result.Success = Regex.IsMatch(Msg, @"OK", RegexOptions.IgnoreCase | RegexOptions.Multiline); return Result; }
public SmsResult Send(string mobile, string msg, DateTime?sendTime, string smsTemplateCode) { var smsResult = new SmsResult(); string smsModelName = ""; string smsModelId = ""; string smsParams = ""; switch (smsModelName) { case "用户注册验证码": smsModelId = "SMS_7456196"; // 用户注册验证码 smsParams = "{\"code\":\"code\",\"product\":\"product\"}"; // 验证码${code},您正在注册成为${product}用户,感谢您的支持! break; case "身份验证验证码": smsModelId = "SMS_7456200"; // 身份验证验证码 smsParams = "{\"code\":\"code\",\"product\":\"product\"}"; // 验证码${code},您正在进行${product}身份验证,打死不要告诉别人哦! break; case "修改密码验证码": smsModelId = "SMS_7456194"; // 修改密码验证码 smsParams = "{\"code\":\"code\",\"product\":\"product\"}"; // 验证码${code},您正在尝试修改${product}登录密码,请妥善保管账户信息。 break; } if (smsModelId == "" || smsParams == "") { smsResult.Status = SmsResultStatus.Failue; smsResult.RowCount = 0; return(smsResult); } //alibaba.aliqin.fc.sms.num.send //http://gw.api.taobao.com/router/rest string method = "alibaba.aliqin.fc.sms.num.send"; string result = ""; Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("method", method); parameters.Add("app_key", AppKey); parameters.Add("timestamp", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); parameters.Add("format", "json"); parameters.Add("v", "2.0"); parameters.Add("sign_method", "md5"); parameters.Add("sms_type", "normal"); parameters.Add("sms_free_sign_name", "爱勤全球购"); parameters.Add("sms_param", "{\"customer\":\"chen\"}"); parameters.Add("rec_num", mobile); parameters.Add("sms_template_code", smsTemplateCode); parameters.Add("sign", ComputeSignature(parameters)); string tempStr = ""; foreach (var i in parameters) { tempStr += i.Key + "=" + i.Value + "&"; } if (tempStr.Length > 0) { tempStr = tempStr.Substring(0, tempStr.Length - 1); } UTF8Encoding encoding = new UTF8Encoding(); byte[] postData = encoding.GetBytes(tempStr); result = PostRequest("http://gw.api.taobao.com/router/rest", postData); var _result = JObject.Parse(result); if (_result.Property(method) != null && _result[method]["result"]["success"].ToString() == "True") { smsResult.Status = SmsResultStatus.Success; smsResult.RowCount = 1; return(smsResult); } else { smsResult.Status = SmsResultStatus.Failue; smsResult.RowCount = 0; return(smsResult); } }
/// <summary> /// 发送短信 /// </summary> /// <param name="mobile">手机号(13811290000;15210950000)</param> /// <param name="msg">消息</param> /// <param name="sendTime">定时</param> /// <returns>执行结果</returns> public SmsResult Send(string mobile, string msg, DateTime?sendTime) { var smsResult = new SmsResult(); return(smsResult); }
public override SmsResult Send(string content, string number) { SmsResult smsResult = SmsResult.未知错误; try { Encoding encoding = Encoding.UTF8; var wc = new WebClient(); wc.Encoding = encoding; int contentIndex = 0; int limitedLetterCount = 65 * 4; //组装消息,判断内容长度,太长则分开发 List <string> messageList = new List <string>(); while (contentIndex < content.Length) { string limitedContent = content.Substring(contentIndex, Math.Min(limitedLetterCount, content.Length - contentIndex)); messageList.Add(limitedContent); contentIndex += limitedLetterCount; } //分批发送 for (int i = 0; i < messageList.Count; i++) { var msg = messageList[i]; if (messageList.Count > 1) { msg = $" [{i + 1}/{messageList.Count}]" + msg; } //msg += "【盛派网络】"; string encodedLimitedConent = UrlEncode(msg, encoding); var url = string.Format("{0}/SMSSend?OperId={1}&OperPass={2}&Mobiles={3}&Message={4}", SmsServiceAddress, Setting.SmsAccountCORPID, Setting.SmsAccountPassword, number, encodedLimitedConent); var smsState = wc.DownloadString(url); var fissosoft_SendResult = Newtonsoft.Json.JsonConvert.DeserializeObject <Fissosoft_SendResult>(smsState); if (fissosoft_SendResult.Code == 1) { smsResult = SmsResult.成功; } else { if (!Enum.TryParse(fissosoft_SendResult.Code.ToString(), out smsResult)) { smsResult = SmsResult.未知错误; } } Log.LogUtility.SmsLogger.Info($"发送短信成功:{content},号码:{number}。状态:{smsResult.ToString()}。发送通道:Fissoft"); Thread.Sleep(200); } } catch { Log.LogUtility.SmsLogger.Error($"发送短信失败:{content},号码:{number}。发送通道:Fissoft"); } finally { } return(smsResult); }
/// <summary> /// 作者:Ark /// 时间:2014.08.05 /// 描述:短信发送 /// </summary> /// <param name="smsList">短信列表信息</param> /// <returns></returns> public SmsResult Send(List<SmsModel> smsList) { SmsResult smsRet = new SmsResult(); // 转为json字符串 string jsonSms = JsonHelper.ToJson(smsList); //try //{ // // 实例化服务 // APIServiceClient client = new APIServiceClient(); // // 调用发送短信,返回结果为json字符串 // string ret = client.(jsonSms); // smsRet = JsonHelper.FromJson<SmsResult>(ret); // // 关闭 // client.Close(); //} //catch (Exception ex) //{ // smsRet.Code = 101; // smsRet.Msg = "调用SmsForEme服务异常,请联系管理员!"; //} //2015-1-15号换成直接调用供应商(亿美)接口进行短信发送 SmsToEme.SDKClientClient client = new SDKClientClient(); foreach (var item in smsList) { try { var content = item.Message; List<string> mobiles = new List<string>() { item.Mobile }; var serial = item.Serial; var smsId = item.SmsId; //var mresult = new MobileResult(); int result = client.sendSMS(SerialNo, SoftwareKey, "", mobiles.ToArray(), content, serial, "GBK", 5, smsId); //记录日志 //Common.Log4Helper.WriteLog("mobile:"+mobiles.ToString()+",content:"+content+",senttime:"+DateTime.Now+",resutl:"+result); if (result == 0) { smsRet.Count += 1; smsRet.Code = result; smsRet.Msg = GetErrMsgByCode(result); } } catch (Exception ex) { smsRet.Code = 101; smsRet.Msg = "调用SmsToEme服务异常,请联系管理员!"; } } client.Close(); return smsRet; }
/// <summary> /// Sets message result to spacified message /// </summary> public void SetMessageResult(SmsResult result) { SmsMessageDao.Instance.SetMessageResult(result); }
public void Defaults() { var sms = new SmsResult(); Assert.Equal(UserCommandType.Unknown, sms.UserCommand); }