Exemplo n.º 1
0
        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
                    };
                }
            }));
        }
Exemplo n.º 2
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
         });
     }
 }
Exemplo n.º 3
0
        /// <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);
        }
        /// <summary>
        /// 发送短信
        /// </summary>
        /// <param name="phoneNumber">手机号码</param>
        /// <param name="msg">消息</param>
        /// <param name="extend">扩展(选填参数)</param>
        /// <param name="ext">说明(选填参数)</param>
        /// <returns></returns>
        public dynamic send(string phoneNumber, string msg, string extend, string ext)
        {
            SmsSingleSender ssender = new SmsSingleSender(int.Parse(base.appid), base.appkey);
            var             result  = ssender.send(1, "86", phoneNumber, msg, "", "");

            return(result);
        }
        /// <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);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 腾讯云短信发送kcp
        /// </summary>
        /// <param name="site"></param>
        /// <param name="phoneNumber"></param>
        /// <param name="vcode"></param>
        public static int SendMsgByTXY(string site, string phoneNumber, string vcode)
        {
            int    sdkappid = int.Parse(ConfigurationManager.AppSettings["sdkappid"]);
            string appkey   = ConfigurationManager.AppSettings["appkey"];
            int    result   = 1;//默认失败

            try
            {
                SmsSingleSender singleSender = new SmsSingleSender(sdkappid, appkey);

                //string msg = "您的验证码是:7894";
                string msg = "您的验证码是:" + vcode;


                var sendResult = singleSender.Send(0, "86", phoneNumber, msg, "", "");
                LogHelper.InfoFormat("{0}短信发送结果:{1}", phoneNumber, sendResult.ToJsonString());
                result = sendResult.result;

                return(result);
            }

            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            return(result);
        }
Exemplo n.º 8
0
        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));
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
 /// <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;
 }
Exemplo n.º 11
0
        public string sendCodebyqq(string ramcode, string phoneNumber)
        {
            // 请根据实际 appid 和 appkey 进行开发,以下只作为演示 sdk 使用
            int    sdkappid = 1400036626;
            string appkey   = "523bf885d88484e5f65952187520c0fe";

            int    tmplId     = 31143;
            string returncode = string.Empty;
            SmsSingleSenderResult singleResult;

            try
            {
                SmsSingleSender singleSender = new SmsSingleSender(sdkappid, appkey);

                List <string> templParams = new List <string>();
                templParams.Add(ramcode);

                // 指定模板单发
                singleResult = singleSender.SendWithParam("86", phoneNumber, tmplId, templParams, "", "", "");
                returncode   = singleResult.result.ToString();
            }
            catch (Exception e)
            {
            }
            return(returncode);
        }
Exemplo n.º 12
0
        /// <summary>
        /// 保存表单(新增、修改)
        /// </summary>
        /// <param name="keyValue">主键值</param>
        /// <param name="entity">实体对象</param>
        /// <returns></returns>
        public void SaveForm(string keyValue, TelphoneLiangJoinEntity entity)
        {
            if (!string.IsNullOrEmpty(keyValue))
            {
                entity.Modify(keyValue);
                this.BaseRepository().Update(entity);
            }
            else
            {
                entity.Create();
                this.BaseRepository().Insert(entity);

                //短信提醒上级审核
                IRepository db        = new RepositoryFactory().BaseRepository().BeginTrans();
                var         parentOrg = db.FindEntity <OrganizeEntity>(t => t.OrganizeId == entity.OrganizeId);
                if (parentOrg != null)
                {
                    SmsSingleSenderResult singleResult;
                    SmsSingleSender       singleSender = new SmsSingleSender(1400040861, "a92c87d0d291698777a9b5f323c0388a");
                    List <string>         templParams  = new List <string>();
                    templParams.Add(parentOrg.FullName);
                    singleResult = singleSender.SendWithParam("86", parentOrg.OuterPhone, 205528, templParams, "", "", "");
                }
                //申请加盟+1
                orgService.UpdateJoinCount(entity.OrganizeId);
            }
        }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
            SmsSingleSender       singleSender = new SmsSingleSender(appid, appkey);
            SmsSingleSenderResult resutl       = singleSender.send(0, "86", "18328636270", "这是测试信息", "", "");

            Console.WriteLine(resutl.result + "---" + resutl.errMsg);
            Console.ReadKey();
        }
Exemplo n.º 14
0
        public ActionResult SendSms(string telphone)
        {
            // 短信应用SDK AppID
            int appid = 1400247845;

            // 短信应用SDK AppKey
            string appkey = "e4f356f4cf5927e06994b73df3fa86c5";

            // 需要发送短信的手机号码
            //  string[] phoneNumbers = { "139094236879", "18193169220" };
            // string smsPhone = "13909426879";
            // 短信模板ID,需要在短信应用中申请
            int templateId = 444799; //

            // 签名
            string smsSign = "五点科技"; // NOTE: 这里的签名只是示例,请使用真实的已申请的签名, 签名参数使用的是`签名内容`,而不是`签名ID`
            //验证码
            Random r1      = new Random();
            int    smsCode = r1.Next(100000, 999999);
            //消息
            string smsMeg = "甘肃土木建筑学年会登录";


            //单发短信
            try
            {
                SmsSingleSender ssender = new SmsSingleSender(appid, appkey);
                var             result  = ssender.send(0, "86", "" + telphone + "",
                                                       "【" + smsSign + "】验证码" + smsCode + ",用于" + smsMeg + ",5分钟内有效。验证码提供给他人可能导致帐号被盗,请勿泄露,谨防被骗。", "", "");
                Console.WriteLine(result);
                ViewBag.code = smsCode;
                ViewBag.msg  = "消息已发送!";
                Sms obj = new Sms()
                {
                    Code     = smsCode,
                    TelPhone = telphone
                };
                var result2 = new SmsBLL().AddCoreInfo(obj);
            }

            catch (JSONException e)
            {
                Console.WriteLine(e);
                ViewBag.msg = e;
            }
            catch (HTTPException e)
            {
                Console.WriteLine(e);
                ViewBag.msg = e;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                ViewBag.msg = e;
            }

            return(View("Reg"));
        }
Exemplo n.º 15
0
        public ActionResult SendMobile_RechargeSum(Dictionary <string, string> queryvalues)
        {
            string Hour      = queryvalues.ContainsKey("Hour") ? queryvalues["Hour"] : string.Empty;
            string HourInter = queryvalues.ContainsKey("HourInter") ? queryvalues["HourInter"] : "10";
            string Money     = queryvalues.ContainsKey("Money") ? queryvalues["Money"] : "0";
            string Limit     = queryvalues.ContainsKey("Limit") ? queryvalues["Limit"] :"0";

            // 请根据实际 appid 和 appkey 进行开发,以下只作为演示 sdk 使用

            log.Info("充值统计接受参数Hour" + Hour + ",Money" + Money + ",Limit" + Limit);

            int    sdkappid = 1400023585;
            string appkey   = "aa51e0fe315f7873094779bda1d715b8";


            int tmplId = 9048;

            try
            {
                SmsSingleSender singleSender = new SmsSingleSender(sdkappid, appkey);

                List <string> templParams = new List <string>();

                SmsMultiSenderResult multiResult;
                SmsMultiSender       multiSender = new SmsMultiSender(sdkappid, appkey);
                //List<string> phoneNumbers = new List<string>() {
                //    "15918716259"
                //};
                List <string> phoneNumbers = new List <string>()
                {
                    "13923666964", "13760368110", "13651452358", "13058199330",
                    "15019431331", "13829601181", "13651452358"
                };
                // 指定模板群发
                // 假设短信模板内容为:测试短信,{1},{2},{3},上学。
                templParams.Clear();
                templParams.Add(HourInter);
                templParams.Add(Money);
                templParams.Add(Limit);
                multiResult = multiSender.SendWithParam("86", phoneNumbers, tmplId, templParams, "", "", "");

                log.Info("multiResult:" + multiResult.result);


                int res = NoAuthBLL.UpdateRechargeSum(Convert.ToInt32(Hour));

                log.Info("res:" + res);


                return(Content("1"));
            }
            catch (Exception e)
            {
                log.Info("充值统计接口错误" + e.Message);
                return(Content("0"));
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// 核单
        /// </summary>
        /// <param name="entity">主键值</param>
        /// <param name="State">状态:1-启动;0-禁用</param>
        public string UpdateTopOrg(TelphoneLiangJoinEntity entity, int State)
        {
            //获取0级机构id
            IRepository db = new RepositoryFactory().BaseRepository().BeginTrans();

            //生成靓号商场平台
            OrganizeEntity orgEntity = new OrganizeEntity()
            {
                ParentId   = "0",//0级机构
                FullName   = entity.CompanyName,
                ShortName  = entity.NickName,
                OuterPhone = entity.Telphone,
                InnerPhone = entity.WxAccount, //微信账号
                Nature     = entity.WxQRcode,  //微信二维码
                ManagerId  = entity.OpenId,
                Manager    = entity.FullName,
                Layer      = 1,
                DeleteMark = 0
            };
            OrganizeEntity newEntity = orgService.SaveReturnEntity(orgEntity);

            //更新申请状态
            TelphoneLiangJoinEntity reserveEntity = new TelphoneLiangJoinEntity();

            reserveEntity.Modify(entity.Id);
            reserveEntity.TopMark = State;
            this.BaseRepository().Update(reserveEntity);

            //创建vip机构
            TelphoneLiangVipEntity telphoneLiangVipEntity = new TelphoneLiangVipEntity()
            {
                OrganizeId   = newEntity.OrganizeId,
                FullName     = newEntity.FullName,
                UploadMax    = 1000,
                OtherMax     = 0,
                OrgMax       = 10,
                Price        = 0,
                VipStartDate = DateTime.Now,
                VipEndDate   = DateTime.Now.AddDays(7)
            };

            telphoneLiangVipIService.SaveForm(null, telphoneLiangVipEntity);

            //发送通过短信
            if (!string.IsNullOrEmpty(newEntity.Description))
            {
                SmsSingleSenderResult singleResult;
                SmsSingleSender       singleSender = new SmsSingleSender(1400040861, "a92c87d0d291698777a9b5f323c0388a");
                List <string>         templParams  = new List <string>();
                templParams.Add(entity.FullName);
                templParams.Add(newEntity.Description);
                //成功
                singleResult = singleSender.SendWithParam("86", entity.Telphone, 205617, templParams, "", "", "");
            }

            return($"已通过短信的方式通知了你的下级,其靓号商城为:{newEntity.Description}");
        }
Exemplo n.º 17
0
        public SmsSingleSender GetSingleSender()
        {
            if (!HasInitSingleSender())
            {
                SingleSenderCache = new SmsSingleSender(_appId, _appKey);
            }

            return(SingleSenderCache);
        }
Exemplo n.º 18
0
        static void Main(string[] args)
        {
            var appid        = 1400061152;
            var appkey       = "aed63c940dcfc946340f9b280e0dabfc";
            var phoneNumbers = new string[] { "5142438578", "" };
            var templateId   = 75975;
            var ssender      = new SmsSingleSender(appid, appkey);
//            var result = ssender.sendWithParam("1", phoneNumbers[0],
//                templateId, new string[]{}, "", "", "");
//            Console.WriteLine(result.result);
        }
Exemplo n.º 19
0
        static void Main(string[] args)
        {
            // 请根据实际 appid 和 appkey 进行开发,以下只作为演示 sdk 使用
            // appid,appkey,templId申请方式可参考接入指南 https://www.qcloud.com/document/product/382/3785#5-.E7.9F.AD.E4.BF.A1.E5.86.85.E5.AE.B9.E9.85.8D.E7.BD.AE
            int    sdkappid     = 123456;
            string appkey       = "1234567890abcdef1234567890abcdef";
            string phoneNumber1 = "12345678901";
            string phoneNumber2 = "12345678902";
            string phoneNumber3 = "12345678903";
            int    tmplId       = 7839;

            try
            {
                SmsSingleSenderResult singleResult;
                SmsSingleSender       singleSender = new SmsSingleSender(sdkappid, appkey);

                singleResult = singleSender.Send(0, "86", phoneNumber2, "测试短信,普通单发,深圳,小明,上学。", "", "");
                Console.WriteLine(singleResult);

                List <string> templParams = new List <string>();
                templParams.Add("指定模板单发");
                templParams.Add("深圳");
                templParams.Add("小明");
                // 指定模板单发
                // 假设短信模板内容为:测试短信,{1},{2},{3},上学。
                singleResult = singleSender.SendWithParam("86", phoneNumber2, tmplId, templParams, "", "", "");
                Console.WriteLine(singleResult);

                SmsMultiSenderResult multiResult;
                SmsMultiSender       multiSender  = new SmsMultiSender(sdkappid, appkey);
                List <string>        phoneNumbers = new List <string>();
                phoneNumbers.Add(phoneNumber1);
                phoneNumbers.Add(phoneNumber2);
                phoneNumbers.Add(phoneNumber3);

                // 普通群发
                // 下面是 3 个假设的号码
                multiResult = multiSender.Send(0, "86", phoneNumbers, "测试短信,普通群发,深圳,小明,上学。", "", "");
                Console.WriteLine(multiResult);

                // 指定模板群发
                // 假设短信模板内容为:测试短信,{1},{2},{3},上学。
                templParams.Clear();
                templParams.Add("指定模板群发");
                templParams.Add("深圳");
                templParams.Add("小明");
                multiResult = multiSender.SendWithParam("86", phoneNumbers, tmplId, templParams, "", "", "");
                Console.WriteLine(multiResult);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Exemplo n.º 20
0
        static void Main(string[] args)
        {
            // 请根据实际 appid 和 appkey 进行开发,以下只作为演示 sdk 使用
            int    sdkappid     = 123456;
            string appkey       = "1234567890abcdef1234567890abcdef";
            string phoneNumber1 = "12345678901";
            string phoneNumber2 = "12345678902";
            string phoneNumber3 = "12345678903";
            int    tmplId       = 7839;

            try
            {
                SmsSingleSenderResult singleResult;
                SmsSingleSender       singleSender = new SmsSingleSender(sdkappid, appkey);

                singleResult = singleSender.Send(0, "86", phoneNumber2, "测试短信,普通单发,深圳,小明,上学。", "", "");
                Console.WriteLine(singleResult);

                List <string> templParams = new List <string>();
                templParams.Add("指定模板单发");
                templParams.Add("深圳");
                templParams.Add("小明");
                // 指定模板单发
                // 假设短信模板内容为:测试短信,{1},{2},{3},上学。
                singleResult = singleSender.SendWithParam("86", phoneNumber2, tmplId, templParams, "", "", "");
                Console.WriteLine(singleResult);

                SmsMultiSenderResult multiResult;
                SmsMultiSender       multiSender  = new SmsMultiSender(sdkappid, appkey);
                List <string>        phoneNumbers = new List <string>();
                phoneNumbers.Add(phoneNumber1);
                phoneNumbers.Add(phoneNumber2);
                phoneNumbers.Add(phoneNumber3);

                // 普通群发
                // 下面是 3 个假设的号码
                multiResult = multiSender.Send(0, "86", phoneNumbers, "测试短信,普通群发,深圳,小明,上学。", "", "");
                Console.WriteLine(multiResult);

                // 指定模板群发
                // 假设短信模板内容为:测试短信,{1},{2},{3},上学。
                templParams.Clear();
                templParams.Add("指定模板群发");
                templParams.Add("深圳");
                templParams.Add("小明");
                multiResult = multiSender.SendWithParam("86", phoneNumbers, tmplId, templParams, "", "", "");
                Console.WriteLine(multiResult);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Exemplo n.º 21
0
 /// <summary>
 /// 发送单条信息
 /// </summary>
 /// <param name="MsgType">短信类型</param>
 /// <param name="MsgContent">短信内容</param>
 /// <param name="phoneNumbers">发送号码</param>
 public static string SendSmsForOne(string MsgContent, string phoneNumber)
 {
     try
     {
         SmsSingleSender ssender = new SmsSingleSender(appid, appkey);
         var             result  = ssender.send(0, "86", phoneNumber, MsgContent, "", "");
         return(result.ToString());
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemplo n.º 22
0
 /// <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;
     }
 }
Exemplo n.º 23
0
        public JsonResult doCodeGet(String mobile)
        {
            int    sdkappid = 1400096240;
            string appkey   = "409fa0923289125b7b12025b0b281535";
            SmsSingleSenderResult singleResult;
            SmsSingleSender       singleSender = new SmsSingleSender(sdkappid, appkey);
            List <string>         templParams  = new List <string>();

            SMSCode = GetRandomString(4, true, false, false, false, "");
            templParams.Add(SMSCode);
            singleResult = singleSender.SendWithParam("86", mobile, 128733, templParams, "", "", "");
            //var result = "{\"response\": {\"issuccess\": \"0\",\"msg\": \"用户名或密码错误!\"}}";

            return(Json(singleResult, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 24
0
        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));
        }
Exemplo n.º 25
0
        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);
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// 作废
        /// </summary>
        /// <param name="keyValue">主键值</param>
        /// <param name="State">状态:1-启动;0-禁用</param>
        public void UpdateDeleteState(string keyValue, int State)
        {
            TelphoneLiangJoinEntity reserveEntity = new TelphoneLiangJoinEntity();

            reserveEntity.Modify(keyValue);
            reserveEntity.DeleteMark = State;
            this.BaseRepository().Update(reserveEntity);
            var entity = this.BaseRepository().FindEntity(keyValue);

            if (entity != null)
            {
                SmsSingleSenderResult singleResult;
                SmsSingleSender       singleSender = new SmsSingleSender(1400040861, "a92c87d0d291698777a9b5f323c0388a");
                List <string>         templParams  = new List <string>();
                templParams.Add(entity.FullName);
                //申请失败提醒
                singleResult = singleSender.SendWithParam("86", entity.Telphone, 205531, templParams, "", "", "");
            }
        }
Exemplo n.º 27
0
 /// <summary>
 /// 发送短信验证码
 /// </summary>
 /// <param name="mobilePhone">手机号</param>
 /// <param name="smsMessage">短信内容</param>
 /// <param name="appID">appID</param>
 /// <param name="appKey">appKey</param>
 /// <param name="signature">短信签名</param>
 /// <param name="templateID">短信模板id</param>
 /// <returns>是否成功发送</returns>
 private bool SendMsg2User(string mobilePhone, List <string> smsMessage, int appID, string appKey, string signature, int templateID)
 {
     try
     {
         SmsSingleSender       smsSender = new SmsSingleSender(appID, appKey);
         SmsSingleSenderResult smsResult = smsSender.SendWithParam("86", mobilePhone, templateID, smsMessage, signature, "", "");
         if (smsResult.result != 0)
         {
             NLog.LogManager.GetCurrentClassLogger().Error("SmsMultiSender has error: " + smsResult);
             return(false);
         }
         return(true);
     }
     catch (Exception ex)
     {
         NLog.LogManager.GetCurrentClassLogger().Error(ex, ex.Message);
         return(false);
     }
 }
Exemplo n.º 28
0
        /// <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);
        }
Exemplo n.º 29
0
        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);
        }
Exemplo n.º 30
0
        /// <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);
        }