initial crm server

This commit is contained in:
zchengo
2022-11-28 16:38:30 +08:00
parent 61122aef6a
commit af7cd0c44c
36 changed files with 2615 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
package common
import (
"crm/global"
"strconv"
"time"
"github.com/golang-jwt/jwt/v4"
)
var signingKey = []byte(global.Config.Jwt.SigningKey)
// 生成Token
func GenToken(uid int64, expire int64) (string, error) {
username := strconv.FormatInt(uid, 20)
type Claims struct {
Username string `json:"username"`
jwt.RegisteredClaims
}
claims := Claims{username, jwt.RegisteredClaims{
ExpiresAt: &jwt.NumericDate{Time: time.Now().Add(time.Duration(expire) * time.Hour)},
Issuer: username,
}}
token, err := jwt.NewWithClaims(jwt.SigningMethodHS256, claims).SignedString(signingKey)
return token, err
}