package handler import ( "context" "fmt" "goproduct/common" "goproduct/domain/model" "goproduct/domain/service" "goproduct/proto" "log" "time" ) type User struct { UserDataService service.IUserDataService } // 登录 (clientId int32, phone string, systemId int32, verifi func (u *User) Login(ctx context.Context, loginRequest *proto.LoginRequest, loginResp *proto.LoginResp) error { userInfo, err := u.UserDataService.Login(loginRequest.ClientId, loginRequest.GetPhone(), loginRequest.SystemId, loginRequest.VerificationCode) if err != nil { return err } fmt.Println(">>>>>>>>>>>>> login success :", userInfo) UserForResp(userInfo, loginResp) return nil } func UserForResp(userModel *model.User, resp *proto.LoginResp) *proto.LoginResp { timeStr := fmt.Sprintf("%d", time.Now().Unix()) resp.Token = common.Md5Encode(timeStr) //"123456" resp.User = &proto.User{} log.Println(userModel) resp.User.Id = userModel.ID resp.User.Avatar = userModel.Avatar resp.User.ClientId = userModel.ClientId resp.User.EmployeeId = 1 //userModel.EmployeeId resp.User.Nickname = userModel.Nickname resp.User.SessionId = resp.Token resp.User.Phone = userModel.Phone //token 过期时间 tp, _ := time.ParseDuration("1h") tokenExpireTime := time.Now().Add(tp) expiretimeStr := tokenExpireTime.Format("2006-01-02 15:04:05") resp.User.TokenExpireTime = expiretimeStr resp.User.UnionId = userModel.UnionId return resp }