コード例 #1
0
        public async Task <ResultCaptcha> Validate(string token)
        {
            ResultCaptcha result = new ResultCaptcha();

            try
            {
                var client = new HttpClient();

                var ruta = $"https://www.google.com/recaptcha/api/siteverify?secret={Secret}&response={token}";

                var respuesta = await client.GetStringAsync(requestUri : ruta);

                result = JsonConvert.DeserializeObject <ResultCaptcha>(respuesta);
            }
            catch (Exception e)
            {
                result.Errors = e.Message;
                return(result);
            }

            return(result);
        }
コード例 #2
0
ファイル: SYS_PhoneCode.cs プロジェクト: kkwkk/ybyzt
    /// <summary>
    /// 获取修改登录密码,核心企业入驻的短信验证码
    /// </summary>
    /// <param name="JSon"></param>
    /// <param name="version"></param>
    /// <returns></returns>
    public ResultCaptcha GetCaptcha(string JSon, string version)
    {
        string phonenumb = string.Empty;
        string Type      = string.Empty;
        int    typeint   = 0;
        string typename  = string.Empty;
        string phonenum  = string.Empty;
        List <Hi.Model.SYS_Users> userList = null;

        Hi.BLL.SYS_Users bll_user = new Hi.BLL.SYS_Users();
        try
        {
            #region//JSon取值
            JsonData JInfo = JsonMapper.ToObject(JSon);
            if (JInfo.Count > 0 && JInfo["PhoneNumb"].ToString().Trim() != "" && JInfo["Type"].ToString().Trim() != "")
            {
                phonenumb = JInfo["PhoneNumb"].ToString();
                Type      = JInfo["Type"].ToString();
            }
            else
            {
                return(new ResultCaptcha()
                {
                    Result = "T", Description = "参数异常"
                });
            }
            #endregion
            //double loginnum = 0;
            //if (double.TryParse(phonenumb, out loginnum))//如果输入的登录名是整数,则先判断是否是手机号登录,不是手机号登录的话,再判断是否是账号名登录
            //{
            //    userList = bll_user.GetList("",
            //           "Phone = " + phonenumb + " and AuditState =2 and dr=0 and isnull(IsEnabled,0) =1", "");
            //}
            //if (userList == null || userList.Count <= 0)//不是手机号登录的话,再判断是不是账号名登录
            //{
            //    userList = bll_user.GetList("",
            //           "UserName = '******' and AuditState =2 and dr=0 and isnull(IsEnabled,0) =1", "");
            //    //如果两种情况都没找到,就是账号不存在
            //    if (userList == null || userList.Count <= 0)
            //        return new ResultCaptcha() { Result = "F", Description = "账号不存在" };
            //}
            Hi.Model.SYS_Users user = new Hi.Model.SYS_Users();
            switch (Type)
            {
            case "1":
                double loginnum = 0;
                if (double.TryParse(phonenumb, out loginnum))    //如果输入的登录名是整数,则先判断是否是手机号登录,不是手机号登录的话,再判断是否是账号名登录
                {
                    userList = bll_user.GetList("",
                                                "Phone = " + phonenumb + " and AuditState =2 and dr=0 and isnull(IsEnabled,0) =1", "");
                }
                if (userList == null || userList.Count <= 0)     //不是手机号登录的话,再判断是不是账号名登录
                {
                    userList = bll_user.GetList("",
                                                "UserName = '******' and AuditState =2 and dr=0 and isnull(IsEnabled,0) =1", "");
                    //如果两种情况都没找到,就是账号不存在
                    if (userList == null || userList.Count <= 0)
                    {
                        return new ResultCaptcha()
                               {
                                   Result = "F", Description = "账号不存在"
                               }
                    }
                    ;
                }
                user     = userList[0];
                typeint  = -5;
                typename = "修改登录密码";
                phonenum = user.Phone;
                break;

            case "2":
                //首先验证这手机号是否已经注册
                List <Hi.Model.SYS_Users> list_users = bll_user.GetList("",
                                                                        "Phone = " + phonenumb + " and AuditState =2 and dr=0 and isnull(IsEnabled,0) =1", "");
                //如果已经注册,就不发送验证码,并提示
                if (list_users != null && list_users.Count > 0)
                {
                    return new ResultCaptcha()
                           {
                               Result = "F", Description = "该手机号码已注册过账号,请使用未注册的手机号码注册"
                           }
                }
                ;
                typeint  = -10;
                typename = "核心企业注册";
                phonenum = phonenumb;
                break;

            default:
                return(new ResultCaptcha()
                {
                    Result = "F", Description = "操作类型不存在"
                });
            }
            //获取六位随机数
            string       PhoneCode    = new Common().CreateRandomCode(6);
            GetPhoneCode getphonecode = new GetPhoneCode();
            getphonecode.GetUser(
                System.Configuration.ConfigurationManager.AppSettings["PhoneCodeAccount"].ToString(),
                System.Configuration.ConfigurationManager.AppSettings["PhoneCodePwd"].ToString());
            //手机发送验证码
            string rstr = getphonecode.ReturnSTR(phonenum, PhoneCode);
            //信息发送成功的话需要在sys_phonecode表中插入一条数据
            if (rstr == "Success")
            {
                Hi.Model.SYS_PhoneCode phonecode = new Hi.Model.SYS_PhoneCode();
                phonecode.Type       = typeint;
                phonecode.Module     = typename;
                phonecode.Phone      = phonenum;
                phonecode.PhoneCode  = PhoneCode;
                phonecode.IsPast     = 0;
                phonecode.UserID     = user.ID;
                phonecode.UserName   = "";
                phonecode.CreateDate = DateTime.Now;
                phonecode.ts         = DateTime.Now;
                phonecode.modifyuser = user.ID;
                int i = new Hi.BLL.SYS_PhoneCode().Add(phonecode);
                if (i > 0)//新增成功的话拼接返回参数
                {
                    ResultCaptcha resultcaptcha = new ResultCaptcha();

                    resultcaptcha.Result      = "T";
                    resultcaptcha.Description = "返回成功";
                    resultcaptcha.SendId      = i.ToString();
                    resultcaptcha.Captcha     = PhoneCode;
                    resultcaptcha.PhoneNumb   = phonenum;
                    return(resultcaptcha);
                }
                else
                {
                    return(new ResultCaptcha()
                    {
                        Result = "F", Description = "验证码异常"
                    });
                }
            }
            else
            {
                return(new ResultCaptcha()
                {
                    Result = "F", Description = "发送失败 " + rstr
                });
            }
        }
        catch (Exception ex)
        {
            Common.CatchInfo(ex.Message + ":" + ex.StackTrace, "GetCaptcha:" + JSon);
            return(new ResultCaptcha()
            {
                Result = "F", Description = "参数异常"
            });
        }
    }