广告平台(站长使用)
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.
 
 
 
 
 

29 line
586 B

  1. package youlianghui
  2. import (
  3. "crypto/sha1"
  4. "encoding/base64"
  5. "fmt"
  6. "strconv"
  7. "strings"
  8. "time"
  9. )
  10. // GetToken 获取token
  11. func GetToken(memberId, secret string) (token string) {
  12. timestamp := strconv.FormatInt(time.Now().Unix(), 10) // 时间戳,精确到秒
  13. // 计算签名
  14. hash := sha1.New()
  15. hash.Write([]byte(memberId + secret + timestamp))
  16. sign := fmt.Sprintf("%x", hash.Sum(nil))
  17. // 构建列表
  18. listV := []string{memberId, timestamp, sign}
  19. plain := strings.Join(listV, ",")
  20. // 编码为Base64
  21. token = base64.StdEncoding.EncodeToString([]byte(plain))
  22. return
  23. }