-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcheck.go
38 lines (30 loc) · 902 Bytes
/
check.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
package wlc
import (
"context"
"net/http"
)
const (
kCheckURL = "https://api.wlc.nppa.gov.cn/idcard/authentication/check"
kCheckTestURL = "https://wlc.nppa.gov.cn/test/authentication/check/"
)
func (c *client) Check(ctx context.Context, param CheckParam) (*CheckResult, error) {
return c.check(ctx, kCheckURL, param)
}
func (c *client) CheckTest(ctx context.Context, code string, param CheckParam) (*CheckResult, error) {
return c.check(ctx, kCheckTestURL+code, param)
}
func (c *client) check(ctx context.Context, api string, param CheckParam) (*CheckResult, error) {
var aux = struct {
*Error
Data struct {
Result *CheckResult `json:"result"`
} `json:"data"`
}{}
if err := c.request(ctx, http.MethodPost, api, nil, param, &aux); err != nil {
return nil, err
}
if aux.Error != nil && aux.Error.ErrCode != 0 {
return nil, aux.Error
}
return aux.Data.Result, nil
}