geetest

package
v0.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// 极验二次验证表单传参字段 chllenge
	GeetestParamChallenge = "geetest_challenge"

	// 极验二次验证表单传参字段 validate
	GeetestParamValidate = "geetest_validate"

	// 极验二次验证表单传参字段 seccode
	GeetestParamSeccode = "geetest_seccode"

	// 极验验证API服务状态Session
	GeetestParamServerStatus = "gt_server_status"

	// 是否json格式
	JsonFormat = 1

	SdkVersion = "1.0.0"
)
View Source
const (
	DigestModeMD5        = "md5"
	DigestModeSHA256     = "sha256"
	DigestModeHMACSHA256 = "hmac-sha256"

	ResultStatusFailure = 0
	ResultStatusSuccess = 1

	ResultStatusFailureText = "fail"
	ResultStatusSuccessText = "success"

	HttpMethodGet  = "GET"
	HttpMethodPost = "POST"

	ClientTypeWeb     = "web"     // pc浏览器
	ClientTypeH5      = "h5"      // 手机浏览器,包括webview
	ClientTypeNative  = "native"  // 原生app
	ClientTypeUnknown = "unknown" // 未知

	// 极验服务器状态key, 用来存放到redis
	ServerStatusKey = "geetest:gt_server_status"
)

Variables

View Source
var (
	// 密钥
	AppId  = viper.GetString("geetest.appId")
	AppKey = viper.GetString("geetest.appKey")

	// 服务请求地址
	ApiUrl      = viper.GetString("geetest.apiUrl")
	RegisterUrl = viper.GetString("geetest.registerUrl")
	ValidateUrl = viper.GetString("geetest.validateUrl")

	// 是否启用新验证码
	NewCaptcha = true

	// 是否开启geetest
	Enabled = viper.GetBool("geetest.enabled")

	// 数据签名模式
	DigestMode = viper.GetString("geetest.digestmod")
	ClientType = viper.GetString("geetest.clientType")
)

Functions

func GenerateUUID

func GenerateUUID() string

生成一个不带减号的uuid

Types

type FailValidateParam

type FailValidateParam struct {
	Challenge string `json:"challenge"`
	Validate  string `json:"validate"`
	Seccode   string `json:"seccode"`
}

失败验证参数

type GeetestClient

type GeetestClient struct {
	AppId      string
	AppKey     string
	ClientType string
}

type GeetestResult

type GeetestResult struct {
	Status int    `json:"status"` // 0=失败, 1=成功
	Data   string `json:"data"`
	Msg    string `json:"msg"`
}

返回结果

func FailValidate

func FailValidate(param *FailValidateParam) *GeetestResult

*

  • 异常流程下(即验证初始化失败,宕机模式),二次验证
  • 注意:由于是宕机模式,初衷是保证验证业务不会中断正常业务,所以此处只作简单的参数校验,可自行设计逻辑。

func Register

func Register(param *RegisterParam) *GeetestResult

验证初始化

func SuccessValidate

func SuccessValidate(param *SuccessValidateParam) *GeetestResult

*

  • 正常流程下(即验证初始化成功),二次验证

type Param

type Param struct {
	// user_id作为终端用户的唯一标识,确定用户的唯一性;作用于提供进阶数据分析服务,
	// 可在api1 或 api2 接口传入,不传入也不影响验证服务的使用;若担心用户信息风险,可作预处理(如哈希处理)再提供到极验
	UserId string

	// 客户端请求SDK服务器的ip地址
	IPAddress string

	// 客户端类型,web(pc浏览器),h5(手机浏览器,包括webview),native(原生app),unknown(未知)
	ClientType string
}

type RegisterParam

type RegisterParam struct {
	Param
}

注册步骤参数

type RegisterResult

type RegisterResult struct {
	Success    int32
	AppId      string
	Challenge  string
	NewCaptcha bool
}

注册结果

type SuccessValidateParam

type SuccessValidateParam struct {
	Param
	Seccode   string `json:"geetest_seccode" binding:"required"`   // 核心校验数据, 极验二次验证表单传参字段 seccode
	Challenge string `json:"geetest_challenge" binding:"required"` // 流水号,一次完整验证流程的唯一标识, 极验二次验证表单传参字段 chllenge
	Validate  string `json:"geetest_validate" binding:"required"`  // 待校验的核心数据 chllenge
}

成功验证步骤参数

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL