當前位置: 首頁>>代碼示例>>C#>>正文


C# Random.To方法代碼示例

本文整理匯總了C#中System.Random.To方法的典型用法代碼示例。如果您正苦於以下問題:C# Random.To方法的具體用法?C# Random.To怎麽用?C# Random.To使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Random的用法示例。


在下文中一共展示了Random.To方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SendUnBindingCode

        /// <summary>
        /// 發送解綁手機驗證碼
        /// <para>@mobile:手機號</para>
        /// <para>@rv:驗證碼</para>
        /// </summary>
        private ActionResult SendUnBindingCode(NxpDictionary<string, object> nxpDictionary)
        {
            var mobile = nxpDictionary.GetString("mobile", string.Empty);
            var userid = nxpDictionary.GetInt32("userid", 0);

            var member = _memberService.GetById(userid);
            if (member.Mobile != mobile)
            {
                return LogError("請輸入正確的手機號");
            }

            if (string.IsNullOrWhiteSpace(member.Mobile))
            {
                return LogError("手機號已解除綁定");
            }

            var code = new Random().Next(1000, 9999);

            var res = _memberService.SendSmsUnbindingMobileMessage(mobile, code.To<string>());

            if (!res)
            {
                return LogError("發送失敗或使用次數已滿");
            }

            //驗證碼寫入Session
            Session["UNBINDING_CODE_" + WebHelper.Md5(mobile)] = code;
            Session["UNBINDING_CODE_COUNT_" + WebHelper.Md5(mobile)] = 0;

            return ShowResult("驗證碼已發送");
        }
開發者ID:shouchangfayi,項目名稱:mvc,代碼行數:36,代碼來源:ServicesController.cs

示例2: SendFindPasswordCode

        /// <summary>
        /// 發送找回密碼驗證碼
        /// <para>@username:用戶名</para>
        /// <para>@rv:驗證碼</para>
        /// </summary>
        private ActionResult SendFindPasswordCode(NxpDictionary<string, object> nxpDictionary)
        {
            var userName = nxpDictionary.GetString("username", string.Empty);

            var rv = nxpDictionary.GetString("rv", string.Empty);
            if (string.IsNullOrEmpty(rv) || rv != Session["VALIDATE_CODE"].To<string>(string.Empty))
            {
                return LogError("輸入的答案不正確");
            }

            var member = _memberService.GetByName(userName);
            if (member == null)
            {
                return LogError("用戶名不存在");
            }

            if (member.IsBindingMobile != 1)
            {
                return LogError("用戶未綁定手機號");
            }

            if (member.Status != 0)
            {
                return LogError("用戶賬號被凍結");
            }

            var code = new Random().Next(1000, 9999);

            var res = _memberService.SendSmsRegisterMessage(member.Mobile, code.To<string>());

            if (!res)
            {
                return LogError("發送失敗或使用次數已滿");
            }

            //驗證碼寫入Session
            Session["FINDPASSWORD_CODE_" + WebHelper.Md5(userName)] = code;
            Session["FINDPASSWORD_CODE_COUNT_" + WebHelper.Md5(userName)] = 0;

            return ShowResult("驗證碼已發送");
        }
開發者ID:shouchangfayi,項目名稱:mvc,代碼行數:46,代碼來源:ServicesController.cs

示例3: SendRegisterCode

        /// <summary>
        /// 發送注冊驗證碼
        /// <para>@mobile:手機</para>
        /// <para>@rv:驗證碼</para>
        /// </summary>
        private ActionResult SendRegisterCode(NxpDictionary<string, object> nxpDictionary)
        {
            var mobile = nxpDictionary.GetString("mobile", string.Empty);;
            var rv = nxpDictionary.GetString("rv", string.Empty);

            if (string.IsNullOrEmpty(rv) || rv != Session["VALIDATE_CODE"].To<string>(string.Empty))
            {
                return LogError("輸入的答案不正確");
            }

            if (!Regex.IsMatch(mobile, "\\d{11}"))
            {
                return LogError("非法手機號");
            }

            var member = _memberService.GetByName(mobile);
            if (member != null && member.Id > 0)
            {
                return LogError("手機號已存在");
            }

            var tempMember = _memberService.GetByMobile(mobile);
            if (tempMember != null && tempMember.Id > 0)
            {
                return LogError("該手機號已被其他賬號綁定");
            }

            var code = new Random().Next(1000, 9999);

            var res = _memberService.SendSmsRegisterMessage(mobile, code.To<string>());

            if (!res)
            {
                return LogError("發送失敗或使用次數已滿");
            }

            //驗證碼寫入Session
            Session["REGISTER_CODE_" + WebHelper.Md5(mobile)] = code;
            Session["REGISTER_CODE_COUNT_" + WebHelper.Md5(mobile)] = 0;

            return ShowResult("成功發送了驗證碼");
        }
開發者ID:shouchangfayi,項目名稱:mvc,代碼行數:47,代碼來源:ServicesController.cs

示例4: SendBindingCode

        /// <summary>
        /// 發送綁定手機驗證碼
        /// <para>@mobile:手機號</para>
        /// <para>@rv:驗證碼</para>
        /// </summary>
        private ActionResult SendBindingCode(NxpDictionary<string, object> nxpDictionary)
        {
            var mobile = nxpDictionary.GetString("mobile", string.Empty);

            var rv = nxpDictionary.GetString("rv", string.Empty);
            if (string.IsNullOrEmpty(rv) || rv != Session["VALIDATE_CODE"].To<string>(string.Empty))
            {
                return LogError("輸入的答案不正確");
            }

            if (!Regex.IsMatch(mobile, "\\d{11}"))
            {
                return LogError("非法手機號");
            }

            if (_memberService.GetByMobile(mobile) != null)
            {
                return LogError("手機號已被綁定");
            }

            var code = new Random().Next(1000, 9999);

            var res = _memberService.SendSmsBindingMobileMessage(mobile, code.To<string>());

            if (!res)
            {
                return LogError("發送失敗或使用次數已滿");
            }

            //驗證碼寫入Session
            Session["BINDING_CODE_" + WebHelper.Md5(mobile)] = code;
            Session["BINDING_CODE_COUNT_" + WebHelper.Md5(mobile)] = 0;

            return ShowResult("驗證碼已發送");
        }
開發者ID:shouchangfayi,項目名稱:mvc,代碼行數:40,代碼來源:ServicesController.cs


注:本文中的System.Random.To方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。