httplib_business-admin_service.go
1.8 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package serviceGateway
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"time"
"github.com/astaxie/beego/logs"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/constant"
)
type MmmBusinessAdminServiceGateway struct {
baseURL string
}
func NewMmmBusinessAdminServiceGateway() *MmmBusinessAdminServiceGateway {
return &MmmBusinessAdminServiceGateway{
baseURL: constant.BUSINESS_ADMIN_HOST,
}
}
type ResponseGetUserAuth struct {
UCenterCommonMsg
Data struct {
UserAuth bool `json:"userAuth"`
} `json:"data"`
}
func (gateway MmmBusinessAdminServiceGateway) httpDo(reqURL string, mathod string, bodyData interface{}) ([]byte, error) {
httpclient := http.Client{
Timeout: 60 * time.Second, //请求超时时间60秒
}
bt := &bytes.Buffer{}
if bodyData != nil {
enc := json.NewEncoder(bt)
enc.Encode(bodyData)
}
logs.Info("====>Send To URL:%s", reqURL)
logs.Info("====>Send To BusinessAdmin:%s", bt.String())
req, err := http.NewRequest(mathod, reqURL, bt)
if err != nil {
return nil, err
}
resp, err := httpclient.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
logs.Info("<====BusinessAdmin Return:%s", string(body))
return body, nil
}
func (gateway MmmBusinessAdminServiceGateway) GetUserAuth(userId int64) (*ResponseGetUserAuth, error) {
param := map[string]interface{}{
"userId": userId,
"platformId": 25,
}
url := gateway.baseURL + "/auth/get-user-auth"
byteData, err := gateway.httpDo(url, "POST", param)
if err != nil {
return nil, err
}
respData := &ResponseGetUserAuth{}
err = json.Unmarshal(byteData, respData)
if err != nil {
return nil, fmt.Errorf("body data %s; err:%s", string(byteData), err)
}
return respData, nil
}