httplib_ucenter_service_gateway.go
2.1 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
package serviceGateway
import (
"crypto/sha1"
"fmt"
"net/http"
"net/url"
"strconv"
"strings"
"time"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/serviceGateway/reply"
)
type HttpLibUCenterApiServiceGateway struct {
httpLibBaseServiceGateway
}
func (serviceGateway *HttpLibUCenterApiServiceGateway) buildHeaders() map[string]string {
nowTime := fmt.Sprint(time.Now().Unix())
str := fmt.Sprintf("%s%s%s", nowTime, constant.UCENTER_SECRET, constant.UCENTER_CHECK_ALT)
bt := sha1.Sum([]byte(str))
checksum := fmt.Sprintf("%x", bt)
return map[string]string{
"appKey": constant.UCENTER_APP_KEY,
"nonce": "",
"curTime": nowTime,
"checkSum": checksum,
}
}
// AuthCode PC端登录, 为后台单点登录
func (serviceGateway *HttpLibUCenterApiServiceGateway) AuthCode(code string) (*reply.UCenterAuthCode, error) {
authCodeReply := &reply.UCenterAuthCode{}
serviceGateway.CreateRequest(http.MethodPost, "/auth/serverLogin")
serviceGateway.SetBody(map[string]interface{}{
"type": 3,
"secret": url.QueryEscape(code),
})
serviceGateway.SetHeaders(serviceGateway.buildHeaders())
err := serviceGateway.ToJson(authCodeReply)
return authCodeReply, err
}
// AuthCode 手机应用端登录, 为token登录,app登录
func (serviceGateway *HttpLibUCenterApiServiceGateway) AppAuthCode(tokenCode string, uid int, companyId int) (*reply.UCenterAuthCode, error) {
authCodeReply := &reply.UCenterAuthCode{}
serviceGateway.CreateRequest(http.MethodPost, "/auth/serverLogin")
serviceGateway.SetBody(map[string]interface{}{
"type": 2,
"token": strings.TrimSpace(tokenCode),
"uid": strconv.Itoa(uid),
"companyId": strconv.Itoa(companyId),
})
serviceGateway.SetHeaders(serviceGateway.buildHeaders())
err := serviceGateway.ToJson(authCodeReply)
return authCodeReply, err
}
func NewHttpLibUCenterApiServiceGateway() *HttpLibUCenterApiServiceGateway {
return &HttpLibUCenterApiServiceGateway{
httpLibBaseServiceGateway{baseURL: constant.UCENTER_SERVICE_HOST},
}
}