/// <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);
        }
Exemplo n.º 2
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.º 3
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.º 4
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.º 5
0
        /// <summary>
        /// 发送普通短信,但短信内容必须与事先在腾讯云提交审核通过的模版匹配。
        /// </summary>
        /// <param name="mobile"></param>
        /// <param name="content">短信正文(带签名)。例如:【短信签名】{1}为您的验证码。如非本人操作,请忽略本短信。</param>
        /// <remarks>腾讯云规定:短信内容必须匹配事先提交并通过审核的模版。</remarks>
        /// <returns></returns>
        public async Task <bool> SendSmsAsync(string mobile, string content)
        {
            await Task.FromResult(0);

            var appid             = _options.AppId;
            var appkey            = _options.AppKey;
            var defaultNationCode = TencentSmsDefaults.DefaultNationCode;

            if (string.IsNullOrWhiteSpace(mobile))
            {
                throw new ArgumentNullException(nameof(mobile));
            }
            if (string.IsNullOrWhiteSpace(content))
            {
                throw new ArgumentNullException(nameof(content));
            }

            try
            {
                var sender     = new SmsSingleSender(appid, appkey);
                var sendResult = sender.send(0, defaultNationCode, mobile, content, "", "");

                if (sendResult.result == 0)
                {
                    _logger.LogDebug($"成功发送短信给[{mobile}],内容长度:{content.Length}");
                    return(true);
                }
                else
                {
                    _logger.LogDebug($"未能成功发送短信给[{mobile}],内容长度:{content.Length}");
                    return(false);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "发送短信时发生异常");
                return(false);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 发送短信验证码
        /// </summary>
        /// <param name="strPhone"></param>
        /// <param name="strCode"></param>
        public static ApiMessage <string> Send(string strPhone, string strCode)
        {
            var msg = new ApiMessage <string>();

            try
            {
                LogHelper.WriteLog(JsonConvert.SerializeObject(new { strPhone, strCode }), LogHelper.LogType.Info);
                SmsSingleSender ssender = new SmsSingleSender(appid, appkey);
                var             result  = ssender.send(0, "86", strPhone, "【" + logoname + "】您的验证码是: " + strCode, "", "");
                LogHelper.WriteLog(JsonConvert.SerializeObject(result), LogHelper.LogType.Info);
                if (result.result == 0)
                {
                    return(msg);
                }
                msg.Success = false;
                msg.Msg     = result.errMsg;
                return(msg);
            }
            catch (JSONException e)
            {
                msg.Success = false;
                msg.Msg     = e.Message;
                return(msg);
            }
            catch (HTTPException e)
            {
                msg.Success = false;
                msg.Msg     = e.Message;
                return(msg);
            }
            catch (Exception e)
            {
                msg.Success = false;
                msg.Msg     = e.Message;
                return(msg);
            }
        }
Exemplo n.º 7
0
        public void Send(ISMSEntity entity)
        {
            var sender = new SmsSingleSender(Constants.SMS_AppId, Constants.SMS_AppKey);

            sender.send(0, "86", entity.Mobile, entity.GetBody(), string.Empty, string.Empty);
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            ConsCL();
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic["Monday"]    = "一";
            dic["Tuesday"]   = "二";
            dic["Wednesday"] = "三";
            dic["Thursday"]  = "四";
            dic["Friday"]    = "五";
            dic["Saturday"]  = "六";
            dic["Sunday"]    = "日";
            Dictionary <string, int> dictoint = new Dictionary <string, int>();

            dictoint["Monday"]    = 1;
            dictoint["Tuesday"]   = 2;
            dictoint["Wednesday"] = 3;
            dictoint["Thursday"]  = 4;
            dictoint["Friday"]    = 5;
            dictoint["Saturday"]  = 6;
            dictoint["Sunday"]    = 7;

            string cityname = "北京";
            string uri      = GetString(cityname);
            string res      = GetHttpData(uri);
            string uri2     = GetString2(cityname);//空气指数
            string res2     = GetHttpData(uri2);

            //Console.WriteLine(res);
            //Console.WriteLine(res2);

            //return;

            // 短信应用SDK AppID
            int appid = 1400066350;
            // 短信应用SDK AppKey
            string appkey = "c9b1355bc16f6c84f707aaef08953227";

            // 需要发送短信的手机号码
            string[] phoneNumbers = { "13261660202", "15010735298", "13001023920" };
            // 短信模板ID,需要在短信应用中申请

            string weather = GetWea(res);
            string temp    = GetTemp(res);
            string aqi     = GetAQI(res2);
            string qlty    = GetQlty(res2);

            //Console.WriteLine(aqi);
            //Console.WriteLine(qlty);
            //return;



            //int templateId = 83661; // NOTE: 这里的模板ID`7839`只是一个示例,真实的模板ID需要在短信控制台中申请
            string test = "小楠宝,你好,今天是" +
                          DateTime.Now.Year.ToString() + "年"
                          + DateTime.Now.Month.ToString() + "月"
                          + DateTime.Now.Day.ToString() + "日,星期"
                          + dic[DateTime.Now.DayOfWeek.ToString()] + ","
                          + cityname + "现在的温度是" + temp + "℃,天气是“" + weather + "”,空气质量指数为" + aqi + ",空气质量为“" + qlty + "”,"
                          + conscoursetext(DateTime.Now.Subtract(new DateTime(2018, 2, 26, 0, 0, 0)).Days / 7 + 1, dictoint[DateTime.Now.DayOfWeek.ToString()]) +
                          "。今天要开开心心的哦。--来自小小龙宝。\n";

            Console.WriteLine(test);
            return;

            try
            {
                SmsSingleSender ssender = new SmsSingleSender(appid, appkey);
                var             result  = ssender.send(0, "86", phoneNumbers[0],
                                                       test, "", "");
                Console.WriteLine(result);
            }
            catch (JSONException e)
            {
                Console.WriteLine(e);
            }
            catch (HTTPException e)
            {
                Console.WriteLine(e);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            //Console.ReadLine();
        }