golang 使用时间通过md5生成token

来源:互联网 发布:阿里数据库oceanbase 编辑:程序博客网 时间:2024/06/08 14:58
                                                                                                     
  1. package main  

  2.   

  3. import (  

  4.     "crypto/md5"  

  5.     "fmt"  

  6.     "io"  

  7.     "strconv"  

  8.     "time"  

  9. )  

  10.   

  11. func main() {  

  12.   

  13.     crutime := time.Now().Unix()  

  14.     fmt.Println("crutime-->", crutime)  

  15.   

  16.     h := md5.New()  

  17.     fmt.Println("h-->", h)  

  18.   

  19.     fmt.Println("strconv.FormatInt(crutime, 10)-->", strconv.FormatInt(crutime, 10))  

  20.     io.WriteString(h, strconv.FormatInt(crutime, 10))  

  21.   

  22.     fmt.Println("h-->", h)  

  23.   

  24.     token := fmt.Sprintf("%x", h.Sum(nil))  

  25.     fmt.Println("token--->", token)  

  26.   

  27.     fmt.Println(len("8e1a188743c6077110da3c9778183031"))  

  28. }  




查看原文:http://www.zoues.com/2016/10/27/golang-%e4%bd%bf%e7%94%a8%e6%97%b6%e9%97%b4%e9%80%9a%e8%bf%87md5%e7%94%9f%e6%88%90token/
0 0
原创粉丝点击