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.
149 lines
3.1 KiB
149 lines
3.1 KiB
package publicapi
|
|
|
|
import (
|
|
"appPlatform/middleware/grocerystore"
|
|
"appPlatform/overall"
|
|
"appPlatform/overall/publicmethod"
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
"unicode"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 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)
|
|
}
|
|
|