-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathaccount.go
108 lines (95 loc) · 2.74 KB
/
account.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
105
106
107
108
package gofofa
import "encoding/json"
// DeductMode should deduct fcoin automatically or just use free limit
type DeductMode int
const (
// DeductModeFree only use free limit size
DeductModeFree DeductMode = 0
// DeductModeFCoin deduct fcoin automatically if account has fcoin
DeductModeFCoin DeductMode = 1
)
// ParseDeductMode parse string to DeductMode
func ParseDeductMode(v string) DeductMode {
switch v {
case "0", "DeductModeFree":
return DeductModeFree
case "1", "DeductModeFCoin":
return DeductModeFCoin
default:
panic("unknown deduct mode")
}
}
type VipLevel int
const (
VipLevelNone VipLevel = 0 // 注册用户
VipLevelNormal VipLevel = 1 // 普通会员
VipLevelAdvanced VipLevel = 2 // 高级会员
VipLevelEnterprise VipLevel = 3 // 企业版
VipLevelEnterprise2 VipLevel = 5 // 企业版
)
const (
VipLevelSubPersonal VipLevel = 11 // 订阅个人
VipLevelSubPro VipLevel = 12 // 订阅专业
VipLevelSubBuss VipLevel = 13 // 订阅商业版
)
const (
VipLevelRed VipLevel = 20 // 红队版
VipLevelStudent VipLevel = 22 // 教育账户
VipLevelNever VipLevel = 100 // 不可能的等级
)
// AccountInfo fofa account info
type AccountInfo struct {
Error bool `json:"error"` // error or not
ErrMsg string `json:"errmsg,omitempty"` // error string message
FCoin int `json:"fcoin"` // fcoin count
FofaPoint int64 `json:"fofa_point"` // fofa point
IsVIP bool `json:"isvip"` // is vip
VIPLevel VipLevel `json:"vip_level"` // vip level
RemainApiQuery int `json:"remain_api_query"` // available query
RemainApiData int `json:"remain_api_data"` // available data amount
}
func (ai AccountInfo) String() string {
d, _ := json.MarshalIndent(ai, "", " ")
return string(d)
}
// AccountInfo fetch account info from fofa
func (c *Client) AccountInfo() (ac AccountInfo, err error) {
err = c.Fetch("info/my", nil, &ac)
return
}
// freeSize 获取可以免费使用的数据量
func (c *Client) freeSize() int {
if !c.Account.IsVIP {
// 不是会员有
return 0
}
switch c.Account.VIPLevel {
//case 0: // 上面已经退出了
// return 0
case VipLevelNormal:
return 100
case VipLevelAdvanced:
return 10000
case VipLevelEnterprise, VipLevelEnterprise2:
return 100000
case VipLevelRed:
return 10000
case VipLevelStudent:
return 10000
// 订阅用户:通过 api 查询余额
case VipLevelSubPersonal:
fallthrough
case VipLevelSubPro:
fallthrough
case VipLevelSubBuss:
info, err := c.AccountInfo()
if err != nil {
info = c.Account
}
if info.RemainApiQuery > 0 {
return info.RemainApiData
}
}
// other level, ignore free limit check
return -1
}