123456789101112131415161718192021222324252627282930313233343536 |
- package main
- import (
- "sparrow/pkg/models"
- "time"
- jwt "github.com/dgrijalva/jwt-go"
- )
- const SignedString = "www.yehaoji.com"
- type AppClaims struct {
- AppID uint
- AppName string
- AppKey string
- SecretKey string
- VendorID uint
- jwt.StandardClaims
- }
- // TokenMaker 生成token
- func TokenMaker(app *models.Application) string {
- claims := AppClaims{
- AppID: app.ID,
- AppName: app.AppName,
- AppKey: app.AppKey,
- SecretKey: app.SecretKey,
- VendorID: app.VendorID,
- }
- claims.ExpiresAt = time.Now().Add(time.Hour * 24).Unix()
- claims.IssuedAt = time.Now().Unix()
- claims.Issuer = "apiprovider"
- token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
- ser, _ := token.SignedString([]byte(SignedString))
- return ser
- }
|