dddd
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.

87 lines
1.8 KiB

package commonus
4 years ago
import (
"crypto/md5"
4 years ago
"crypto/rand"
"fmt"
4 years ago
"math/big"
"strconv"
"time"
"github.com/flipped-aurora/gin-vue-admin/server/global"
4 years ago
)
// import (
// "crypto/md5"
// "exam_server/config"
// "fmt"
// )
// func Md5(str string, key ...string) string {
// key_val := config.AppConfig.AppKey
// if len(key) > 0 {
// key_val = key[0]
// }
// str = str + key_val
// data := []byte(str)
// has := md5.Sum(data)
// md5str1 := fmt.Sprintf("%x", has) //将[]byte转成16进制
// return md5str1
// }
4 years ago
//获取编号(副本)
func GetFileNumberEs() (num int64) {
// esult, _ := rand.Int(rand.Reader, big.NewInt(100))
result, _ := rand.Int(rand.Reader, big.NewInt(10000))
4 years ago
result64 := result.Int64()
// timeVal := time.Now().Unix()
timeVal := time.Now().UnixNano() / 1e6
num, _ = strconv.ParseInt(strconv.FormatInt(timeVal, 10)+strconv.FormatInt(result64, 10), 10, 64)
return
}
/*
*加密算法
*/
type Md5Encryption struct {
Code string `json:"code"`
AppKey string `json:"appKey"`
}
func (m *Md5Encryption) Md5EncryptionAlgorithm() (md5Val string) {
if m.AppKey == "" {
m.Md5EncryptionInit(m.Code)
}
// fmt.Printf("Code ====> %v\n", m.Code)
// fmt.Printf("AppKey ====> %v\n", m.AppKey)
mdNew := md5.New()
mdNew.Write([]byte(m.AppKey))
keyMd5 := fmt.Sprintf("%x", mdNew.Sum(nil))
codeNewMd1 := md5.New()
codeNewMd1.Write([]byte(m.Code))
codeMd1 := fmt.Sprintf("%x", codeNewMd1.Sum(nil))
yiCeng := codeMd1 + keyMd5
yiCengNew := md5.New()
yiCengNew.Write([]byte(yiCeng))
yiCengMd5 := fmt.Sprintf("%x", yiCengNew.Sum(nil))
erCeng := yiCengMd5 + m.AppKey
erCengNew := md5.New()
erCengNew.Write([]byte(erCeng))
md5Val = fmt.Sprintf("%x", erCengNew.Sum(nil))
// md5Val = codeMd1
return
}
//初始化程序
func (m *Md5Encryption) Md5EncryptionInit(code string) {
m.AppKey = global.GVA_CONFIG.MyConfig.AppKey
m.Code = code
}