You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
646 B
28 lines
646 B
package session |
|
|
|
import ( |
|
"encoding/base64" |
|
"sig-pub/api/pb" |
|
"sig-pub/pkg/utils/security" |
|
"time" |
|
|
|
"google.golang.org/protobuf/proto" |
|
) |
|
|
|
func NewRpcSubject(userId int64, account string, extra map[string]string) (subject *pb.RpcSubject) { |
|
subject = &pb.RpcSubject{Uid: userId, Account: account, Time: time.Now().UnixMilli(), Extra: extra} |
|
return |
|
} |
|
|
|
func RpcSubjectGenToken(aesKey []byte, subject *pb.RpcSubject) (token string, err error) { |
|
bytes, err := proto.Marshal(subject) |
|
if err != nil { |
|
return |
|
} |
|
t, err := security.EncryptAesCBC(bytes, aesKey) |
|
if err != nil { |
|
return |
|
} |
|
token = base64.URLEncoding.EncodeToString(t) |
|
return |
|
}
|
|
|