修改了手机号登陆
This commit is contained in:
@@ -3,6 +3,7 @@ package utils
|
||||
import (
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"crypto/hmac"
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
@@ -83,6 +84,16 @@ func HashString(s string) string {
|
||||
return s
|
||||
}
|
||||
|
||||
// HmacSHA256 计算 HMAC-SHA256 签名
|
||||
func HmacSHA256(data string, key string) string {
|
||||
// 创建新的 HMAC 使用 SHA256 哈希函数
|
||||
h := hmac.New(sha256.New, []byte(key))
|
||||
// 写入数据
|
||||
h.Write([]byte(data))
|
||||
// 计算 HMAC-SHA256 并返回其字节切片
|
||||
return hex.EncodeToString(h.Sum(nil))
|
||||
}
|
||||
|
||||
// 将任意长度的密钥转换为适合 AES 的长度(32 字节)
|
||||
func hashKey(key string) []byte {
|
||||
hash := sha256.Sum256([]byte(key))
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"image/jpeg"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 一些计算
|
||||
@@ -83,3 +84,26 @@ func ConvertPDFToImages(pdfPath string, outputDir string, filename string) error
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CalculateAge 计算年龄
|
||||
func CalculateAge(birthdate string) (int, error) {
|
||||
// 解析出生日期字符串
|
||||
layout := "2006-01-02 15:04:05"
|
||||
birthTime, err := time.Parse(layout, birthdate)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// 获取当前时间
|
||||
now := time.Now()
|
||||
|
||||
// 计算年龄
|
||||
years := now.Year() - birthTime.Year()
|
||||
|
||||
// 如果今年的生日还没到,年龄减一
|
||||
if now.Month() < birthTime.Month() || (now.Month() == birthTime.Month() && now.Day() < birthTime.Day()) {
|
||||
years--
|
||||
}
|
||||
|
||||
return years, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user