• js 之智能无感验证


    官网:https://www.dingxiang-inc.com/business/captcha

    开发文档:https://www.dingxiang-inc.com/docs/detail/captcha#doc-h3-31

    DEMO:https://cdn.dingxiang-inc.com/ctu-group/captcha-ui/demo/

    一、效果图

     二、后端

    include ("CaptchaClient.php");
    /**构造入参为appId和appSecret
     * appId和前端验证码的appId保持一致,appId可公开
     * appSecret为秘钥,请勿公开
     * token在前端完成验证后可以获取到,随业务请求发送到后台,token有效期为两分钟**/
    $appId = "appId";
    $appSecret = "appSecret";
    $client = new CaptchaClient($appId,$appSecret);
    $client->setTimeOut(2);      //设置超时时间,默认2秒
    # $client->setCaptchaUrl("http://cap.dingxiang-inc.com/api/tokenVerify");   
    //特殊情况可以额外指定服务器,默认情况下不需要设置
    $response = $client->verifyToken(token);  //token指的是前端传递的值,即验证码验证成功颁发的token
    echo $response->serverStatus;
    //确保验证状态是SERVER_SUCCESS,SDK中有容错机制,在网络出现异常的情况会返回通过
    if($response->result){
        echo "true";
        /**token验证通过,继续其他流程**/
    }else{
        echo "false";
        /**token验证失败**/
    }

    三、前端

    <script src="https://cdn.dingxiang-inc.com/ctu-group/captcha-ui/index.js"></script>
    var myCaptcha = _dx.Captcha(document.getElementById('c1'), {
        appId: 'appId', //appId,在控制台中“应用管理”或“应用配置”模块获取
        success: function (token) {
          // console.log('token:', token)
        }
    })
  • 相关阅读:
    1002 写出这个数
    1001 害死人不偿命的(3n+1)猜想
    Graph I
    Tree
    进程通信
    管道
    fork函数
    Priority Queue
    Search
    游戏 slider
  • 原文地址:https://www.cnblogs.com/yang-2018/p/13328413.html
Copyright © 2020-2023  润新知