54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package robot
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/utils"
|
|
"log"
|
|
"time"
|
|
|
|
jsoniter "github.com/json-iterator/go"
|
|
"github.com/nacos-group/nacos-sdk-go/util"
|
|
)
|
|
|
|
type LoginParam struct {
|
|
Account string `json:"account"`
|
|
ServerId int `json:"serverId"`
|
|
TimeStamp int64 `json:"timestamp"`
|
|
}
|
|
|
|
func (r *Robot) BuildSecStr() string {
|
|
jsonByte, _ := jsoniter.Marshal(&LoginParam{
|
|
Account: r.opts.Account,
|
|
ServerId: r.opts.ServerId,
|
|
TimeStamp: time.Now().Unix(),
|
|
})
|
|
jsonBase64 := utils.Base64Encode(jsonByte)
|
|
// log.Printf("client base64:%s", jsonBase64)
|
|
clientMd5key := util.Md5(jsonBase64)
|
|
// log.Printf("client md5:%s", clientMd5key)
|
|
return fmt.Sprintf("CE:%s%s", clientMd5key, jsonBase64)
|
|
}
|
|
|
|
//处理登录请求
|
|
func (r *Robot) AccountLogin() {
|
|
//登录
|
|
sec := r.BuildSecStr()
|
|
// log.Printf("client secret key:%s", sec)
|
|
loginReg := &pb.UserLoginReq{
|
|
Sec: sec,
|
|
}
|
|
|
|
head := &pb.UserMessage{
|
|
MainType: "user",
|
|
SubType: "login",
|
|
}
|
|
defer traceFunc(head.MainType, head.SubType, "0", loginReg)
|
|
err := r.SendToClient(head, loginReg)
|
|
if err != nil {
|
|
log.Fatalf("send err:%v", err)
|
|
}
|
|
|
|
log.Printf("account:[%s] login...", r.opts.Account)
|
|
}
|