Exemple #1
0
        /// <summary>
        /// 新增或者修改短信验证信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool Edit(SwtSmsVerificationModel model)
        {
            string sql = string.Format(@"if not exists(select * from Swt_SmsVerification where SSV_Phone='{0}' AND SSV_CustomerId={3})
                                        begin insert into Swt_SmsVerification (SSV_Verification,SSV_AddTime,SSV_IsInvalid,SSV_Phone,SSV_CustomerId) 
                                        values('{1}',getdate(),{2},'{0}',{3}) end
                                        else begin update Swt_SmsVerification set SSV_Verification='{1}',SSV_AddTime=getdate(),
                                        SSV_IsInvalid={2} where SSV_Phone='{0}' AND SSV_CustomerId={3} end",
                                       model.SSV_Phone,
                                       model.SSV_Verification,
                                       model.SSV_IsInvalid,
                                       model.SSV_CustomerId);

            return(DbHelperSQLP.ExecuteNonQuery(WebConfig.getConnectionString(), CommandType.Text, sql) > 0);
        }
Exemple #2
0
        /// <summary>
        /// 发送短信
        /// </summary>
        /// <param name="customerid"></param>
        /// <param name="type">1普通短信  2语音短信</param>
        /// <param name="mobile"></param>
        /// <param name="AppCode"></param>
        /// <returns></returns>
        public static bool SendSms(int type, string mobile, out ApiStatusCode AppCode)
        {
            int customerid = ConstConfig.storeId;

            try
            {
                using (var dal = FactoryDispatcher.SmsFactory())
                {
                    if (!dal.Sendable(mobile, customerid))
                    {
                        LogHelper.Log("操作太频繁,请稍后再试!", LogHelperTag.INFO, WebConfig.debugMode());
                        AppCode = ApiStatusCode.INVALID_OPTION_CODE;
                        return(false);
                    }

                    string verificationNum = StringHelper.GetRandomNumber(100000, 999999).ToString();

                    while (dal.Exists(verificationNum))
                    {
                        verificationNum = StringHelper.GetRandomNumber(100000, 999999).ToString();
                    }
                    using (TransactionScope scope = new TransactionScope())
                    {
                        SwtSmsVerificationModel model = new SwtSmsVerificationModel();
                        model.SSV_Verification = verificationNum;
                        model.SSV_AddTime      = DateTime.Now;
                        model.SSV_IsInvalid    = 0;
                        model.SSV_Phone        = mobile;
                        model.SSV_CustomerId   = customerid;
                        string content = string.Empty;
                        string msg     = "";
                        if (dal.Edit(model))
                        {
                            if (type == 1)
                            {
                                content = string.Format("您的验证码为:{0} ,有效期10分钟,祝您生活愉快!", verificationNum);
                            }
                            else
                            {
                                content = string.Format("您的验证码是{0}", verificationNum);
                            }
                            if (send(type, mobile, content, out msg))
                            {
                                AppCode = ApiStatusCode.OK;
                                LogHelper.Log(content, LogHelperTag.INFO, WebConfig.debugMode());
                                scope.Complete();
                                return(true);
                            }
                            AppCode = ApiStatusCode.APP_SEND_CODE;
                            LogHelper.Log(string.Format("mobile:{0}, content:{1}, result:{2}", mobile, verificationNum, "发送失败 " + msg), LogHelperTag.INFO, WebConfig.debugMode());
                        }
                        else
                        {
                            AppCode = ApiStatusCode.APP_SEND_CODE;
                            LogHelper.Log(string.Format("mobile:{0}, content:{1}, result:{2}", mobile, verificationNum, "发送失败"), LogHelperTag.INFO, WebConfig.debugMode());
                            return(false);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                AppCode = ApiStatusCode.APP_SEND_CODE;
                LogHelper.Log(string.Format("mobile:{0}, Message:{1}, StackTrace:{2}", mobile, ex.Message, ex.StackTrace), LogHelperTag.ERROR);
            }
            return(false);
        }