Forráskód Böngészése

更新验证码逻辑

sandm 1 éve
szülő
commit
f244f68c4a

+ 1 - 0
public/themes/default/views/app/auth/login.blade.php

@@ -258,6 +258,7 @@
 
             var mobile_captcha = new TencentCaptcha('196587903', mobile_captcha_callback, {});
             $('.btn-getcode').on('click', function () {
+
                 var mobile = $("input[name='mobile']").val();
                 if(mobile == null || mobile == ''){
                     $("#message_mobile").addClass("errinfo");

+ 133 - 57
public/themes/default/views/mobile/app/auth/login_mobile.blade.php

@@ -11,6 +11,7 @@
 @push('js')
     <script type="text/javascript" src="{{ theme_asset('gt/gt.js') }}"></script>
     <script type="text/javascript" src="{{ theme_asset('gt/gt.handle.js') }}"></script>
+    <script src="https://captcha.253.com/TCaptcha.js"></script>
 @endpush
 
 @section('content')
@@ -138,7 +139,82 @@
                 });
             };
 
-            gt_init(gt_call_back);//初始化极验
+            //gt_init(gt_call_back);//初始化极验
+
+            var mobile_captcha_flag = false;
+            var mobile_captcha_callback = function(res){
+                if(res.hasOwnProperty('errorMessage')){
+                    alert(res.errorMessage)
+                }
+                if(res.ret == 0){
+                    mobile_captcha_flag = true;
+                    console.log('行为验证通过');
+                    $("#ticket1").val(res.ticket);
+                    $("#bizState1").val(res.bizState);
+                    $("#randstr1").val(res.randstr);
+                    submit_data={
+                        "mobile":$("input[name='mobile']").val(),
+                        "type":"login",
+                        "ticket": res.ticket,
+                        "bizState": res.bizState,
+                        "randstr": res.randstr
+                    };
+                    $.ajax({
+                        method: 'post',
+                        url: '{{route('sms.send')}}',
+                        data: submit_data,
+                        beforeSend:function () {
+                            // console.log('请求开始');
+                            // $(".errinfo").text("");
+                            // $(".errinfo").removeClass("errinfo");
+
+                        },
+                        complete:function() {
+                            console.log('请求结束');
+                        },
+                        success: function (data) {
+                            // console.log(data);
+                            qsToast({type:2,context: '验证码已发送,请注意查收'});
+                            settime();
+                        },
+                        error: function (errorData) {
+                            // console.log(errorData);
+                            if (countdown == 60) {
+                                $('#getVerfyCode').removeClass('qs-btn-border-disabled');
+                                $('#getVerfyCode').text('获取验证码');
+                            }
+                            var response=$.parseJSON(errorData.response);
+                            if (errorData.status==422) {//验证错误
+                                $.each(response.errors,function (key,val) {
+                                    qsToast({type:2,context: val[0]});
+                                    return false;
+                                });
+                            }
+                            else if(errorData.status==400) {//业务错误
+                                qsToast({type:2,context: response.message});
+                                //is_need_geetest=response.errors.is_need_geetest;
+                            }
+                        }
+                    });
+                }else{
+                    console.log('用户主动关闭验证码')
+                }
+                console.log('callback:', res);
+            }
+
+            var mobile_captcha = new TencentCaptcha('196587903', mobile_captcha_callback, {});
+            $('.btn-getcode').on('click', function () {
+                var mobile = $.trim($('input[name=mobile]').val());
+                if (mobile == '') {
+                    qsToast({type:2,context: '请输入手机号码'});
+                    return false;
+                }
+                if ($('#getVerfyCode').hasClass('qs-btn-border-disabled')) {
+                    return false;
+                }
+                mobile_captcha.show();
+
+            });
 
             $(".input-login").keydown(function(ev){
                 ev = ev || window.event;
@@ -157,58 +233,58 @@
                     $('#autoLogin').val('0');
                 }
             })
-            $('.btn-getcode').on('click', function () {
-                var mobile = $.trim($('input[name=mobile]').val());
-                if (mobile == '') {
-                    qsToast({type:2,context: '请输入手机号码'});
-                    return false;
-                }
-                if ($('#getVerfyCode').hasClass('qs-btn-border-disabled')) {
-                    return false;
-                }
-                $('#getVerfyCode').addClass('qs-btn-border-disabled');
-                $('#getVerfyCode').text('发送中...');
-                submit_data={
-                    "mobile":mobile,
-                    "type":"login"
-                };
-                $.ajax({
-                    type: 'post',
-                    url: '{{route('sms.send')}}',
-                    data: submit_data,
-                    beforeSend:function () {
-                       // console.log('请求开始');
-
-
-                    },
-                    complete:function() {
-                        //console.log('请求结束');
-                    },
-                    success: function (data) {
-                       // console.log(data);
-                        qsToast({type:2,context: '验证码已发送,请注意查收'});
-                        settime();
-                    },
-                    error: function (errorData) {
-                       // console.log(errorData);
-                        if (countdown == 60) {
-                            $('#getVerfyCode').removeClass('qs-btn-border-disabled');
-                            $('#getVerfyCode').text('获取验证码');
-                        }
-                        var response=$.parseJSON(errorData.response);
-                        if (errorData.status==422) {//验证错误
-                            $.each(response.errors,function (key,val) {
-                                qsToast({type:2,context: val[0]});
-                                return false;
-                            });
-                        }
-                        else if(errorData.status==400) {//业务错误
-                            qsToast({type:2,context: response.message});
-                            is_need_geetest=response.errors.is_need_geetest;
-                        }
-                    }
-                });
-            });
+            {{--$('.btn-getcode').on('click', function () {--}}
+            {{--    var mobile = $.trim($('input[name=mobile]').val());--}}
+            {{--    if (mobile == '') {--}}
+            {{--        qsToast({type:2,context: '请输入手机号码'});--}}
+            {{--        return false;--}}
+            {{--    }--}}
+            {{--    if ($('#getVerfyCode').hasClass('qs-btn-border-disabled')) {--}}
+            {{--        return false;--}}
+            {{--    }--}}
+            {{--    $('#getVerfyCode').addClass('qs-btn-border-disabled');--}}
+            {{--    $('#getVerfyCode').text('发送中...');--}}
+            {{--    submit_data={--}}
+            {{--        "mobile":mobile,--}}
+            {{--        "type":"login"--}}
+            {{--    };--}}
+            {{--    $.ajax({--}}
+            {{--        type: 'post',--}}
+            {{--        url: '{{route('sms.send')}}',--}}
+            {{--        data: submit_data,--}}
+            {{--        beforeSend:function () {--}}
+            {{--           // console.log('请求开始');--}}
+
+
+            {{--        },--}}
+            {{--        complete:function() {--}}
+            {{--            //console.log('请求结束');--}}
+            {{--        },--}}
+            {{--        success: function (data) {--}}
+            {{--           // console.log(data);--}}
+            {{--            qsToast({type:2,context: '验证码已发送,请注意查收'});--}}
+            {{--            settime();--}}
+            {{--        },--}}
+            {{--        error: function (errorData) {--}}
+            {{--           // console.log(errorData);--}}
+            {{--            if (countdown == 60) {--}}
+            {{--                $('#getVerfyCode').removeClass('qs-btn-border-disabled');--}}
+            {{--                $('#getVerfyCode').text('获取验证码');--}}
+            {{--            }--}}
+            {{--            var response=$.parseJSON(errorData.response);--}}
+            {{--            if (errorData.status==422) {//验证错误--}}
+            {{--                $.each(response.errors,function (key,val) {--}}
+            {{--                    qsToast({type:2,context: val[0]});--}}
+            {{--                    return false;--}}
+            {{--                });--}}
+            {{--            }--}}
+            {{--            else if(errorData.status==400) {//业务错误--}}
+            {{--                qsToast({type:2,context: response.message});--}}
+            {{--                is_need_geetest=response.errors.is_need_geetest;--}}
+            {{--            }--}}
+            {{--        }--}}
+            {{--    });--}}
+            {{--});--}}
 
 
             function ajax_login(type, captchaObj) {
@@ -272,9 +348,9 @@
                         },
                         error: function (errorData) {
                             var response=$.parseJSON(errorData.response);
-                            if (is_need_geetest==1){
-                                captchaObj.reset();
-                            }
+                            // if (is_need_geetest==1){
+                            //     captchaObj.reset();
+                            // }
                             if (errorData.status==422) {//验证错误
                                 $.each(response.errors,function (key,val) {
                                     qsToast({type:2,context: val[0]});
@@ -283,7 +359,7 @@
                             }
                             else if(errorData.status==400) {//业务错误
                                 qsToast({type:2,context: response.message});
-                                is_need_geetest=response.errors.is_need_geetest;
+                                //is_need_geetest=response.errors.is_need_geetest;
                             }
                         }
                     });