Browse Source

创建解密函数

master
herenshan112 1 day ago
parent
commit
f0ea41056c
  1. 25
      api/shiyan/maptostruct/shiyan.go
  2. 6
      api/shiyan/maptostruct/type.go
  3. 2
      api/version1/customerApp/companyduty.go
  4. 1
      apirouter/apishiyan/maptostruct.go
  5. 20
      overall/publicmethod/formatOutput.go
  6. 3
      overall/publicmethod/newSm4.go

25
api/shiyan/maptostruct/shiyan.go

@ -935,3 +935,28 @@ func generateSchedule(startDate time.Time, numDays int) []Shift {
func (a *ApiMethod) JiaoZhengTableWord(c *gin.Context) {
}
/*
*
@ 作者: 秦东
@ 时间: 2026-01-26 14:25:42
@ 功能: SM4解密函数
*/
func (a *ApiMethod) Sm4JiemiVal(c *gin.Context) {
var requestData JimiToSm4
err := c.ShouldBindJSON(&requestData)
if requestData.AuthKey == "" {
publicmethod.ResultNoJiami(100, err, c)
return
}
if requestData.Data == "" {
publicmethod.ResultNoJiami(100, err, c)
return
}
jimi, err := publicmethod.SM4DecryptNew(requestData.Data, requestData.AuthKey)
fmt.Printf("----------------->%v---------->%v\n\n", err, string(jimi))
var sendMap map[string]interface{}
err = json.Unmarshal(jimi, &sendMap)
fmt.Printf("----------------->%v--------->%v\n\n", err, sendMap)
publicmethod.ResultNoJiami(0, sendMap, c)
}

6
api/shiyan/maptostruct/type.go

@ -131,3 +131,9 @@ type PersonalityTestOut struct {
Name string `json:"name"`
Address string `json:"address"`
}
// 解密
type JimiToSm4 struct {
AuthKey string `json:"authKey"`
Data string `json:"data"`
}

2
api/version1/customerApp/companyduty.go

@ -65,7 +65,7 @@ func (a *ApiMethod) CompanyDutyInit(c *gin.Context) {
monthAllDay = append(monthAllDay, fmt.Sprintf("%v日", i))
}
myPower := publicmethod.GetMyMenuPower(userCont.Key, "38")
myPower := publicmethod.GetMyMenuPower(userCont.Key, "167")
//角色权限范围判定
//1:本岗位;2:本部门;3:本分部;4:指定行政组织;5:所有
// switch SearchRoleLevev(userCont.Role) {

1
apirouter/apishiyan/maptostruct.go

@ -47,6 +47,7 @@ func (a *ApiRouter) RouterGroup(router *gin.RouterGroup) {
apiRouter.POST("setUpWorkWatch", methodBinding.SetUpWorkWatch) //测试通过企业微信获取人员
apiRouter.POST("workTimeSortTP", methodBinding.WorkTimeSortTP) //工作段排序
apiRouter.POST("sm4JiemiVal", methodBinding.Sm4JiemiVal) //SM4解密函数
}
}

20
overall/publicmethod/formatOutput.go

@ -298,3 +298,23 @@ func ReceiveData(c *gin.Context) ([]byte, error) {
}
return json.Marshal(val)
}
// 格式化输出
func ResultNoJiami(code int, data interface{}, c *gin.Context, msgAry ...string) {
var msg string
if _, isTrue := ErrorCodeMsg[code]; isTrue {
msg = ErrorCodeMsg[code]
}
if len(msgAry) > 0 {
for _, v := range msgAry {
if msg == "" {
msg = fmt.Sprintf("%v", v)
} else {
msg = fmt.Sprintf("%v。%v", msg, v)
}
}
}
c.JSON(http.StatusOK, Reply{code, msg, data}) //输出json格式数据
}

3
overall/publicmethod/newSm4.go

@ -97,9 +97,6 @@ func SM4DecryptNew(data, sm4IvStr string, key ...string) ([]byte, error) {
if len(key) > 0 {
SM4Key = strings.Join(key, "-")
}
if len(key) > 0 {
SM4Key = strings.Join(key, "-")
}
SM4Key = ProcessString(SM4Key, 16, "s")
//sm4随机安全码
SM4Iv := overall.CONSTANT_CONFIG.Appsetup.Sm4Token

Loading…
Cancel
Save