-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.go
More file actions
59 lines (52 loc) · 1.43 KB
/
types.go
File metadata and controls
59 lines (52 loc) · 1.43 KB
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
package main
import (
"encoding/json"
)
// Query is the request body for /endpoints/verify-captcha
// Matches the TS type Query
// request_query.signature is the HMAC signature
type Query struct {
Token string `json:"token"`
TGLogin TGLogin `json:"tglogin"`
RequestQuery RequestData `json:"request_query"`
}
type RequestData struct {
ChatID int64 `json:"chat_id,string"`
MsgID int64 `json:"msg_id,string"`
Timestamp int64 `json:"timestamp,string"`
Signature string `json:"signature"`
}
type TGUser struct {
ID int64 `json:"id"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Username string `json:"username"`
}
// TGLogin 支持动态字段
type TGLogin struct {
QueryID string `json:"query_id"`
User string `json:"user"`
AuthDate int64 `json:"auth_date,string"`
Hash string `json:"hash"`
Extra map[string]interface{} `json:"-"`
}
func (t *TGLogin) UnmarshalJSON(data []byte) error {
type Alias TGLogin
temp := &struct {
*Alias
}{Alias: (*Alias)(t)}
if err := json.Unmarshal(data, &temp); err != nil {
return err
}
var raw map[string]interface{}
if err := json.Unmarshal(data, &raw); err != nil {
return err
}
t.Extra = make(map[string]interface{})
for k, v := range raw {
if k != "query_id" && k != "user" && k != "auth_date" && k != "hash" {
t.Extra[k] = v
}
}
return nil
}