Xunm模版升级成功,原购买的朋友可以联系作者进行升级操作
首页 » 福利 » 极验拼图验证码源码案例
极验拼图验证码源码案例
  • admin
  • 2018-07-18
  • 123 次
  • 0 条
  • 福利

  • 这是从贴吧云签到插件中扒出来的代码,极验id和key都使用的默认的。

    首先创建一个登录表单index.php

    <?php
    /**
     * 极验拖动验证码
     * @time  2018年6月15日
     * 
     */
    
    // 调用极验类库
    include 'geetestlib.php';
    if (isset($_POST['user'])&&isset($_POST['password'])) {
        // 极验验证码表单post过来
        if(isset($_POST['geetest_challenge']) && isset($_POST['geetest_validate']) && isset($_POST['geetest_seccode'])){
            $geetest = new GeetestLib();
            // 极验key
            $geetest->set_privatekey("2d5be5ba4207f11d33f7ae5e14a1c33e");
            // 使用key解码,解码成功返回true
            $result = $geetest->validate($_POST['geetest_challenge'], $_POST['geetest_validate'], $_POST['geetest_seccode']);
            if ($result == TRUE) {
                exit("<script language='javascript'>alert('登录成功!');</script>");
            } else if ($result == FALSE) {
                exit("<script language='javascript'>alert('登陆失败,请拖动滑块完成验证!');</script>");
            } else {
                exit("<script language='javascript'>alert('登陆失败,请拖动滑块完成验证!');</script>");
            }
        }else{
            exit("<script language='javascript'>alert('登陆失败,请拖动滑块完成验证!');</script>");
        }
    }
    
    
    ?>
    
    <form action="index.php" method="post">
        <p>user:<input type="text" name="user" /></p>
        <p>password:<input type="password" name="password" /></p>
        <?php
        echo "<div class=\"box\">";
        $geetest = new GeetestLib();
                // 使用id获取验证码
        $geetest->set_captchaid("a757a567a6c660610521e79a429d7e4c");
        if ($geetest->register()) {
            echo $geetest->get_widget("embed");
        }
        echo "</div><br/>";
        ?>
        <input type="submit" value="登录" />
    </form>
    

    之后我们创建极验的类库geetestlib.php,放入代码:

    <?php
    /**
     * 极验验证码类库
     * 
     */
    define('GT_API_SERVER', 'http://api.geetest.com');
    define('GT_SSL_SERVER', 'https://api.geetest.com');
    define('GT_SDK_VERSION', 'php_2.15.4.2.2');
    class GeetestLib{
        function __construct() {
            $this->challenge = "";
        }
        
        function set_captchaid($captcha_id) {
            $this->captcha_id = $captcha_id;
        }
    
        function set_privatekey($private_key) {
            $this->private_key = $private_key;
        }
        
        function register() {
            $this->challenge = $this->_send_request("/register.php", array("gt"=>$this->captcha_id));
            if (strlen($this->challenge) != 32) {
                return 0;
            }
            return 1;
        }
        
        function get_widget($product, $popupbtnid="", $ssl=FALSE) {
            $params = array(
                "gt" => $this->captcha_id,
                "challenge" => $this->challenge,
                "product" => $product,
            );
            if ($product == "popup") {
                $params["popupbtnid"] = $popupbtnid;
            }
            if(!isset($_SERVER['HTTPS'])){
                $server = GT_API_SERVER;
            }
            else{
                $server = GT_SSL_SERVER ;
            }
            return "<script type='text/javascript' src='".$server."/get.php?".http_build_query($params)."'></script>";
        }
    
        function validate($challenge, $validate, $seccode) {    
            if ( ! $this->_check_validate($challenge, $validate)) {
                return FALSE;
            }
            $query = http_build_query(array("seccode"=>$seccode,"sdk"=>GT_SDK_VERSION));
            $codevalidate = $this->_http_post('api.geetest.com', '/validate.php', $query);
            if (strlen($codevalidate)>0 && $codevalidate==md5($seccode)) {
                return TRUE;
            } else if ($codevalidate == "false"){
                return FALSE;
            } else { 
                return $codevalidate;
            }
        }
        
        function _check_validate($challenge, $validate) {
            if (strlen($validate) != 32) {
                return FALSE;
            }
            if (md5($this->private_key.'geetest'.$challenge) != $validate) {
                return FALSE;
            } 
            return TRUE;
        }
    
        function _send_request($path, $data, $method="GET") {
            if ($method=="GET") {
                $opts = array(
                    'http'=>array(
                        'method'=>"GET",
                        'timeout'=>2,
                    )
                );
                $context = stream_context_create($opts);
                $response = file_get_contents(GT_API_SERVER.$path."?".http_build_query($data), false, $context);
    
            }
            return $response;
        }
    
        function _http_post($host,$path,$data,$port = 80){
            $http_request = "POST $path HTTP/1.0\r\n";
            $http_request .= "Host: $host\r\n";
            $http_request .= "Content-Type: application/x-www-form-urlencoded\r\n";
            $http_request .= "Content-Length: " . strlen($data) . "\r\n";
            $http_request .= "\r\n";
            $http_request .= $data;
            $response = '';
            if (($fs = @fsockopen($host, $port, $errno, $errstr, 10)) == false) {
                die ('Could not open socket! ' . $errstr);
            }        
            fwrite($fs, $http_request);
            while (!feof($fs))
                $response .= fgets($fs, 1160);
            fclose($fs);        
            $response = explode("\r\n\r\n", $response, 2);
            return $response[1];
        }
    }
    ?>
    

    放在同级目录即可。
    5a5e1529041592.jpg



    最后修改于:2018-07-18 11:55
    分享


    博主介绍

  • 博主:寻梦xunm
  • 邮箱:vipshiyi@qq.com
  • 微信:shiihk
  • 熊掌号:奇乐之梦
  • 语录:追寻最初的梦想,坚持走下去!
  • 博主说说

    申请转正的朋友请在或者文章下面进行评论留言即可,

    转正评论留言格式为:你注册的用户名称或者邮箱即可!