-
Notifications
You must be signed in to change notification settings - Fork 0
/
ip.go
104 lines (99 loc) · 2.56 KB
/
ip.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package AossGoSdk
import (
"errors"
jsoniter "github.com/json-iterator/go"
Net "github.com/tobycroft/TuuzNet"
)
type IP struct {
Token string
Code string
}
func (self *IP) IpRange(country any, province []any, ip any) (bool, error) {
province_json, err := jsoniter.MarshalToString(province)
if err != nil {
return false, err
}
param := map[string]any{
"country": country,
"province": province_json,
"ip": ip,
"token": self.Token,
}
ret, err := Net.Post(baseUrl+"/v1/ip/range/check", nil, param, nil, nil)
//fmt.Println(ret, err)
if err != nil {
return false, err
} else {
var rs ret_std
errs := jsoniter.UnmarshalFromString(ret, &rs)
if errs != nil {
return false, errors.New(ret)
} else {
if rs.Code == 0 {
return true, nil
} else {
return false, errors.New(rs.Echo)
}
}
}
}
// IpRangeAuth this will check the ip is in the ip range of the country and province,if not it will needs client to complete the captcha check, this is recommended to be used if you are running a sms services
func (self *IP) IpRangeAuth(country any, province []any, ip any) (bool, error) {
province_json, err := jsoniter.MarshalToString(province)
if err != nil {
return false, err
}
param := map[string]any{
"country": country,
"province": province_json,
"ip": ip,
"token": self.Token,
}
ret, err := Net.Post(baseUrl+"/v1/ip/range/auth", nil, param, nil, nil)
//fmt.Println(ret, err)
if err != nil {
return false, err
} else {
var rs ret_std
errs := jsoniter.UnmarshalFromString(ret, &rs)
if errs != nil {
return false, errors.New(ret)
} else {
if rs.Code == 0 {
return true, nil
} else {
return false, errors.New(rs.Echo)
}
}
}
}
// IpRangeCaptcha This function is pretty similar to IpRangeAuth, but it will return the response code like CheckWithCode, when the code is -103 means it needs to complete the captcha check
func (self *IP) IpRangeCaptcha(country any, province []any, ip any) (int64, error) {
province_json, err := jsoniter.MarshalToString(province)
if err != nil {
return 400, err
}
param := map[string]any{
"country": country,
"province": province_json,
"ip": ip,
"token": self.Token,
}
ret, err := Net.Post(baseUrl+"/v1/ip/range/auth", nil, param, nil, nil)
//fmt.Println(ret, err)
if err != nil {
return 200, err
} else {
var rs ret_std
errs := jsoniter.UnmarshalFromString(ret, &rs)
if errs != nil {
return 500, errors.New(ret)
} else {
if rs.Code == 0 {
return rs.Code, nil
} else {
return rs.Code, errors.New(rs.Echo)
}
}
}
}