httplib_usercenter_service.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 service_gateway
import (
"crypto/sha1"
"fmt"
"net/http"
"time"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/constant"
)
type MmmUserCenterServiceGateway struct {
httplibBaseServiceGateway
}
func NewMmmUserCenterServiceGateway() *MmmUserCenterServiceGateway {
return &MmmUserCenterServiceGateway{
httplibBaseServiceGateway{
baseURL: constant.UCENTER_HOST,
connectTimeout: 100 * time.Second,
readWriteTimeout: 30 * time.Second,
}}
}
func (gateway MmmUserCenterServiceGateway) buildHeader() http.Header {
var h = http.Header{}
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)
h.Set("Content-Type", "application/json")
h.Set("appKey", constant.UCENTER_APP_KEY)
h.Set("nonce", "")
h.Set("curTime", nowTime)
h.Set("checkSum", checksum)
h.Set("Accept", "application/json")
return h
}
type ResponseLogin struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data struct {
Id int64 `json:"id"` //统一用户中心的id,对应本系统中users表的open_id
Phone string `json:"phone"`
NickName string `json:"nickname"` //昵称
Avatar string `json:"avatar"` //头像
Imtoken string `json:"imtoken"` //网易云imtoken
Accid int64 `json:"accid"` //网易云id
CustomerAccount int64 `json:"customerAccount"` //客服id
CompanyId int64 `json:"companyId"` //总后台的公司id
Muid int64 `json:"muid"` //企业平台的用户id,对应本系统中users表的id
} `json:"data"`
}
func (gateway MmmUserCenterServiceGateway) RequestUCenterLoginBySecret(secret string) (*ResponseLogin, error) {
// param := map[string]interface{}{
// "type": 3, //登录方式 固定值
// "secret": url.QueryEscape(secret), //必要的转换
// }
// url := "/auth/serverLogin"
// httpRequest := gateway.createRequest(url, "post")
// httpRequest.
return nil, nil
}