del: 移除jwt-go依赖
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
|||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"crypto/sha512"
|
"crypto/sha512"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -12,35 +11,9 @@ import (
|
|||||||
|
|
||||||
"be.ems/lib/log"
|
"be.ems/lib/log"
|
||||||
|
|
||||||
"github.com/dgrijalva/jwt-go"
|
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GenToken 生成Token值
|
|
||||||
func GenToken(mapClaims jwt.MapClaims) (string, error) {
|
|
||||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, mapClaims)
|
|
||||||
var nowDate = time.Now()
|
|
||||||
var secret = fmt.Sprintf("%v%v", nowDate, "xxxx")
|
|
||||||
return token.SignedString([]byte(secret))
|
|
||||||
}
|
|
||||||
|
|
||||||
// GenerateToken 生成Token值
|
|
||||||
func GenerateToken(mapClaims jwt.MapClaims, key string) (string, error) {
|
|
||||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, mapClaims)
|
|
||||||
return token.SignedString([]byte(key))
|
|
||||||
}
|
|
||||||
|
|
||||||
// ParseToken: "解析token"
|
|
||||||
func ParseToken(token string, secret string) (string, error) {
|
|
||||||
claim, err := jwt.Parse(token, func(token *jwt.Token) (interface{}, error) {
|
|
||||||
return []byte(secret), nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return claim.Claims.(jwt.MapClaims)["cmd"].(string), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func RandAccessToken(n int) (ret string) {
|
func RandAccessToken(n int) (ret string) {
|
||||||
allString := "52661fbd-6b84-4fc2-aa1e-17879a5c6c9b"
|
allString := "52661fbd-6b84-4fc2-aa1e-17879a5c6c9b"
|
||||||
ret = ""
|
ret = ""
|
||||||
|
|||||||
Reference in New Issue
Block a user