/// <summary> /// 发送验证码 /// </summary> public bool SendVerificationCode(string VerificationCode, string phoneNumber) { // 短信模板ID,需要在短信应用中申请 int templateId = 170466; try { SmsSingleSender ssender = new SmsSingleSender(appid, appkey); var result = ssender.sendWithParam("86", phoneNumber, templateId, new[] { VerificationCode }, "", "", ""); if (result.result == 0) { return(true); } else { return(false); } } catch (JSONException e) { RCLog.Error(this, e.ToString()); } catch (HTTPException e) { RCLog.Error(this, e.ToString()); } catch (Exception e) { RCLog.Error(this, e.ToString()); } return(false); }
public Task <SmsSingleSenderResult> SendVerifySMSAsync(string phoneNumber, int templateId, string[] parameters, VerifyType type) { return(Task.Run(() => { try { SmsSingleSender ssender = new SmsSingleSender(_appId, _appKey); var result = ssender.sendWithParam("86", phoneNumber, templateId, parameters, _sign, "", ""); // 签名参数未提供或者为空时,会使用默认签名发送短信 _applicationDbContext.SMSVerifyRecord.Add(new Models.SMSVerifyRecord() { Sid = result.sid, PhoneNumber = phoneNumber, Code = parameters?[0], Deadline = DateTime.Now.AddMinutes(Convert.ToDouble(parameters?[1])), Type = type }); _applicationDbContext.SaveChanges(); return result; } catch (Exception ex) { return new SmsSingleSenderResult() { result = -1, errMsg = ex.InnerException.Message }; } })); }
public Task SendSmsAsync(string number, string message) { int appid = _smsSenderOptions.AppId; string appkey = _smsSenderOptions.AppKey; var phoneNumbers = new string[] { number }; int templateId = _smsSenderOptions.TemplateId; string smsSign = _smsSenderOptions.SmsSign; // 签名的参数(codepie) try { // 签名参数未提供或者为空时,会使用默认签名发送短信 var ssender = new SmsSingleSender(appid, appkey); SmsSingleSenderResult result = ssender.sendWithParam("86", phoneNumbers[0], templateId, new[] { "5678", "tes-.-" }, smsSign, "", ""); } catch (JSONException e) { Console.WriteLine(e); } catch (HTTPException e) { Console.WriteLine(e); } catch (Exception e) { Console.WriteLine(e); } return(Task.CompletedTask); }
/// <summary> /// 发送通知短信 /// </summary> /// <param name="phoneNumber"></param> /// <param name="templateNumber"></param> /// <param name="param"></param> /// <returns></returns> private bool SmsSend(string phoneNumber, int templateNumber, string[] param) { bool res = false; try { SmsSingleSender ssender = new SmsSingleSender(appid, appkey); var result = ssender.sendWithParam("86", phoneNumber, templateId[templateNumber], param, smsSign, "", ""); // 签名参数未提供或者为空时,会使用默认签名发送短信 res = true; } catch (JSONException e) { ShowMsg(e.ToString()); //MessageBox.Show(e.ToString()); } catch (HTTPException e) { ShowMsg(e.ToString()); //MessageBox.Show(e.ToString()); } catch (Exception e) { ShowMsg(e.ToString()); //MessageBox.Show(e.ToString()); } return res; }
public bool SendCode(string phone, int templateId, string[] paramters) { SmsSingleSender ssender = new SmsSingleSender(this.appId, this.appKey); var result = ssender.sendWithParam("86", phone, templateId, paramters, null, "", ""); // 签名参数未提供或者为空时,会使用默认签名发送短信 return(result.result == 0); }
//string pwd = System.Configuration.ConfigurationManager.AppSettings["Pwd"]; public SmsSingleSenderResult SmsSingleSenderFunc(MsgParam msgParam) { try { SmsSingleSender ssender = new SmsSingleSender(msgParam.appid, msgParam.appkey); var result = ssender.sendWithParam("86", msgParam.phoneNumbers[0], msgParam.templateId, new[] { "5678" }, msgParam.smsSign, "", ""); // 签名参数不能为空串 return(result); } catch (JSONException e) { return(new SmsSingleSenderResult() { result = 0, errMsg = e.Message }); } catch (HTTPException e) { return(new SmsSingleSenderResult() { result = 0, errMsg = e.Message }); } catch (Exception e) { return(new SmsSingleSenderResult() { result = 0, errMsg = e.Message }); } }
public ActionResult SendCode(string phone) { Random num = new Random(); int code = num.Next(1000, 9999); phonecode codeModel = entity.phonecode.FirstOrDefault(p => p.phone == phone); if (codeModel == null) { phonecode newCodeModel = new phonecode() { code = code.ToString(), phone = phone, sys_datetime = DateTime.Now, }; entity.phonecode.Add(newCodeModel); } else { codeModel.code = code.ToString(); } SmsSingleSender ssender = new SmsSingleSender(1400078324, "b6bcf068fb3ef4b611833bffb0181aaa"); var result = ssender.sendWithParam("86", phone, 100278, new[] { code.ToString(), "10" }, null, "", ""); // 签名参数未提供或者为空时,会使用默认签名发送短信 Console.WriteLine(result); return(Json(entity.SaveChanges() > 0, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 发送短息 /// </summary> /// <param name="phoneNumber">手机号码</param> /// <param name="templateId">模板编号</param> /// <param name="parameters">参数</param> /// <param name="sign">验证(选填参数)</param> /// <param name="extend">扩展(选填参数)</param> /// <param name="ext">说明(选填参数)</param> /// <returns></returns> public dynamic sendWithParam(string phoneNumber, int templateId, string[] parameters, string sign, string extend, string ext) { SmsSingleSender ssender = new SmsSingleSender(int.Parse(base.appid), base.appkey); var result = ssender.sendWithParam("86", phoneNumber, templateId, parameters, "", "", ""); // 签名参数未提供或者为空时,会使用默认签名发送短信 return(result); }
/// <summary> /// 指定模板发送单条信息 /// </summary> /// <param name="MsgType">短信类型</param> /// <param name="MsgContent">短信内容</param> /// <param name="phoneNumbers">发送号码</param> public static string SendSmsHaveTemplateForOne(SmsMsgType MsgType, string MsgContent, string[] phoneNumbers) { try { SmsSingleSender ssender = new SmsSingleSender(appid, appkey); var result = ssender.sendWithParam("86", phoneNumbers[0], (int)MsgType, new[] { MsgContent }, smsSign, "", ""); return(result.ToString()); } catch (Exception e) { throw e; } }
public async Task SendSmsAsync(string phoneNumber, int templateCode, string[] messages) { var result = await Task.Run(() => _singleSender.sendWithParam(NATION_CODE, phoneNumber, templateCode, messages, _options.Signature, QCLOUD_EXTEND_CODE, QCLOUD_EXT)); if (result.result != 0) { throw new SmsException(result.errMsg); } }
public static Tuple <string, string, int> SendSms(string phone) { Random rad = new Random(); int value = rad.Next(1000, 10000); string code = value.ToString(); int appId = Convert.ToInt32(ConfigurationManager.AppSettings["appId"]); string appKey = ConfigurationManager.AppSettings["appKey"].ToString(); int templateId = Convert.ToInt32(ConfigurationManager.AppSettings["templateId"].ToString()); string smsTimeOut = ConfigurationManager.AppSettings["smsTimeOut"].ToString(); SmsSingleSender ssender = new SmsSingleSender(appId, appKey); var result = ssender.sendWithParam("86", phone, templateId, new[] { code, smsTimeOut }, "", "", ""); return(Tuple.Create(code, result.errMsg, result.result)); }
public static void SendVerifyCode(string phoneNum) { var random = new Random(); var verifyCode = random.Next(0, 9999).ToString("0000"); if (_records.ContainsKey(phoneNum)) { _records[phoneNum] = new VerifyRecord { VerifyCode = verifyCode, ValidThrough = DateTime.Now.AddMinutes(5) }; } else { _records.Add(phoneNum, new VerifyRecord { VerifyCode = verifyCode, ValidThrough = DateTime.Now.AddMinutes(5) }); } try { SmsSingleSender ssender = new SmsSingleSender(appid, appkey); SmsService.Sms(phoneNum, verifyCode); var results = ssender.sendWithParam("86", phoneNum, templateId, new[] { verifyCode, "5" }, smsSign, "", "");// 签名参数未提供或者为空时,会使用默认签名发送短信 Console.WriteLine(results); } catch (JSONException e) { Console.WriteLine(e); } catch (HTTPException e) { Console.WriteLine(e); } catch (Exception e) { Console.WriteLine(e); } }
public void TestMessage() { // 短信应用 SDK AppID int appid = 1400268227; // 短信应用 SDK AppKey string appkey = "c1d2cbfb30b5df4e8f0f4be3bd905964"; // 需要发送短信的手机号码 string[] phoneNumbers = { "21212313123", "12345678902", "12345678903" }; // 短信模板 ID,需要在短信控制台中申请 int templateId = 440141; // NOTE: 这里的模板 ID`7839`只是示例,真实的模板 ID 需要在短信控制台中申请 // 签名 string smsSign = "网医智捷"; // NOTE: 签名参数使用的是`签名内容`,而不是`签名ID`。这里的签名"腾讯云"只是示例,真实的签名需要在短信控制台申请 SmsSingleSender ssender = new SmsSingleSender(appid, appkey); var result = ssender.sendWithParam("86", "18942561085", templateId, new[] { "5678", "3" }, smsSign, "", ""); Console.WriteLine(result); }
/// <summary> /// 短信单发 /// </summary> /// <param name="phoneNumber">手机号</param> /// <param name="templateId">短信模板ID,腾讯云后台查询</param> /// <param name="msgParams">短信模板变量一次对应的值</param> /// <returns></returns> private static SmsSingleSenderResult SingleSend(string phoneNumber, int templateId, string[] msgParams) { SmsSingleSenderResult result; try { SmsSingleSender ssender = new SmsSingleSender(appid, appkey); result = ssender.sendWithParam("86", phoneNumber, templateId, msgParams, "", "", ""); } catch (Exception ex) { result = new SmsSingleSenderResult() { result = -1, errMsg = ex.Message }; } return(result); }
/// <summary> /// 发送验证码 /// </summary> /// <param name="context"></param> /// <param name="phoneNumber"></param> /// <returns></returns> public bool SendVerificationCode2(string[] context, string phoneNumber) { var template = GetSMSAppTemplate(SMSTemplateType.verification); try { SmsSingleSender ssender = new SmsSingleSender(Convert.ToInt32(template.Appid), template.Appkey); var result = ssender.sendWithParam("86", phoneNumber, Convert.ToInt32(template.TemplateId), context, "", "", ""); Console.WriteLine(result); var lastSendSMSLogs = _context.SendSMSLogs.Where(x => x.Year == DateTime.Now.Year && x.Month == DateTime.Now.Month).OrderByDescending(x => x.CreateTime).FirstOrDefault(); SendSMSLog log = new SendSMSLog() { Appid = template.Appid, SMSAppTemplateId = template.TemplateId, Month = DateTime.Now.Month, Year = DateTime.Now.Year, Content = string.Join(",", context), phoneNumbers = phoneNumber, QuantityBeforeSend = lastSendSMSLogs == null ? 0 : lastSendSMSLogs.QuantityAfterSend, QuantityAfterSend = lastSendSMSLogs == null ? 1 : lastSendSMSLogs.QuantityAfterSend + 1, CreateTime = DateTime.Now }; _context.Add(log); _context.SaveChanges(); return(true); } catch (JSONException e) { RCLog.Error(this, e.ToString()); } catch (HTTPException e) { RCLog.Error(this, e.ToString()); } catch (Exception e) { RCLog.Error(this, e.ToString()); } return(false); }
public int Send(string phone, string Content, SMSType type) { #if !FB return(0); #endif SmsSingleSenderResult result = null; try { resultMsg = ""; SmsSingleSender ssender = new SmsSingleSender(appid, appkey); result = ssender.sendWithParam("86", phone, 289735, new[] { Content }, "单身狗APP", "", ""); // 签名参数未提供或者为空时,会使用默认签名发送短信 Console.WriteLine(result); resultMsg = Newtonsoft.Json.JsonConvert.SerializeObject(result); } catch (JSONException e) { resultMsg = e.Message; Console.WriteLine(e); return(1); } catch (HTTPException e) { resultMsg = e.Message; Console.WriteLine(e); return(1); } catch (Exception e) { resultMsg = e.Message; Console.WriteLine(e); return(1); } if (result.result != 0) { resultMsg = result.errMsg; return(1); } return(0); }
/// <summary> /// 发送手机验证码 /// </summary> /// <param name="code">前端生成的验证码</param> /// <param name="phoNum">发送的手机号</param> /// <returns>发送结果</returns> public string MobileMsg(string code, string phoNum) { //短信应用SDK AppID int appid = 1400187647; //短信应用SDK AppKey string appkey = "225561ebc612eb400a62819edd1f192e"; //需要发送短信的手机号码 string[] phoneNumbers = { phoNum }; //短信模板ID,需要在短信应用中申请 int templateId = 281441; //签名 string smsSign = "郑兴豪个人开发测试"; //发送短信 try { SmsSingleSender ssender = new SmsSingleSender(appid, appkey); var info = ssender.sendWithParam("86", phoneNumbers[0], templateId, new[] { code, "30" }, smsSign, "", ""); string result = info.errMsg; //返回结果 return(result); } catch (JSONException e) { throw e; } catch (HTTPException e) { throw e; } catch (Exception e) { throw e; } }
private void SendMessage(int type, string phoneNumber) { // 短信应用SDK AppID int appid = 122333333; // 短信应用SDK AppKey string appkey = "9ff91d87c2cd7cd0ea762f141975d1df37481d48700d70ac37470aefc60f9bad"; // 短信模板ID,需要在短信应用中申请 int templateId = 7839; // NOTE: 这里的模板ID`7839`只是一个示例,真实的模板ID需要在短信控制台中申请 // 签名 string smsSign = "腾讯云"; // NOTE: 这里的签名只是示例,请使用真实的已申请的签名, 签名参数使用的是`签名内容`,而不是`签名ID` Random random = new Random(); string valCode = random.Next(1000, 9999) + ""; Session["valicode" + phoneNumber] = valCode; try { SmsSingleSender ssender = new SmsSingleSender(appid, appkey); var result = ssender.sendWithParam("86", phoneNumber, templateId, new[] { valCode }, smsSign, "", ""); // 签名参数未提供或者为空时,会使用默认签名发送短信 Response.Write(result); } catch (JSONException e) { Console.WriteLine(e); } catch (HTTPException e) { Console.WriteLine(e); } catch (Exception e) { Console.WriteLine(e); } }
public static void SendSMSUseTencentAPI() { // 短信应用SDK AppID int appid = 1400130590; // 短信应用SDK AppKey string appkey = "f9683967be57f6617d7096e2cc5ce78c"; // 需要发送短信的手机号码 string[] phoneNumbers = { "18397776538" }; // 短信模板ID,需要在短信应用中申请 int templateId = 182188; // NOTE: 这里的模板ID`7839`只是一个示例,真实的模板ID需要在短信控制台中申请 //templateId 7839 对应的内容是"您的验证码是: {1}" // 签名 string smsSign = ""; // NOTE: 这里的签名只是示例,请使用真实的已申请的签名, 签名参数使用的是`签名内容`,而不是`签名ID` try { SmsSingleSender ssender = new SmsSingleSender(appid, appkey); var result = ssender.sendWithParam("86", phoneNumbers[0], templateId, new[] { "老婆" }, smsSign, "", ""); // 签名参数未提供或者为空时,会使用默认签名发送短信 Console.WriteLine(result); } catch (JSONException e) { Console.WriteLine(e); } catch (HTTPException e) { Console.WriteLine(e); } catch (Exception e) { Console.WriteLine(e); } }
public async Task <IActionResult> Remind(int toUserId) { var user = await _db.Users .Where(x => x.Id == toUserId) .Select(x => new { UserId = x.Id, UserName = x.UserName, Phone = x.PhoneNumber, Balance = x.AccountDetails.Sum(v => v.Amount), HasToday = x.SmsSendLogReceiveUser.Any(v => v.SendTime > DateTime.Now.Date), }) .FirstOrDefaultAsync(); if (user == null) { return(BadRequest("用户不存在。")); } if (string.IsNullOrWhiteSpace(user.Phone)) { return(BadRequest($"用户电话不存在或格式不对: {user.Phone}。")); } if (user.Balance >= 0) { return(BadRequest($"用户账户余额必须大于0: {user.Balance}。")); } if (user.HasToday) { return(BadRequest($"一天只能给用户催一次帐。")); } string[] parameters = new[] { user.UserName, (-user.Balance).ToString("N2") }; var smsSendLog = new SmsSendLog { OperationUserId = int.Parse(User.GetUserId()), ReceiveUserId = toUserId, SendTime = DateTime.Now, TemplateId = _smsTemplateConfig.RemindTemplateId, ReceiveUserPhone = user.Phone, Parameter = JsonConvert.SerializeObject(parameters), }; _db.SmsSendLog.Add(smsSendLog); await _db.SaveChangesAsync(); var client = new SmsSingleSender(_smsConfig.AppId, _smsConfig.AppKey); var result = client.sendWithParam("86", user.Phone, templateId: _smsTemplateConfig.RemindTemplateId, parameters: parameters, sign: _smsTemplateConfig.Sign, extend: "", ext: ""); smsSendLog.SmsSendResult = new SmsSendResult { ErrorMessage = result.errMsg, ExtensionMessage = result.ext, ErrorCode = result.result, Fee = (byte)result.fee, Sid = result.sid, }; await _db.SaveChangesAsync(); return(result.result switch { 0 => Ok(), _ => BadRequest(result.errMsg), });