zhangmeng
2024-01-19 01dfd9dc8de7b19f9dfa4284722e01bbd5837801
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package bhomedbapi
 
import (
    jsoniter "github.com/json-iterator/go"
)
 
type UserApi struct {
}
 
func (api UserApi) Login(username string, password string) (bool, interface{}) {
    url := "/data/api-u/sys/login"
    netNode := getNetNode(url2Topic(Topic_System_Service, url))
    client := NewClient(WithNodes(netNode))
    paramBody := make(map[string]interface{}, 0)
    paramBody["username"] = username
    paramBody["password"] = password
    respBody, err := client.DoPostRequest(url, CONTENT_TYPE_FORM, paramBody, nil, nil)
    if err != nil {
        return false, nil
    }
    var json = jsoniter.ConfigCompatibleWithStandardLibrary
    var res Result
    if err = json.Unmarshal(respBody, &res); err != nil {
        return false, nil
    }
    return res.Success, res.Data
}
 
func (api UserApi) FindAllUser(curUserId string) (bool, interface{}) {
    url := "/data/api-u/users/findAllUser"
    netNode := getNetNode(url2Topic(Topic_System_Service, url))
    client := NewClient(WithNodes(netNode))
    query := map[string]string{
        "userId": curUserId,
    }
    body, err := client.DoGetRequest(url, query, nil)
    if err != nil {
        return false, nil
    }
 
    var json = jsoniter.ConfigCompatibleWithStandardLibrary
    var res Result
    if err = json.Unmarshal(body, &res); err != nil {
        return false, nil
    }
    return true, res.Data
}
 
func (api UserApi) FindById(userId string) (bool, interface{}) {
    url := "/data/api-u/users/findById"
    netNode := getNetNode(url2Topic(Topic_System_Service, url))
    client := NewClient(WithNodes(netNode))
    paramBody := map[string]interface{}{
        "userId": userId,
    }
    respBody, err := client.DoPostRequest(url, CONTENT_TYPE_FORM, paramBody, nil, nil)
    if err != nil {
        return false, nil
    }
    var json = jsoniter.ConfigCompatibleWithStandardLibrary
    var res Result
    if err = json.Unmarshal(respBody, &res); err != nil {
        return false, nil
    }
    return res.Success, res.Data
}
 
func (api UserApi) GetUserProfile(userId string) (bool, interface{}) {
    url := "/data/api-u/users/profile"
    netNode := getNetNode(url2Topic(Topic_System_Service, url))
    client := NewClient(WithNodes(netNode))
    header := map[string]string{
        "Login_user_id": userId,
    }
    respBody, err := client.DoGetRequest(url, nil, header)
    if err != nil {
        return false, nil
    }
    var json = jsoniter.ConfigCompatibleWithStandardLibrary
    var res Result
    if err = json.Unmarshal(respBody, &res); err != nil {
        return false, nil
    }
    return res.Success, res.Data
}
 
func (api UserApi) SaveAuth(paramBody map[string]interface{}) (bool, interface{}) {
    url := "/data/api-u/users/saveAuth"
    netNode := getNetNode(url2Topic(Topic_System_Service, url))
    client := NewClient(WithNodes(netNode))
    respBody, err := client.DoPostRequest(url, CONTENT_TYPE_JSON, paramBody, nil, nil)
    if err != nil {
        return false, nil
    }
    var json = jsoniter.ConfigCompatibleWithStandardLibrary
    var res Result
    if err = json.Unmarshal(respBody, &res); err != nil {
        return false, nil
    }
    return res.Success, res.Data
}
 
func (api UserApi) UpdatePwd(userId string, oldPwd string, newPwd string) (bool, interface{}) {
    url := "/data/api-u/users/updatePwd"
    netNode := getNetNode(url2Topic(Topic_System_Service, url))
    client := NewClient(WithNodes(netNode))
    paramBody := map[string]interface{}{
        "userId": userId,
        "oldPwd": oldPwd,
        "newPwd": newPwd,
    }
    respBody, err := client.DoPostRequest(url, CONTENT_TYPE_FORM, paramBody, nil, nil)
    if err != nil {
        return false, nil
    }
    var json = jsoniter.ConfigCompatibleWithStandardLibrary
    var res Result
    if err = json.Unmarshal(respBody, &res); err != nil {
        return false, nil
    }
    return res.Success, res.Data
}