How to integrate Geetest verification code with Laravel

不言
Release: 2023-03-28 20:50:02
Original
1629 people have browsed it

This article mainly introduces the method of integrating Geetestverification codewith Laravel. It has a certain reference value. Now I share it with you. Friends in need can refer to it

Geetest integration process

  1. The rough logic of logging in

  2. Register a Geetest account

  3. Register a behavioral verification in the background management of "JiXian"

  4. Configure ourcontroller according to the official Demoand routing

  5. Configure our login template according to the official Demo

  6. Test

##Geetest integration detailed process

1. Implement the general logic of login

Create the controller php artisan make:controller GeetestController


The edit controller/app/Http/Controllers/GeetestController


        
Copy after login

view is a simple form, omitted.


2. Omit => "Register"

3. Omit => "Backend login" => "Behavior verification" => Apply for an id & key

4. Configure the controller and routing

First of all, the core class library provided by the Demo is a class file called class.geetestlib.php, and the class name is GeetestLib. We create a controller with the same class name to replace it php artisan make:controller GeetestLib


Don’t copy the class, just copy the content in the class


GeetestController control Server implementation logic

captchaId, $this->privateKey); session_start(); $data = array( "user_id" => "test", # 网站用户id "client_type" => "web", #web:电脑上的浏览器;h5:手机上的浏览器,包括移动应用内完全内置的web_view;native:通过原生SDK植入APP应用的方式 "ip_address" => "127.0.0.1" # 请在此处传输用户请求验证时所携带的IP ); $status = $GtSdk->pre_process($data, 1); $_SESSION['gtserver'] = $status; $_SESSION['user_id'] = $data['user_id']; echo $GtSdk->get_response_str(); } }
Copy after login

Configure routing/routes/web.php

// 集成 Geetest 验证码 Route::get('GeetestLogin', 'GeetestController@login'); //登录页面 Route::get('GeetestCheck', 'GeetestController@check'); //登录验证 (我们没写具体逻辑) Route::get('GeetestStartCaptchaServlet', 'GeetestController@startCaptchaServlet'); // 调用方法启用验证码
Copy after login

5. Improve the login template/

resources/views/Geetest/login.blade.php

Need to import jquery (we use npm run dev compiled app.js to integrate jquery)


Need to import Demo and give gt.js, we put it under public/js


In fact, in theory, it can also be placed under /resouces/assets/js/, and In /resouces/assets/js/app.js, require comes in so that it can participate in compilation, and it can be packaged and integrated directly in public/js to take effect.


On the template, two style classes need to be defined.show & .hide => The styles used for gt.js control prompt information can also be written under /resouces/assets/sass/


Submit an id to the "Login" button in the form

Copy the front-end logic js provided in the Demo, pay attention to binding this button

Pay attention to the .ajax configuration The url must be the path we defined in web.php with 'GeetestStartCaptchaServlet'

Specific code

           Geetest 集成 Demo 
  

Geetest 集成 Demo Geetest 官方网站

我们不会公开您的邮箱

正在加载验证码......

请先完成验证

Copy after login

Test successful

Area that can be optimized

It is best not to use a "controller" as the core class library. You should find a way to integrate GeetestLib into another place


js on the view template & css should be written in resources/assets to participate in the compilation of generating app.css & app.js


We have not written the specific login logic. You should also be able to confirm whether the Geetest verification is successful in the login verification check() method. You can refer to Demo


Related recommendations:


Laravel framework implements the model layer Example of CURD operation

The above is the detailed content of How to integrate Geetest verification code with Laravel. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!