예제 #1
0
 private void btnTestSms_Click(object sender, RoutedEventArgs e)
 {
     if ((this.gvSms.SelectedItems.Count == 1) && (this.gvSms.SelectedItem is SmsObject))
     {
         SmsObject selectedItem = this.gvSms.SelectedItem as SmsObject;
         new Notificator().Twilio(Notificator.NotificationType.Restock, selectedItem);
     }
 }
예제 #2
0
파일: Commons.cs 프로젝트: huyqta/GetzTool
        public SmsObject SettingConfigurationSms(string strServer)
        {
            SmsObject sms = new SmsObject();

            sms.UrlApiSmoovIM       = ConfigurationManager.AppSettings[strServer + "_UrlApiSmoovIM"];
            sms.AccessKeyApiSmoovIM = ConfigurationManager.AppSettings[strServer + "_AccessKeyApiSmoovIM"];
            sms.SmoovImUserName     = ConfigurationManager.AppSettings[strServer + "_SmoovImUserName"];
            sms.SmoovImPassword     = ConfigurationManager.AppSettings[strServer + "_SmoovImPassword"];

            return(sms);
        }
예제 #3
0
파일: Form1.cs 프로젝트: huyqta/GetzTool
 private void UpdateServerSmoovImConfiguration()
 {
     if (rdSmsUAT.Checked)
     {
         smsObj        = new Commons().SettingConfigurationSms("UAT");
         smsObj.Server = Commons.Servers.UAT;
     }
     else
     {
         smsObj        = new Commons().SettingConfigurationSms("LIVE");
         smsObj.Server = Commons.Servers.LIVE;
     }
 }
예제 #4
0
        /*
         *  北京创世华信科技有限公司
         *  地址: 北京市朝阳区东三环南路联合国际大厦甲段12层
         *  网址:www.ipyy.com
         *  售后服务:010-57135000
         *  接口说明:客户接口部分提供http 和 WebService(目前只支持提交短信) 方式的接口,客户可以根据需求选择相应接口,接口编码方式默认采用UTF-8
         *  短信平台客户端地址:http://c.ipyy.net(近期将会升级,如果访问不通请使用https://c.ipyy.net)
         *  发送规则:
         *  同一个号码,发送内容带有(验证码),3分钟之内只能3条,
         *  超过3条,系统会默认为(恶意注册)
         *  同一个号码,系统默认一天之内只能发送10条信息,超过
         *  10条会超限失败(特殊号码、或特殊客户需要找客服处理)
         *  注:短信计费条数跟短信的字数有关,一般的短信70个字计费一条。超过70个字就划分为长短信,67个字计费一条,例如;71字的短信就是长短信计费2条,134个字也是计费2条(67*2)。135个字计费3条,依次类推。
         *  SendI18NSms
         *  国际短信发送
         *  SendMms
         *  发送彩信接口
         *  SendSms
         *  发送短信接口
         *
         *  userName	    发送用户帐号	用户帐号,由系统管理员
         *  password	    发送帐号密码
         *  sms	            短信参数对象	SmsObject结构,详见下面说明
         *  Msisdns	        全部被叫号码	发信发送的目的号码.多个号码之间用半角逗号隔开
         *  SMSContent	    发送内容	    短信的内容,内容需要UTF-8编码,提交内容格式:内容+【签名】。签名是公司的名字或者公司项目名称。示例:您的验证码:1439【腾飞】。【】是签名的标识符。请按照正规的格式提交内容测试,请用正规内容下发,最好不要当成是测试,就当是正式使用在给自己的客户发信息,签名字数3-8个字
         *  PlanSendTime	定时发送时间	为空表示立即发送,定时发送格式2010-10-24T 09:08:10
         *  ExtNumber	    扩展子号	    请先询问配置的通道是否支持扩展子号,如果不支持,请填空。子号只能为数字,且最多5位数。
         *
         *  返回值
         *  StatusCode	    发送的状态代码	OK表示成功,其它为失败,参见最后的错误代码表。
         *  Description	    发送说明	    发送结果状态操作说明
         *  MsgId	        任务ID	        提交短信的任务批次
         *  Amount	        当前余额	    当前账户的余额
         *  SuccessCounts	成功的号码数量	成功的号码数量
         *  BillingCount	消费的条数	    消费的条数值
         *  Errors	        错误描述	    本次发送中,相关的错误描述
         */


        /// <summary>
        /// 发送短信
        /// </summary>
        /// <param name="msisdns">发信发送的目的号码.多个号码之间用半角逗号隔开</param>
        /// <param name="smsContent">短信的内容,内容需要UTF-8编码,提交内容格式:内容+【签名】。签名是公司的名字或者公司项目名称。示例:您的验证码:1439【腾飞】。【】是签名的标识符。请按照正规的格式提交内容测试,请用正规内容下发,最好不要当成是测试,就当是正式使用在给自己的客户发信息,签名字数3-8个字 </param>
        /// <param name="planSendTime">定时发送时间	为空表示立即发送,定时发送格式2010-10-24T 09:08:10</param>
        /// <param name="extNumber">扩展子号 请先询问配置的通道是否支持扩展子号,如果不支持,请填空。子号只能为数字,且最多5位数</param>
        /// <returns>发送结果</returns>
        static public string DoSend(string msisdns, int?smsTemplateId, string smsContent, DateTime?planSendTime, string extNumber)
        {
            string result = string.Empty;

            try
            {
                DateTime CreateDate = DateTime.Now;
                string   userName   = CommonHelper.GetAppSettingsValue("smsUserName", "AA01177");
                string   password   = CommonHelper.GetAppSettingsValue("smsPass", "AA0117706");
                string   apiPass    = CommonHelper.GetAppSettingsValue("apiPass", "AA0117755");

                SmsObject smsObj = new SmsObject();
                smsObj.Msisdns      = msisdns;
                smsObj.SMSContent   = smsContent;
                smsObj.PlanSendTime = planSendTime;
                smsObj.ExtNumber    = extNumber;

                WebServiceSoapClient op  = new WebServiceSoapClient();
                SendResult           rlt = op.SendSms(userName, apiPass, smsObj);

                result = FormatResult(rlt);

                SmsSendLogBLL opSmsSendLogBLL = new SmsSendLogBLL();
                SmsSendLog    modelSmsSendLog = new SmsSendLog();
                modelSmsSendLog.SmsTemplateId = smsTemplateId;
                modelSmsSendLog.SendType      = ((planSendTime == null) ? (1) : (2));
                modelSmsSendLog.SmsContent    = smsContent;
                modelSmsSendLog.Mobile        = msisdns;
                if (rlt.StatusCode == ResultCode.OK)
                {
                    modelSmsSendLog.Status = 1;
                }
                else
                {
                    modelSmsSendLog.Status = 0;
                }
                modelSmsSendLog.IsDeleted  = 0;
                modelSmsSendLog.CreateDate = CreateDate;
                modelSmsSendLog.SendDate   = DateTime.Now;
                modelSmsSendLog.SendResult = result;
                int res = opSmsSendLogBLL.Add(modelSmsSendLog);
            }
            catch (Exception ex)
            {
                result = ex.Message;
                ExceptionLogBLL.WriteExceptionLogToDB("发送短信接口:" + ex.ToString());
            }
            return(result);
        }
예제 #5
0
파일: Form1.cs 프로젝트: huyqta/GetzTool
        public SmoovIMResponse CallApiSendSms(SmsObject smsObject)
        {
            var timestamp = DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds.ToString("###");

            var urlSms = string.Format(UrlSmoovIm.SendSms, smsObject.UrlApiSmoovIM);

            var accessKey = smsObject.AccessKeyApiSmoovIM;

            SmoovIMResponse apiResult = null;

            var responseOneTime = SmoovImHelper.GetOneTimeToken(accessKey, timestamp, smsObject.UrlApiSmoovIM);

            if (smsObject != null)
            {
                var stSmsModel = new JavaScriptSerializer().Serialize(smsObject);

                if (responseOneTime != null && responseOneTime.Status.Equals(StatusApiSmoovIM.Succcess))
                {
                    var responseRequestApiKey = SmoovImHelper.RequestApiKeysApi(smsObject.SmoovImUserName, smsObject.SmoovImPassword, accessKey, timestamp,
                                                                                responseOneTime.Response.Data.Token, smsObject.UrlApiSmoovIM);

                    if (responseRequestApiKey != null && responseRequestApiKey.Status.Equals(StatusApiSmoovIM.Succcess))
                    {
                        apiResult = SmoovImHelper.SendSms(smsObject, responseRequestApiKey.Response.Data.Apikey, timestamp,
                                                          responseRequestApiKey.Response.Data.Secret, urlSms);

                        if (responseRequestApiKey.Status.Equals(StatusApiSmoovIM.Succcess))
                        {
                            return(apiResult);
                        }

                        var stResponseRequestApiKey = new JavaScriptSerializer().Serialize(responseRequestApiKey);

                        apiResult = responseRequestApiKey;

                        var stApiResult = new JavaScriptSerializer().Serialize(apiResult);

                        var stError = string.Format("CallApiSendSMS Failed with stSmsModel: {0} stResponseRequestApiKey: {1} stApiResult: {2}",
                                                    stSmsModel, stResponseRequestApiKey, stApiResult);
                    }
                    else
                    {
                        var stResponseRequestApiKey = new JavaScriptSerializer().Serialize(responseRequestApiKey);

                        apiResult = responseRequestApiKey;

                        var stApiResult = new JavaScriptSerializer().Serialize(apiResult);

                        var stError = string.Format("CallApiSendSMS1 Failed with stSmsModel: {0} stResponseRequestApiKey: {1} stApiResult: {2}",
                                                    stSmsModel, stResponseRequestApiKey, stApiResult);
                    }
                }
                else
                {
                    var stResponseOneTime = new JavaScriptSerializer().Serialize(responseOneTime);

                    apiResult = responseOneTime;

                    var stApiResult = new JavaScriptSerializer().Serialize(apiResult);

                    var stError = string.Format("CallApiSendSMS2 Failed with stSmsModel: {0} stResponseOneTime: {1} stApiResult: {2}", stSmsModel,
                                                stResponseOneTime, stApiResult);
                }
            }

            return(apiResult);
        }
예제 #6
0
        public override async Task Run(IJobExecutionContext context)
        {
            await Console.Out.WriteLineAsync("开始处理短信事务...");

            var count = 0;

            //取得待发送列表
            using (var dapper = DapperFactory.Create())
            {
                var builder = new QueryBuilder().Select <SmsQueue>().Concat <Sms>().Concat <SmsTemplet>().Concat <SmsAccount>()
                              .From <SmsQueue>()
                              .InnerJoin <Sms>().On(new ConditionBuilder().Equal <SmsQueue, Sms>(m => m.SmsId, s => s.Id))
                              .InnerJoin <SmsTemplet>().On(new ConditionBuilder().Equal <Sms, SmsTemplet>(s => s.SmsTempletId, t => t.Id))
                              .InnerJoin <SmsAccount>().On(new ConditionBuilder().Equal <SmsTemplet, SmsAccount>(t => t.SmsAccountId, a => a.Id))
                              .Where(new ConditionBuilder().Equal <SmsQueue>(m => m.Status, EmSmsQueueStatus.WaitSend)
                                     .And().Equal <SmsQueue>(m => m.IsDeleted, false)
                                     .And().Equal <Sms>(s => s.IsDeleted, false)
                                     .And().Equal <SmsTemplet>(t => t.IsDeleted, false)
                                     .And().Equal <SmsAccount>(a => a.IsDeleted, false))
                ;

                var items = await dapper.QueryListAsync <SmsQueue, Sms, SmsTemplet, SmsAccount, SmsQueue>(builder, (m, s, t, a) =>
                {
                    m.Sms        = s;
                    s.SmsTemplet = t;
                    t.SmsAccount = a;
                    return(m);
                }, splitOn : "Id");

                foreach (var item in items)
                {
                    using (var trans = dapper.BeginTrans())
                    {
                        if (item.ExpireTime < DateTime.Now)
                        {
                            //已过期
                            item.Status = EmSmsQueueStatus.Expired;
                            await dapper.UpdateAsync <SmsQueue>(new { item.Status }, new { item.Id });
                        }
                        else
                        {
                            //发送短信
                            var account = item.Sms.SmsTemplet.SmsAccount;
                            var sms     = new SmsObject
                            {
                                Mobile     = item.Sms.Mobile,
                                Signature  = item.Sms.SmsTemplet.Signature,
                                TempletKey = item.Sms.SmsTemplet.TempletKey,
                                Data       = JsonConvert.DeserializeObject <IDictionary <string, string> >(item.Sms.Data),
                                OutId      = item.Id.ToString()
                            };

                            var dict            = JsonConvert.DeserializeObject <IDictionary <string, string> >(account.ParameterConfig);
                            var accessKeyId     = dict["AccessKeyId"];
                            var accessKeySecret = dict["AccessKeySecret"];

                            (bool success, string response)res;
                            switch (account.Type)
                            {
                            case EmSmsAccountType.Aliyun:
                                res = await new AliyunSmsSender(accessKeyId, accessKeySecret).Send(sms);
                                break;

                            default:
                                res = (false, "短信账户功能未实现");
                                break;
                            }

                            item.Response = res.response.Substr(0, 1000);
                            item.Status   = res.success ? EmSmsQueueStatus.Sent : EmSmsQueueStatus.Error;
                            item.SendTime = DateTime.Now;

                            await dapper.UpdateAsync <SmsQueue>(new { item.Status, item.SendTime, item.Response }, new { item.Id });

                            count++;
                        }
                        trans.Commit();
                    }
                }
            }

            await Console.Out.WriteLineAsync($"共发送{count}条短信");

            await Console.Out.WriteLineAsync("结束处理短信事务...");
        }
예제 #7
0
        internal void Twilio(NotificationType type, SmsObject rec = null)
        {
            List <SmsObject> list = null;

            if (rec != null)
            {
                list = new List <SmsObject> {
                    rec
                };
            }
            else if (type == NotificationType.Restock)
            {
                list = (from x in Global.SETTINGS.SMS
                        where x.SmsType == SmsObject.SmsMessageEnum.Restock
                        select x).ToList <SmsObject>();
            }
            else if (type != NotificationType.Atc)
            {
                if (type == NotificationType.Paypal)
                {
                    list = (from x in Global.SETTINGS.SMS
                            where x.SmsType == SmsObject.SmsMessageEnum.PayPal
                            select x).ToList <SmsObject>();
                }
                else
                {
                    list = (from x in Global.SETTINGS.SMS
                            where x.SmsType == SmsObject.SmsMessageEnum.Checkout
                            select x).ToList <SmsObject>();
                }
            }
            else
            {
                list = (from x in Global.SETTINGS.SMS
                        where x.SmsType == SmsObject.SmsMessageEnum.Atc
                        select x).ToList <SmsObject>();
            }
            if (list != null)
            {
                foreach (SmsObject obj2 in list)
                {
                    try
                    {
                        decimal?nullable;
                        bool?   nullable2;
                        int?    nullable3;
                        string  message = obj2.Message;
                        if (rec == null)
                        {
                            message = message.Replace("#product_url#", this._url).Replace("#product_title#", this._productName).Replace("#time#", DateTime.Now.ToLocalTime().ToString("dd/MM/yy hh:mm:sstt", CultureInfo.InvariantCulture)).Replace("#rnd#", "(" + _rnd.Next(0, 20).ToString() + ")").Replace("#paypal#", this._task.PaypalLink).Replace("#orderno#", this._task.OrderNo).Replace("#profile_name#", this._task.CheckoutProfile).Replace("#size#", this._task.PickedSize).Replace("#website#", this._task.HomeUrl).Replace("#task_name#", this._task.Name);
                        }
                        else
                        {
                            message = "TESTING MESSAGE";
                        }
                        if (this._task != null)
                        {
                            Global.SETTINGS.PROFILES.First <ProfileObject>(x => x.Id == this._task.CheckoutId);
                            if (this._task.Login)
                            {
                                message = message.Replace("#username#", this._task.Username).Replace("#password#", this._task.Password);
                            }
                        }
                        TwilioClient.Init(obj2.AccountSid, obj2.AuthToken);
                        List <Uri> mediaUrl = null;
                        if (message.Contains("#img#") && !string.IsNullOrEmpty(this._task.ImgUrl))
                        {
                            message  = message.Replace("#img#", "");
                            mediaUrl = new List <Uri> {
                                new Uri(this._task.ImgUrl)
                            };
                        }
                        PhoneNumber to = new PhoneNumber(obj2.NumberTo);
                        if (mediaUrl != null)
                        {
                            nullable  = null;
                            nullable2 = null;
                            nullable3 = null;
                            nullable2 = null;
                            nullable2 = null;
                            MessageResource.Create(to, null, new PhoneNumber(obj2.NumberFrom), null, message, mediaUrl, null, null, nullable, nullable2, nullable3, null, nullable2, null, null, null, nullable2, null);
                        }
                        else
                        {
                            nullable  = null;
                            nullable2 = null;
                            nullable3 = null;
                            nullable2 = null;
                            nullable2 = null;
                            MessageResource.Create(to, null, new PhoneNumber(obj2.NumberFrom), null, message, null, null, null, nullable, nullable2, nullable3, null, nullable2, null, null, null, nullable2, null);
                        }
                    }
                    catch (Exception exception)
                    {
                        if (this._task == null)
                        {
                            Global.Logger.Error("Error sending sms test message", exception);
                        }
                        else
                        {
                            Global.Logger.Error($"Task '{this._task.Name}': error sending sms message", exception);
                        }
                    }
                }
            }
        }
예제 #8
0
 public SmsData()
 {
     Object = new SmsObject();
 }