httplib_business_admin_service_gateway.go
1.7 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 svr
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
"strconv"
"strings"
"time"
)
type HttplibBusinessAdminApiServiceGateway struct {
httplibBaseServiceGateway
}
// 服务登录
func (serviceGateway *HttplibBusinessAdminApiServiceGateway) UserAuth(userId int64, platformId string) (int, error) {
url := strings.Join([]string{serviceGateway.baseURL, "auth", "get-user-auth"}, "/")
request := serviceGateway.createRequest(url, "post")
request.Header("appKey", constant.UCENTER_APP_KEY)
options := make(map[string]interface{})
options["userId"] = fmt.Sprintf("%v", userId)
options["platformId"] = fmt.Sprintf("%v", platformId)
request.JSONBody(options)
response := make(map[string]interface{})
err := request.ToJSON(&response)
if err != nil {
log.Error("Service Gateway Fail:", err)
return 0, err
}
return serviceGateway.handlerError(response)
}
func (serviceGateway *HttplibBusinessAdminApiServiceGateway) handlerError(in map[string]interface{}) (int, error) {
var rspCode int
var err error
if code, ok := in["code"]; ok {
rspCode, _ = strconv.Atoi(fmt.Sprintf("%v", code))
} else {
err = fmt.Errorf("网关解析错误")
}
if msg, ok := in["msg"]; ok {
msg := msg.(string)
if rspCode != 0 && len(msg) > 0 {
err = fmt.Errorf(msg)
}
}
return rspCode, err
}
func NewHttplibBusinessAdminApiServiceGateway() *HttplibBusinessAdminApiServiceGateway {
return &HttplibBusinessAdminApiServiceGateway{
httplibBaseServiceGateway: httplibBaseServiceGateway{
baseURL: constant.BUSINESS_ADMIN_SERVICE_HOST,
connectTimeout: 100 * time.Second,
readWriteTimeout: 30 * time.Second,
},
}
}