@@ -11,8 +11,8 @@ import (
1111const arcaptchaApi = "https://arcaptcha.ir/2/siteverify"
1212
1313type Website struct {
14- SiteKey string `json:"site_key"`
15- SecretKey string `json:"secret_key"`
14+ SiteKey string
15+ SecretKey string
1616}
1717
1818func NewWebsite (siteKey , secretKey string ) * Website {
@@ -21,7 +21,8 @@ func NewWebsite(siteKey, secretKey string) *Website {
2121 SecretKey : secretKey ,
2222 }
2323}
24- func (w * Website ) ValidateCaptcha (challengeID string ) error {
24+
25+ func (w * Website ) ValidateCaptcha (challengeID string ) (success bool , err error ) {
2526
2627 data := & verifyCaptchaRequest {
2728 SiteKey : w .SiteKey ,
@@ -30,7 +31,7 @@ func (w *Website) ValidateCaptcha(challengeID string) error {
3031 }
3132 bin , err := json .Marshal (data )
3233 if err != nil {
33- return err
34+ return
3435 }
3536
3637 req , err := http .NewRequest (
@@ -39,32 +40,30 @@ func (w *Website) ValidateCaptcha(challengeID string) error {
3940 bytes .NewBuffer (bin ),
4041 )
4142 if err != nil {
42- return err
43+ return
4344 }
4445
4546 req .Header .Add ("Content-Type" , "application/json" )
4647 req .Header .Add ("Content-Length" , strconv .Itoa (len (string (bin ))))
4748
4849 res , err := http .DefaultClient .Do (req )
4950 if err != nil {
50- return err
51+ return
5152 }
5253 defer func () {
5354 _ = res .Body .Close ()
5455 }()
5556
5657 bin , err = ioutil .ReadAll (res .Body )
5758 if err != nil {
58- return err
59- }
60- var errRes Error
61- if err = json .Unmarshal (bin , & errRes ); err != nil {
62- return err
59+ return
6360 }
6461
65- if res .StatusCode != http .StatusOK {
66- return errRes
62+ var response VerifyCaptchaResponse
63+ if err = json .Unmarshal (bin , & response ); err != nil {
64+ return
6765 }
68- return nil
6966
67+ success = response .Success
68+ return
7069}
0 commit comments