generated from oklookat/gostarter
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2_validatePhone.go
62 lines (51 loc) · 1.39 KB
/
2_validatePhone.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
package vkmauth
import (
"context"
"fmt"
)
func validatePhone(ctx context.Context, phone, sid string, by *anonymousToken) (*validatePhoneResponse, error) {
form := map[string]string{
"access_token": by.Token,
"device_id": by.DeviceId,
"phone": phone,
"supported_ways": _authSupportedWays.Join(","),
"sak_version": _sakVersion,
"v": _apiVersion,
"api_id": _apiId,
}
if len(sid) > 0 {
form["sid"] = sid
}
result := &validatePhoneResponse{}
cl := getClient()
resp, err := cl.R().
SetFormUrlMap(form).
SetResult(&result).
Post(ctx, _vkApiUrl+"/method/auth.validatePhone")
if err != nil {
return nil, err
}
if result.IsError() {
return nil, result
}
if resp.IsError() {
return nil, newError(fmt.Sprintf("%d", resp.StatusCode), "validatePhone resp.IsError()")
}
return result, err
}
type validatePhoneResponse struct {
ResponseWithError
Response struct {
// "general"?
Type string `json:"type"`
// Session ID?
Sid string `json:"sid"`
Delay int `json:"delay"`
LibverifySupport bool `json:"libverify_support"`
// Type code by this way.
ValidationType AuthSupportedWay `json:"validation_type"`
// If resend, code will be resended by this way.
ValidationResend AuthSupportedWay `json:"validation_resend"`
CodeLength int `json:"code_length"`
} `json:"response"`
}