Git Product home page Git Product logo

gtsdk's Introduction

Gt Golang SDK

极验验证的非官方Golang SDK目前提供基于Beego框架的DEMO。

本项目是面向服务器端的,具体使用可以参考极验的 文档 ,客户端相关开发请参考极验的 前端文档。.

开发环境

  • Golang (推荐1.6.2以上版本)
  • Beego (推荐1.6.1以上版本)

快速开始

下面使用示例代码的均以Beego框架为例。

  1. 获取代码

通过go get获取代码:

$ go get github.com/lomoalbert/gtsdk
  1. 初始化验证

在调用GeetestLib前请自行在app.conf设定公钥和私钥,用户id为可选项,默认为空字符串:

PrivateKey = "你的私钥"
CaptchaID = "你的公钥"

根据自己的私钥初始化验证

func (ctl *RegisterController)Get() {
    userID := ""
    gt := gtsdk.GeetestLib(PrivateKey, CaptchaID)
    status := gt.PreProcess(userID)
    ctl.SetSession(gtsdk.GT_STATUS_SESSION_KEY, status)
    ctl.SetSession("user_id", userID)
    responseStr := gt.GetResponseStr()
    ctl.Ctx.WriteString(responseStr)
}
  1. 二次验证
func (ctl *ValidateController)Post() {
    var result bool
    var respstr string
    gt := gtsdk.GeetestLib(PrivateKey, CaptchaID)
    challenge := ctl.GetString(gtsdk.FN_CHALLENGE)
    validate := ctl.GetString(gtsdk.FN_VALIDATE)
    seccode := ctl.GetString(gtsdk.FN_SECCODE)
    status := ctl.GetSession(gtsdk.GT_STATUS_SESSION_KEY).(int)
    userID := ctl.GetSession("user_id").(string)
    if status == 0 {
        result = gt.FailbackValidate(challenge, validate, seccode)
    } else {
        result = gt.SuccessValidate(challenge, validate, seccode, userID)
    }
    if result {
        respstr = "success"
    } else {
        respstr = "fail"
    }
    ctl.Ctx.WriteString(respstr)
}

运行demo

  1. Beego demo运行:进入demo文件夹,运行bee run:
$ cd $GOPATH/src/github.com/lomoalbert/gtsdk/demo
$ bee run

在浏览器中访问http://localhost:8080即可看到Demo界面

发布日志

  • 3.2.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.