Skip to content

Commit 0b11258

Browse files
authored
Merge pull request #1 from arcaptcha/co_version
Co version
2 parents 70ee035 + 99a54e6 commit 0b11258

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ Register on [Arcaptcha](https://arcaptcha.ir/), create website and get your own
2323

2424
```go
2525
website := arcaptcha.NewWebsite("YOUR_SITE_KEY", "YOUR_SECRET_KEY")
26-
//'arcaptcha-token' is created for each captcha
27-
//After you put captcha widget in your website, you can get 'arcaptcha-token' from form
28-
result, err := website.Verify("arcaptcha-token")
26+
//'arcaptcha-response' is created for each captcha
27+
//After you put captcha widget in your website, you can get 'arcaptcha-response' from form
28+
result, err := website.Verify("arcaptcha-response")
2929
if err != nil {
3030
// error in sending or receiving API request
3131
// handle error
@@ -66,8 +66,8 @@ func handler(w http.ResponseWriter, r *http.Request) {
6666
func verifyCaptcha(next http.Handler) http.Handler {
6767
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
6868
r.ParseForm()
69-
token := r.FormValue("arcaptcha-token")
70-
result, err := website.Verify(token)
69+
response := r.FormValue("arcaptcha-response")
70+
result, err := website.Verify(response)
7171
if err != nil {
7272
// error in sending or receiving API request
7373
// handle error

arcaptcha.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,27 @@ import (
88
)
99

1010
// arcaptchaApi arcaptcha verify API for captcha V2
11-
const arcaptchaApi = "https://arcaptcha.ir/2/siteverify"
11+
const arcaptchaApi = "https://arcaptcha.co/2/siteverify"
1212

1313
type Website struct {
1414
SiteKey string
1515
SecretKey string
1616
}
1717

1818
type verifyReq struct {
19-
SiteKey string `json:"site_key"`
20-
SecretKey string `json:"secret_key"`
21-
ChallengeID string `json:"challenge_id"`
19+
SiteKey string `json:"sitekey"`
20+
SecretKey string `json:"secret"`
21+
Response string `json:"response"`
22+
RemoteIp string `json:"remoteip"`
2223
}
2324

2425
// VerifyResp represents verify API response
2526
// error codes are available in https://docs.arcaptcha.ir/en/API/Verify
2627
type VerifyResp struct {
27-
Success bool `json:"success"`
28-
ErrorCodes []string `json:"error-codes"`
28+
Success bool `json:"success"`
29+
ChallengeTS string `json:"challenge_ts,omitempty"`
30+
Hostname string `json:"hostname,omitempty"`
31+
ErrorCodes []string `json:"error-codes,omitempty"`
2932
}
3033

3134
// NewWebsite creates a new Website
@@ -40,11 +43,11 @@ func NewWebsite(siteKey, secretKey string) *Website {
4043
//
4144
// if an error occurs while sending or receiving the request, returns error.
4245
// server side errors are available in VerifyResp.ErrorCodes.
43-
func (w *Website) Verify(token string) (VerifyResp, error) {
46+
func (w *Website) Verify(response string) (VerifyResp, error) {
4447
data := &verifyReq{
45-
SiteKey: w.SiteKey,
46-
SecretKey: w.SecretKey,
47-
ChallengeID: token,
48+
SiteKey: w.SiteKey,
49+
SecretKey: w.SecretKey,
50+
Response: response,
4851
}
4952
var resp VerifyResp
5053
err := sendRequest(http.MethodPost, arcaptchaApi, data, &resp)

examples/demo.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<html lang="en">
44
<head>
55
<meta charset="UTF-8">
6-
<title>Go Package Demo</title>
6+
<title>ARCaptcha Go Demo</title>
77
<script src="https://widget.arcaptcha.ir/2/api.js"></script>
88
</head>
99
<body>

examples/example.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ func handleDemo(w http.ResponseWriter, r *http.Request) {
4141
submitted := r.FormValue("submitted")
4242
if submitted != "" {
4343
// verify captcha
44-
token := r.FormValue("arcaptcha-token")
45-
result, err := website.Verify(token)
44+
response := r.FormValue("arcaptcha-response")
45+
result, err := website.Verify(response)
4646
if err != nil {
4747
log.Fatal(err)
4848
}

0 commit comments

Comments
 (0)