httplib_ucenter_service_gateway.go
1.4 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
package serviceGateway
import (
"crypto/sha1"
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/serviceGateway/reply"
"net/http"
"net/url"
"time"
)
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
}
func NewHttpLibUCenterApiServiceGateway() *HttpLibUCenterApiServiceGateway {
return &HttpLibUCenterApiServiceGateway{
httpLibBaseServiceGateway{baseURL: constant.UCENTER_SERVICE_HOST},
}
}