|
|
|
|
package publicapi
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"appPlatform/middleware/grocerystore"
|
|
|
|
|
"appPlatform/models/modelshr"
|
|
|
|
|
"appPlatform/overall"
|
|
|
|
|
"appPlatform/overall/publicmethod"
|
|
|
|
|
"fmt"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
"unicode"
|
|
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
"github.com/mitchellh/mapstructure"
|
|
|
|
|
"github.com/mozillazg/go-pinyin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
@ 作者: 秦东
|
|
|
|
|
@ 时间: 2023-07-05 11:41:12
|
|
|
|
|
@ 功能:获取汉字首字母
|
|
|
|
|
@ 参数
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
@ 返回值
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
@ 方法原型
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
*/
|
|
|
|
|
func (a *ApiMethod) ChineseInitial(c *gin.Context) {
|
|
|
|
|
var requestData publicmethod.PublicName
|
|
|
|
|
err := c.ShouldBindJSON(&requestData)
|
|
|
|
|
if err != nil {
|
|
|
|
|
publicmethod.Result(100, err, c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if requestData.Name == "" {
|
|
|
|
|
publicmethod.Result(1, requestData.Name, c, "请输入关键字!")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
var wordStr string
|
|
|
|
|
for _, v := range requestData.Name {
|
|
|
|
|
if unicode.Is(unicode.Han, v) {
|
|
|
|
|
firstWord := publicmethod.ChineseFirstWordCapitalize(fmt.Sprintf("%c", v))
|
|
|
|
|
smallWord := strings.ToLower(firstWord)
|
|
|
|
|
// fmt.Printf("sddff--->%v----------->%v\n", firstWord, smallWord)
|
|
|
|
|
wordStr = fmt.Sprintf("%v%v", wordStr, smallWord)
|
|
|
|
|
} else {
|
|
|
|
|
wordStr = fmt.Sprintf("%v%c", wordStr, v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
// fmt.Printf("请输入关键字!----->%v\n", wordStr)
|
|
|
|
|
// firstWord := publicmethod.ChineseFirstWordCapitalize(requestData.Name)
|
|
|
|
|
// smallWord := strings.ToLower(firstWord)
|
|
|
|
|
var keyField string
|
|
|
|
|
jbq := 0
|
|
|
|
|
for _, kj := range wordStr {
|
|
|
|
|
if jbq < 1 {
|
|
|
|
|
if !unicode.IsNumber(kj) {
|
|
|
|
|
jbq++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if jbq > 0 {
|
|
|
|
|
keyField = fmt.Sprintf("%v%c", keyField, kj)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
publicmethod.Result(0, keyField, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
@ 作者: 秦东
|
|
|
|
|
@ 时间: 2023-07-07 09:27:19
|
|
|
|
|
@ 功能: 输出编号
|
|
|
|
|
@ 参数
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
@ 返回值
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
@ 方法原型
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
*/
|
|
|
|
|
func (a *ApiMethod) SendNumber(c *gin.Context) {
|
|
|
|
|
var requestData publicmethod.CommonId[int64]
|
|
|
|
|
err := c.ShouldBindJSON(&requestData)
|
|
|
|
|
if err != nil {
|
|
|
|
|
requestData.Id = 9
|
|
|
|
|
}
|
|
|
|
|
if requestData.Id == 0 {
|
|
|
|
|
requestData.Id = 9
|
|
|
|
|
}
|
|
|
|
|
uuid := publicmethod.GetUUid(requestData.Id)
|
|
|
|
|
var sendCont SendUUID
|
|
|
|
|
sendCont.UuId = uuid
|
|
|
|
|
sendCont.UuIdString = strconv.FormatInt(uuid, 10)
|
|
|
|
|
publicmethod.Result(0, sendCont, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
@ 作者: 秦东
|
|
|
|
|
@ 时间: 2023-07-20 11:41:00
|
|
|
|
|
@ 功能: 生成身份验证唯一识别符
|
|
|
|
|
@ 参数
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
@ 返回值
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
@ 方法原型
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
*/
|
|
|
|
|
func (a *ApiMethod) GenerateSignCode(c *gin.Context) {
|
|
|
|
|
userKey := c.Request.Header.Get("user-key")
|
|
|
|
|
userToken := c.Request.Header.Get("user-token")
|
|
|
|
|
if userKey == "" || userToken == "" {
|
|
|
|
|
publicmethod.Result(1, userKey, c, "验证失败!未知识别符!")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
uuid := publicmethod.GetUUid(6)
|
|
|
|
|
uuidStr := strconv.FormatInt(uuid, 10)
|
|
|
|
|
signCode := publicmethod.Sha1Encryption(uuidStr)
|
|
|
|
|
|
|
|
|
|
var singCodeMd5 publicmethod.Md5Encryption
|
|
|
|
|
singCodeMd5.Md5EncryptionInit(signCode)
|
|
|
|
|
signCodeRedisKey := singCodeMd5.Md5EncryptionAlgorithm()
|
|
|
|
|
redisFileKey := fmt.Sprintf("ScanCode:Aut:IdentRec_%v_%v", overall.CONSTANT_CONFIG.RedisPrefixStr.Alias, signCodeRedisKey)
|
|
|
|
|
redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS4)
|
|
|
|
|
redisClient.SetRedisTime(180)
|
|
|
|
|
writeRedisData := map[string]interface{}{
|
|
|
|
|
"userkey": userKey,
|
|
|
|
|
"usertoken": userToken,
|
|
|
|
|
}
|
|
|
|
|
redisClient.HashMsetAdd(redisFileKey, writeRedisData)
|
|
|
|
|
sendCode := publicmethod.MapOut[string]()
|
|
|
|
|
sendCode["code"] = signCode
|
|
|
|
|
publicmethod.Result(0, sendCode, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
@ 作者: 秦东
|
|
|
|
|
@ 时间: 2023-09-26 11:51:43
|
|
|
|
|
@ 功能: 中文转拼音
|
|
|
|
|
@ 参数
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
@ 返回值
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
@ 方法原型
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
*/
|
|
|
|
|
func (a *ApiMethod) ChineseToPinyin(c *gin.Context) {
|
|
|
|
|
var requestData HanziToPinyin
|
|
|
|
|
c.ShouldBindJSON(&requestData)
|
|
|
|
|
if requestData.Title == "" {
|
|
|
|
|
publicmethod.Result(1, requestData, c, "未知中文语句!")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
pyObject := pinyin.NewArgs()
|
|
|
|
|
switch requestData.Types {
|
|
|
|
|
case 1:
|
|
|
|
|
pyObject.Style = pinyin.Tone
|
|
|
|
|
case 2:
|
|
|
|
|
pyObject.Style = pinyin.Tone2
|
|
|
|
|
case 3:
|
|
|
|
|
pyObject.Style = pinyin.Initials
|
|
|
|
|
case 4:
|
|
|
|
|
pyObject.Style = pinyin.FirstLetter
|
|
|
|
|
case 5:
|
|
|
|
|
pyObject.Style = pinyin.Finals
|
|
|
|
|
case 6:
|
|
|
|
|
pyObject.Style = pinyin.FinalsTone
|
|
|
|
|
case 7:
|
|
|
|
|
pyObject.Style = pinyin.FinalsTone2
|
|
|
|
|
case 8:
|
|
|
|
|
pyObject.Style = pinyin.Tone3
|
|
|
|
|
case 9:
|
|
|
|
|
pyObject.Style = pinyin.FinalsTone3
|
|
|
|
|
default:
|
|
|
|
|
pyObject.Style = pinyin.Normal
|
|
|
|
|
}
|
|
|
|
|
pyObject.Separator = requestData.Connector
|
|
|
|
|
str := pinyin.Slug(requestData.Title, pyObject)
|
|
|
|
|
publicmethod.Result(0, str, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
@ 作者: 秦东
|
|
|
|
|
@ 时间: 2023-11-02 10:35:14
|
|
|
|
|
@ 功能: 生成一键登录地址
|
|
|
|
|
@ 参数
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
@ 返回值
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
@ 方法原型
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
*/
|
|
|
|
|
func (a *ApiMethod) CreateOneClickLogin(c *gin.Context) {
|
|
|
|
|
userKey := c.Request.Header.Get("user-key")
|
|
|
|
|
userToken := c.Request.Header.Get("user-token")
|
|
|
|
|
if userKey == "" || userToken == "" {
|
|
|
|
|
publicmethod.Result(1, userKey, c, "验证失败!未知识别符!")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
sendMap := publicmethod.MapOut[string]()
|
|
|
|
|
var requestData SendUrl
|
|
|
|
|
err := c.ShouldBindJSON(&requestData)
|
|
|
|
|
if err != nil || requestData.UrlStr == "" {
|
|
|
|
|
publicmethod.Result(100, err, c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
timeVal := time.Now().UnixNano() / 1e6
|
|
|
|
|
urlStr := fmt.Sprintf("/insensibleLogin?userkey=%v&usertoken=%v&time=%v", userKey, userToken, timeVal)
|
|
|
|
|
if !strings.HasPrefix(requestData.UrlStr, "https://") && !strings.HasPrefix(requestData.UrlStr, "http://") {
|
|
|
|
|
urlStr = fmt.Sprintf("http://%v%v", requestData.UrlStr, urlStr)
|
|
|
|
|
} else {
|
|
|
|
|
urlStr = fmt.Sprintf("%v%v", requestData.UrlStr, urlStr)
|
|
|
|
|
}
|
|
|
|
|
singStr := fmt.Sprintf("%v%v%v", userKey, userToken, timeVal)
|
|
|
|
|
var singCodeMd5 publicmethod.Md5Encryption
|
|
|
|
|
singCodeMd5.Md5EncryptionInit(singStr)
|
|
|
|
|
signCodeRedisKey := singCodeMd5.Md5EncryptionAlgorithm()
|
|
|
|
|
urlStr = fmt.Sprintf("%v&sing=%v", urlStr, signCodeRedisKey)
|
|
|
|
|
|
|
|
|
|
sendMap["http"] = strings.HasPrefix(requestData.UrlStr, "http://")
|
|
|
|
|
sendMap["https"] = strings.HasPrefix(requestData.UrlStr, "https://")
|
|
|
|
|
sendMap["userKey"] = userKey
|
|
|
|
|
sendMap["userToken"] = userToken
|
|
|
|
|
sendMap["urlStr"] = urlStr
|
|
|
|
|
|
|
|
|
|
publicmethod.Result(0, urlStr, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
@ 作者: 秦东
|
|
|
|
|
@ 时间: 2023-12-05 15:34:23
|
|
|
|
|
@ 功能: 获取带规则编号
|
|
|
|
|
@ 参数
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
@ 返回值
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
@ 方法原型
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
*/
|
|
|
|
|
func (a *ApiMethod) GainNumber(c *gin.Context) {
|
|
|
|
|
var requestData GainRulsNumner
|
|
|
|
|
c.ShouldBindJSON(&requestData)
|
|
|
|
|
uuid := strconv.FormatInt(publicmethod.GetUUid(1), 10)
|
|
|
|
|
// fmt.Printf("uuidAry---->%v\n", uuid)
|
|
|
|
|
if requestData.Automatic {
|
|
|
|
|
uuid = requestData.GainUniqueNumber(uuid)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
publicmethod.Result(0, uuid, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
@ 作者: 秦东
|
|
|
|
|
@ 时间: 2023-12-06 10:39:13
|
|
|
|
|
@ 功能: 获取唯一编号
|
|
|
|
|
@ 参数
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
@ 返回值
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
@ 方法原型
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
*/
|
|
|
|
|
func (g *GainRulsNumner) GainUniqueNumber(uuid string) string {
|
|
|
|
|
var uuidAry []string
|
|
|
|
|
if len(g.CustomRules) > 0 {
|
|
|
|
|
for _, v := range g.CustomRules {
|
|
|
|
|
switch v.Types {
|
|
|
|
|
case "text":
|
|
|
|
|
uuidAry = append(uuidAry, v.Rule)
|
|
|
|
|
case "randomnumber":
|
|
|
|
|
maxNum, maxerr := strconv.Atoi(v.Rule)
|
|
|
|
|
// fmt.Printf("maxNum---->%v---->%v\n", maxNum, maxerr)
|
|
|
|
|
if maxerr != nil {
|
|
|
|
|
randNum := publicmethod.GetRandNumber(6)
|
|
|
|
|
uuidAry = append(uuidAry, strconv.FormatInt(randNum, 10))
|
|
|
|
|
} else {
|
|
|
|
|
randNum := publicmethod.GetRandNumber(maxNum)
|
|
|
|
|
uuidAry = append(uuidAry, strconv.FormatInt(randNum, 10))
|
|
|
|
|
}
|
|
|
|
|
case "time":
|
|
|
|
|
uuidAry = append(uuidAry, JudgeYearType(v.Rule))
|
|
|
|
|
case "serialnumber":
|
|
|
|
|
redisClient := grocerystore.RunRedis(overall.CONSTANT_Cluster)
|
|
|
|
|
if g.TableKey == "" {
|
|
|
|
|
redisKey := fmt.Sprintf("GetEncoding:AppPlatform:Key_Currency_%v", overall.CONSTANT_CONFIG.RedisPrefixStr.Alias)
|
|
|
|
|
numAry, numErr := redisClient.Lrange(redisKey, 0, -1)
|
|
|
|
|
if numErr != nil {
|
|
|
|
|
redisClient.Rpush(redisKey, v.Rule)
|
|
|
|
|
uuidAry = append(uuidAry, v.Rule)
|
|
|
|
|
} else {
|
|
|
|
|
if len(numAry) < 1 {
|
|
|
|
|
redisClient.Rpush(redisKey, v.Rule)
|
|
|
|
|
uuidAry = append(uuidAry, v.Rule)
|
|
|
|
|
} else {
|
|
|
|
|
var numFlow JudgeInStringAry
|
|
|
|
|
numFlow.Str = v.Rule
|
|
|
|
|
numFlow.StrAry = numAry
|
|
|
|
|
jieguo := numFlow.GainNotInStr()
|
|
|
|
|
redisClient.Rpush(redisKey, jieguo)
|
|
|
|
|
uuidAry = append(uuidAry, jieguo)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
redisKey := fmt.Sprintf("GetEncoding:AppPlatform:Key_Currency_%v_%v", g.TableKey, overall.CONSTANT_CONFIG.RedisPrefixStr.Alias)
|
|
|
|
|
numAry, _ := redisClient.Lrange(redisKey, 0, -1)
|
|
|
|
|
var count int64
|
|
|
|
|
err := overall.CONSTANT_DB_CustomerForm.Table(g.TableKey).Count(&count).Error
|
|
|
|
|
if err != nil {
|
|
|
|
|
var numFlow JudgeInStringAry
|
|
|
|
|
numFlow.Str = v.Rule
|
|
|
|
|
numFlow.StrAry = numAry
|
|
|
|
|
jieguo := numFlow.GainNotInStr()
|
|
|
|
|
redisClient.Rpush(redisKey, jieguo)
|
|
|
|
|
uuidAry = append(uuidAry, jieguo)
|
|
|
|
|
} else {
|
|
|
|
|
count = count + 1
|
|
|
|
|
var numFlow JudgeInStringAry
|
|
|
|
|
numFlow.Str = strconv.FormatInt(count, 10)
|
|
|
|
|
numFlow.StrAry = numAry
|
|
|
|
|
jieguo := numFlow.GainNotInStr()
|
|
|
|
|
redisClient.Rpush(redisKey, jieguo)
|
|
|
|
|
uuidAry = append(uuidAry, jieguo)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// fmt.Printf("uuidAry-->%v\n", uuidAry)
|
|
|
|
|
if len(uuidAry) > 0 {
|
|
|
|
|
uuid = strings.Join(uuidAry, "-")
|
|
|
|
|
redisClient := grocerystore.RunRedis(overall.CONSTANT_Cluster)
|
|
|
|
|
redisKey := fmt.Sprintf("GetEncoding:AppPlatform:NumKey_Currency_%v", overall.CONSTANT_CONFIG.RedisPrefixStr.Alias)
|
|
|
|
|
if g.TableKey != "" {
|
|
|
|
|
redisKey = fmt.Sprintf("GetEncoding:AppPlatform:NumKey_Currency_%v_%v", g.TableKey, overall.CONSTANT_CONFIG.RedisPrefixStr.Alias)
|
|
|
|
|
}
|
|
|
|
|
numAry, _ := redisClient.Lrange(redisKey, 0, -1)
|
|
|
|
|
if len(numAry) > 0 {
|
|
|
|
|
if !publicmethod.IsInTrue[string](uuid, numAry) {
|
|
|
|
|
redisClient.Rpush(redisKey, uuid)
|
|
|
|
|
return uuid
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
redisClient.Rpush(redisKey, uuid)
|
|
|
|
|
return uuid
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
g.GainUniqueNumber(uuid)
|
|
|
|
|
}
|
|
|
|
|
return uuid
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
@ 作者: 秦东
|
|
|
|
|
@ 时间: 2023-12-06 10:28:01
|
|
|
|
|
@ 功能: 获取一个不存在的字符串
|
|
|
|
|
@ 参数
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
@ 返回值
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
@ 方法原型
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
*/
|
|
|
|
|
func (j *JudgeInStringAry) GainNotInStr() string {
|
|
|
|
|
zhi, _ := strconv.ParseInt(j.Str, 10, 64)
|
|
|
|
|
if !publicmethod.IsInTrue[string](j.Str, j.StrAry) {
|
|
|
|
|
return j.Str
|
|
|
|
|
}
|
|
|
|
|
zhi++
|
|
|
|
|
j.Str = strconv.FormatInt(zhi, 10)
|
|
|
|
|
return j.GainNotInStr()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
@ 作者: 秦东
|
|
|
|
|
@ 时间: 2023-12-05 16:27:20
|
|
|
|
|
@ 功能: 判定随机字符串年格式
|
|
|
|
|
@ 参数
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
@ 返回值
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
@ 方法原型
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
*/
|
|
|
|
|
func JudgeYearType(yearClass string) (timeStr string) {
|
|
|
|
|
yearClassBig := strings.ToUpper(yearClass)
|
|
|
|
|
curraytime := time.Now().Unix()
|
|
|
|
|
switch yearClassBig {
|
|
|
|
|
case "YYYYMMDD":
|
|
|
|
|
timeStr = publicmethod.UnixTimeToDay(curraytime, 20)
|
|
|
|
|
case "YYYYMMD":
|
|
|
|
|
timeStr = publicmethod.UnixTimeToDay(curraytime, 28)
|
|
|
|
|
case "YYYYMD":
|
|
|
|
|
timeStr = publicmethod.UnixTimeToDay(curraytime, 29)
|
|
|
|
|
case "YYMD":
|
|
|
|
|
timeStr = publicmethod.UnixTimeToDay(curraytime, 30)
|
|
|
|
|
case "YYYYMM":
|
|
|
|
|
timeStr = publicmethod.UnixTimeToDay(curraytime, 21)
|
|
|
|
|
case "YYYYM":
|
|
|
|
|
timeStr = publicmethod.UnixTimeToDay(curraytime, 31)
|
|
|
|
|
case "YYYY":
|
|
|
|
|
timeStr = publicmethod.UnixTimeToDay(curraytime, 16)
|
|
|
|
|
case "YY":
|
|
|
|
|
timeStr = publicmethod.UnixTimeToDay(curraytime, 32)
|
|
|
|
|
case "YMD":
|
|
|
|
|
timeStr = publicmethod.UnixTimeToDay(curraytime, 33)
|
|
|
|
|
case "YM":
|
|
|
|
|
timeStr = publicmethod.UnixTimeToDay(curraytime, 34)
|
|
|
|
|
case "Y":
|
|
|
|
|
timeStr = publicmethod.UnixTimeToDay(curraytime, 16)
|
|
|
|
|
case "MMDD":
|
|
|
|
|
timeStr = publicmethod.UnixTimeToDay(curraytime, 35)
|
|
|
|
|
case "MMD":
|
|
|
|
|
timeStr = publicmethod.UnixTimeToDay(curraytime, 36)
|
|
|
|
|
case "MD":
|
|
|
|
|
timeStr = publicmethod.UnixTimeToDay(curraytime, 37)
|
|
|
|
|
case "M":
|
|
|
|
|
timeStr = publicmethod.UnixTimeToDay(curraytime, 38)
|
|
|
|
|
case "MM":
|
|
|
|
|
timeStr = publicmethod.UnixTimeToDay(curraytime, 17)
|
|
|
|
|
case "DD":
|
|
|
|
|
timeStr = publicmethod.UnixTimeToDay(curraytime, 18)
|
|
|
|
|
case "D":
|
|
|
|
|
timeStr = publicmethod.UnixTimeToDay(curraytime, 39)
|
|
|
|
|
default:
|
|
|
|
|
timeStr = publicmethod.UnixTimeToDay(curraytime, 20)
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
@ 作者: 秦东
|
|
|
|
|
@ 时间: 2023-12-13 07:57:27
|
|
|
|
|
@ 功能: 一键登录授权
|
|
|
|
|
@ 参数
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
@ 返回值
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
@ 方法原型
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
*/
|
|
|
|
|
func (a *ApiMethod) ObtainToken(c *gin.Context) {
|
|
|
|
|
ContentType := c.Request.Header.Get("Content-Type")
|
|
|
|
|
Origin := c.Request.Header.Get("Origin")
|
|
|
|
|
userAgent := c.Request.Header.Get("User-Agent")
|
|
|
|
|
var requestData gainAuthorize
|
|
|
|
|
err := c.ShouldBindJSON(&requestData)
|
|
|
|
|
if err != nil {
|
|
|
|
|
publicmethod.Result(100, err, c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if requestData.UserNumber == "" || requestData.Password == "" {
|
|
|
|
|
publicmethod.Result(101, err, c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ContentType == "" || userAgent == "" || Origin == "" {
|
|
|
|
|
publicmethod.Result(100, err, c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
var pwdMd5Cont publicmethod.Md5Encryption
|
|
|
|
|
pwdMd5Cont.Md5EncryptionInit(requestData.Password)
|
|
|
|
|
pwdStr := pwdMd5Cont.Md5EncryptionAlgorithm()
|
|
|
|
|
//验证账号
|
|
|
|
|
var empCont modelshr.EmpowerUser
|
|
|
|
|
err = empCont.GetCont(map[string]interface{}{"userkey": requestData.UserNumber, "password": pwdStr}, "verification_code")
|
|
|
|
|
if err != nil {
|
|
|
|
|
publicmethod.Result(2000, err, c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
//获取雪花随机数
|
|
|
|
|
uuid := publicmethod.GetUUid(6)
|
|
|
|
|
uuidStr := strconv.FormatInt(uuid, 10)
|
|
|
|
|
var uuidMd5 publicmethod.Md5Encryption
|
|
|
|
|
uuidMd5.Md5EncryptionInit(uuidStr)
|
|
|
|
|
if empCont.VerificationCode != "" {
|
|
|
|
|
uuidMd5.AppKey = empCont.VerificationCode
|
|
|
|
|
}
|
|
|
|
|
uuidMd5Str := uuidMd5.Md5EncryptionAlgorithm()
|
|
|
|
|
//头文件加密
|
|
|
|
|
//Content-Type
|
|
|
|
|
var ContentTypeMd5 publicmethod.Md5Encryption
|
|
|
|
|
ContentTypeMd5.Md5EncryptionInit(ContentType)
|
|
|
|
|
if empCont.VerificationCode != "" {
|
|
|
|
|
ContentTypeMd5.AppKey = empCont.VerificationCode
|
|
|
|
|
}
|
|
|
|
|
ContentTypeMd5Str := ContentTypeMd5.Md5EncryptionAlgorithm()
|
|
|
|
|
//Origin
|
|
|
|
|
var OriginMd5 publicmethod.Md5Encryption
|
|
|
|
|
OriginMd5.Md5EncryptionInit(Origin)
|
|
|
|
|
if empCont.VerificationCode != "" {
|
|
|
|
|
OriginMd5.AppKey = empCont.VerificationCode
|
|
|
|
|
}
|
|
|
|
|
OriginMd5Str := OriginMd5.Md5EncryptionAlgorithm()
|
|
|
|
|
//User-Agent
|
|
|
|
|
var userAgentMd5 publicmethod.Md5Encryption
|
|
|
|
|
userAgentMd5.Md5EncryptionInit(userAgent)
|
|
|
|
|
if empCont.VerificationCode != "" {
|
|
|
|
|
userAgentMd5.AppKey = empCont.VerificationCode
|
|
|
|
|
}
|
|
|
|
|
userAgentMd5Str := userAgentMd5.Md5EncryptionAlgorithm()
|
|
|
|
|
|
|
|
|
|
tokenRedisKey := fmt.Sprintf("%v-%v-%v-%v-%v-%v", ContentTypeMd5Str, OriginMd5Str, userAgentMd5Str, uuidMd5Str, requestData.UserNumber, pwdStr)
|
|
|
|
|
|
|
|
|
|
var tokenMd5 publicmethod.Md5Encryption
|
|
|
|
|
tokenMd5.Md5EncryptionInit(tokenRedisKey)
|
|
|
|
|
if empCont.VerificationCode != "" {
|
|
|
|
|
tokenMd5.AppKey = empCont.VerificationCode
|
|
|
|
|
}
|
|
|
|
|
tokenMd5Str := tokenMd5.Md5EncryptionAlgorithm()
|
|
|
|
|
|
|
|
|
|
//redis键
|
|
|
|
|
redisKey := fmt.Sprintf("Authentication:PasswordFreeLogin:key_%v", tokenMd5Str)
|
|
|
|
|
//哈希值
|
|
|
|
|
redisCont := publicmethod.MapOut[string]()
|
|
|
|
|
redisCont["number"] = uuidStr
|
|
|
|
|
redisCont["userkey"] = requestData.UserNumber
|
|
|
|
|
redisCont["password"] = pwdStr
|
|
|
|
|
//将信息写入哈希
|
|
|
|
|
redisClient := grocerystore.RunRedis(overall.CONSTANT_Cluster)
|
|
|
|
|
redisClient.SetRedisTime(10800)
|
|
|
|
|
isTrue := redisClient.HashMsetAdd(redisKey, redisCont)
|
|
|
|
|
if !isTrue {
|
|
|
|
|
publicmethod.Result(1, overall.CONSTANT_Cluster, c, "授权失败!")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
//输出内容
|
|
|
|
|
sendCont := publicmethod.MapOut[string]()
|
|
|
|
|
sendCont["number"] = uuidStr
|
|
|
|
|
sendCont["token"] = tokenMd5Str
|
|
|
|
|
sendCont["isTrue"] = isTrue
|
|
|
|
|
publicmethod.Result(0, sendCont, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
@ 作者: 秦东
|
|
|
|
|
@ 时间: 2023-12-13 09:00:45
|
|
|
|
|
@ 功能: 验证一键登录者身份
|
|
|
|
|
@ 参数
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
@ 返回值
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
@ 方法原型
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
*/
|
|
|
|
|
func (a *ApiMethod) VerifyIdentity(c *gin.Context) {
|
|
|
|
|
contentType := c.Request.Header.Get("Content-Type")
|
|
|
|
|
origin := c.Request.Header.Get("Origin")
|
|
|
|
|
userAgent := c.Request.Header.Get("User-Agent")
|
|
|
|
|
token := c.Query("token")
|
|
|
|
|
number := c.Query("number")
|
|
|
|
|
timeStr := c.Query("time")
|
|
|
|
|
if contentType == "" || userAgent == "" || origin == "" || token == "" || number == "" || timeStr == "" {
|
|
|
|
|
publicmethod.Result(100, contentType, c)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
// currTime := time.Now().Unix()
|
|
|
|
|
// queryTimeInt, _ := strconv.ParseInt(timeStr, 10, 64)
|
|
|
|
|
// if (currTime - queryTimeInt) > 30 {
|
|
|
|
|
// publicmethod.Result(1, timeStr, c, "授权超时")
|
|
|
|
|
// return
|
|
|
|
|
// }
|
|
|
|
|
//redis键
|
|
|
|
|
redisKey := fmt.Sprintf("Authentication:PasswordFreeLogin:key_%v", token)
|
|
|
|
|
redisClient := grocerystore.RunRedis(overall.CONSTANT_Cluster)
|
|
|
|
|
tokenInfo, isTrue := redisClient.HashGetAll(redisKey)
|
|
|
|
|
if isTrue != true {
|
|
|
|
|
publicmethod.Result(1, redisKey, c, "token错误")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
var validator ValidatorType
|
|
|
|
|
err := mapstructure.Decode(tokenInfo, &validator)
|
|
|
|
|
if err != nil {
|
|
|
|
|
publicmethod.Result(1, err, c, "对不起!身份验证失败!")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
//验证账号
|
|
|
|
|
var empCont modelshr.EmpowerUser
|
|
|
|
|
err = empCont.GetCont(map[string]interface{}{"userkey": validator.UserKey, "password": validator.PassWord}, "verification_code")
|
|
|
|
|
if err != nil {
|
|
|
|
|
publicmethod.Result(1, err, c, "对不起!身份验证失败!")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
//头文件加密
|
|
|
|
|
//Content-Type
|
|
|
|
|
var contentTypeMd5 publicmethod.Md5Encryption
|
|
|
|
|
contentTypeMd5.Md5EncryptionInit(contentType)
|
|
|
|
|
if empCont.VerificationCode != "" {
|
|
|
|
|
contentTypeMd5.AppKey = empCont.VerificationCode
|
|
|
|
|
}
|
|
|
|
|
contentTypeMd5Str := contentTypeMd5.Md5EncryptionAlgorithm()
|
|
|
|
|
//Origin
|
|
|
|
|
var originMd5 publicmethod.Md5Encryption
|
|
|
|
|
originMd5.Md5EncryptionInit(origin)
|
|
|
|
|
if empCont.VerificationCode != "" {
|
|
|
|
|
originMd5.AppKey = empCont.VerificationCode
|
|
|
|
|
}
|
|
|
|
|
originMd5Str := originMd5.Md5EncryptionAlgorithm()
|
|
|
|
|
//User-Agent
|
|
|
|
|
var userAgentMd5 publicmethod.Md5Encryption
|
|
|
|
|
userAgentMd5.Md5EncryptionInit(userAgent)
|
|
|
|
|
if empCont.VerificationCode != "" {
|
|
|
|
|
userAgentMd5.AppKey = empCont.VerificationCode
|
|
|
|
|
}
|
|
|
|
|
userAgentMd5Str := userAgentMd5.Md5EncryptionAlgorithm()
|
|
|
|
|
|
|
|
|
|
var uuidMd5 publicmethod.Md5Encryption
|
|
|
|
|
uuidMd5.Md5EncryptionInit(validator.Number)
|
|
|
|
|
if empCont.VerificationCode != "" {
|
|
|
|
|
uuidMd5.AppKey = empCont.VerificationCode
|
|
|
|
|
}
|
|
|
|
|
uuidMd5Str := uuidMd5.Md5EncryptionAlgorithm()
|
|
|
|
|
|
|
|
|
|
tokenRedisKey := fmt.Sprintf("%v-%v-%v-%v-%v-%v", contentTypeMd5Str, originMd5Str, userAgentMd5Str, uuidMd5Str, validator.UserKey, validator.PassWord)
|
|
|
|
|
var tokenMd5 publicmethod.Md5Encryption
|
|
|
|
|
tokenMd5.Md5EncryptionInit(tokenRedisKey)
|
|
|
|
|
if empCont.VerificationCode != "" {
|
|
|
|
|
tokenMd5.AppKey = empCont.VerificationCode
|
|
|
|
|
}
|
|
|
|
|
tokenMd5Str := tokenMd5.Md5EncryptionAlgorithm()
|
|
|
|
|
//系统验证系数
|
|
|
|
|
systemKey := fmt.Sprintf("%v-%v", tokenMd5Str, uuidMd5Str)
|
|
|
|
|
var systemKeyMd5 publicmethod.Md5Encryption
|
|
|
|
|
systemKeyMd5.Md5EncryptionInit(systemKey)
|
|
|
|
|
if empCont.VerificationCode != "" {
|
|
|
|
|
systemKeyMd5.AppKey = empCont.VerificationCode
|
|
|
|
|
}
|
|
|
|
|
systemKeyMd5Str := systemKeyMd5.Md5EncryptionAlgorithm()
|
|
|
|
|
//接收系数
|
|
|
|
|
receiveKey := fmt.Sprintf("%v-%v", token, number)
|
|
|
|
|
var receiveKeyMd5 publicmethod.Md5Encryption
|
|
|
|
|
receiveKeyMd5.Md5EncryptionInit(receiveKey)
|
|
|
|
|
if empCont.VerificationCode != "" {
|
|
|
|
|
receiveKeyMd5.AppKey = empCont.VerificationCode
|
|
|
|
|
}
|
|
|
|
|
receiveKeyMd5Str := receiveKeyMd5.Md5EncryptionAlgorithm()
|
|
|
|
|
if systemKeyMd5Str != receiveKeyMd5Str {
|
|
|
|
|
publicmethod.Result(1, err, c, "对不起!身份验证失败!")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
publicmethod.Result(0, err, c)
|
|
|
|
|
}
|