token_test.go 733 B

12345678910111213141516171819202122232425262728293031
  1. package token
  2. import (
  3. "fmt"
  4. "testing"
  5. cherryCrypto "github.com/cherry-game/cherry/extend/crypto"
  6. )
  7. func TestAll(t *testing.T) {
  8. openId := "open_id_001"
  9. appKey := "app_key_abc"
  10. token := New(1, openId, appKey)
  11. fmt.Println(token)
  12. base64 := token.ToBase64()
  13. fmt.Println(base64)
  14. tokenString, _ := cherryCrypto.Base64Decode(base64)
  15. fmt.Println(tokenString)
  16. validateResult, ok := Validate(token, appKey)
  17. fmt.Println(validateResult, ok)
  18. }
  19. func TestTokenBase64(t *testing.T) {
  20. base64 := "eyJwbGF0Zm9ybV9pZCI6MjEyMjAwMywib3Blbl9pZCI6IjcxNjA5OTE5NjMwOTk5NTUyIiwidHQiOjE2MjY1MTk1MzAsImhhc2giOiIwMmIyYjY4ZDUxODY4MzliZDA2NGEzNDViN2UxNDFlYSJ9"
  21. tokenString, _ := cherryCrypto.Base64Decode(base64)
  22. fmt.Println(tokenString)
  23. }