vaptcha

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2021 License: MIT Imports: 7 Imported by: 0

README

vaptcha-go

This is a third-party golang SDK for Vaptcha.

Quick Usage

  1. get this module by command line

go get github.com/Bisstocuz/vaptcha-go

  1. import this module

import "github.com/Bisstocuz/vaptcha-go"

  1. code with this module
Captcha
	result := vaptcha.RequestAndVerify(&vaptcha.CaptchaRequest{
		VID:      "your_captcha_unit_vid",
		Key:      "your_captcha_unit_key",
		Server:   "verify_url_from_frontend",
		Scene:    0,
		Token:    "token_from_frontend",
		ClientIP: "client_ip_address",
	})

	fmt.Println(result)

Result: true or false

More Usages

You can use separate functions to do more detail works.

Captcha
  1. CaptchaRequest.Request()

This function returns struct CaptchaResponse and you can access to its internal variables(Success,Score,Msg).

  1. CaptchaResponse.Verify()

This function returns various errors, you can check out details here.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIllegalServer   = errors.New("illegal server")
	ErrWrongUserID     = errors.New("userid error")
	ErrEmptyID         = errors.New("id empty")
	ErrWrongID         = errors.New("id error")
	ErrWrongScene      = errors.New("scene error")
	ErrWrongToken      = errors.New("token error")
	ErrExpiredToken    = errors.New("token expired")
	ErrOverrun         = errors.New("frequency overrun")
	ErrBadRequest      = errors.New("bad request")
	ErrIllegalParams   = errors.New("params error")
	ErrUnknown         = errors.New("unknown error")
	ErrInvalidResponse = errors.New("invalid response")
)

Functions

func RequestAndVerify

func RequestAndVerify(request *CaptchaRequest) bool

RequestAndVerify will request and verify captcha info, return true if pass, otherwise false

Types

type CaptchaRequest

type CaptchaRequest struct {
	VID      string `json:"id"`
	Key      string `json:"secretkey"`
	Server   string `json:"-"`
	Scene    int    `json:"scene"`
	Token    string `json:"token"`
	ClientIP string `json:"ip"`
	UserID   string `json:"userid,omitempty"`
}

func (*CaptchaRequest) Request

func (request *CaptchaRequest) Request() (*CaptchaResponse, error)

Request will send request to verify server and get response, if server is illegal, returns ErrIllegalServer,

type CaptchaResponse

type CaptchaResponse struct {
	Success int    `json:"success"`
	Score   int    `json:"score"`
	Msg     string `json:"msg"`
}

func (*CaptchaResponse) Verify

func (response *CaptchaResponse) Verify() error

Verify will verify the response and return nil if pass, otherwise errors with details For example, ErrWrongUserID, ErrIllegalParams, etc. You can find these errors in defined variables.

Jump to

Keyboard shortcuts

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