예제 #1
0
        // 二次验证接口,POST请求
        public JsonResult SecondValidate()
        {
            GeetestLibResult             result    = null;
            IDictionary <string, string> paramDict = new Dictionary <string, string> {
            };
            GeetestLib gtLib        = new GeetestLib(GeetestConfig.GEETEST_ID, GeetestConfig.GEETEST_KEY);
            string     challenge    = Request.Form[GeetestLib.GEETEST_CHALLENGE];
            string     validate     = Request.Form[GeetestLib.GEETEST_VALIDATE];
            string     seccode      = Request.Form[GeetestLib.GEETEST_SECCODE];
            string     bypass_cache = GetBypassCache();

            if (bypass_cache is null)
            {
                return(Json(new { result = "fail", version = GeetestLib.VERSION, msg = "获取缓存的bypass状态发生异常" }));
            }

            if (bypass_cache == "success")
            {
                result = gtLib.SuccessValidate(challenge, validate, seccode, paramDict);
            }
            else
            {
                result = gtLib.FailValidate(challenge, validate, seccode);
            }

            // 注意,不要更改返回的结构和值类型
            if (result.GetStatus() == 1)
            {
                return(Json(new { result = "success", version = GeetestLib.VERSION }));
            }
            else
            {
                return(Json(new { result = "fail", version = GeetestLib.VERSION, msg = result.GetMsg() }));
            }
        }
예제 #2
0
        // 二次验证接口,POST请求
        public JsonResult SecondValidate()
        {
            GeetestLib gtLib     = new GeetestLib(GeetestConfig.GEETEST_ID, GeetestConfig.GEETEST_KEY);
            string     challenge = Request.Form[GeetestLib.GEETEST_CHALLENGE];
            string     validate  = Request.Form[GeetestLib.GEETEST_VALIDATE];
            string     seccode   = Request.Form[GeetestLib.GEETEST_SECCODE];
            int?       status    = HttpContext.Session.GetInt32(GeetestLib.GEETEST_SERVER_STATUS_SESSION_KEY);
            string     userId    = HttpContext.Session.GetString("userId");

            // session必须取出值,若取不出值,直接当做异常退出
            if (status is null)
            {
                return(Json(new { result = "fail", version = GeetestLib.VERSION, msg = "session取key发生异常" }));
            }
            GeetestLibResult result = null;

            if (status == 1)
            {
                /*
                 * 自定义参数,可选择添加
                 *  user_id user_id作为客户端用户的唯一标识,确定用户的唯一性;作用于提供进阶数据分析服务,可在register和validate接口传入,不传入也不影响验证服务的使用;若担心用户信息风险,可作预处理(如哈希处理)再提供到极验
                 *  client_type 客户端类型,web:电脑上的浏览器;h5:手机上的浏览器,包括移动应用内完全内置的web_view;native:通过原生sdk植入app应用的方式;unknown:未知
                 *  ip_address 客户端请求sdk服务器的ip地址
                 */
                IDictionary <string, string> paramDict = new Dictionary <string, string> {
                    { "user_id", userId }, { "client_type", "web" }, { "ip_address", "127.0.0.1" }
                };
                result = gtLib.SuccessValidate(challenge, validate, seccode, paramDict);
            }
            else
            {
                result = gtLib.FailValidate(challenge, validate, seccode);
            }
            // 注意,不要更改返回的结构和值类型
            if (result.GetStatus() == 1)
            {
                return(Json(new { result = "success", version = GeetestLib.VERSION }));
            }
            else
            {
                return(Json(new { result = "fail", version = GeetestLib.VERSION, msg = result.GetMsg() }));
            }
        }