|
|
|
@ -2,6 +2,7 @@ package publicapi |
|
|
|
|
|
|
|
import ( |
|
|
|
"appPlatform/middleware/grocerystore" |
|
|
|
"appPlatform/models/modelshr" |
|
|
|
"appPlatform/overall" |
|
|
|
"appPlatform/overall/publicmethod" |
|
|
|
"fmt" |
|
|
|
@ -11,6 +12,7 @@ import ( |
|
|
|
"unicode" |
|
|
|
|
|
|
|
"github.com/gin-gonic/gin" |
|
|
|
"github.com/mitchellh/mapstructure" |
|
|
|
"github.com/mozillazg/go-pinyin" |
|
|
|
) |
|
|
|
|
|
|
|
@ -254,3 +256,454 @@ func (a *ApiMethod) CreateOneClickLogin(c *gin.Context) { |
|
|
|
|
|
|
|
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) |
|
|
|
} |
|
|
|
|