58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
package robot
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/utils"
|
|
"log"
|
|
"time"
|
|
|
|
jsoniter "github.com/json-iterator/go"
|
|
"github.com/nacos-group/nacos-sdk-go/util"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
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",
|
|
}
|
|
if comm.ProtoEncode(loginReg, head) {
|
|
data, _ := proto.Marshal(head)
|
|
err := r.SendToClient(data)
|
|
if err != nil {
|
|
log.Fatalf("send err:%v", err)
|
|
}
|
|
}
|
|
|
|
log.Printf("%s login ", r.Opts.Account)
|
|
}
|