From 331901c35d29e8e7b150dff07097cd2ab56628d9 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Thu, 28 Nov 2024 11:21:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B9=BF=E5=91=8A=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/hdl/hdl_callback_advertising.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/hdl/hdl_callback_advertising.go b/app/hdl/hdl_callback_advertising.go index dc2919d..dc8dddf 100644 --- a/app/hdl/hdl_callback_advertising.go +++ b/app/hdl/hdl_callback_advertising.go @@ -8,7 +8,9 @@ import ( "code.fnuoos.com/EggPlanet/egg_models.git/src/model" "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" "crypto/sha256" + "encoding/hex" "encoding/json" + "fmt" "github.com/gin-gonic/gin" "github.com/tidwall/gjson" "strings" @@ -40,12 +42,12 @@ func CallbackChuanshanjia(c *gin.Context) { } } keyStr := spaceKey + ":" + transId - h := sha256.New() - //写入数据:将字符串 s 转换为字节切片并写入哈希对象 h。这一步是计算哈希的关键。 - h.Write([]byte(keyStr)) - //计算哈希值:h.Sum(nil) 计算当前哈希值并返回一个字节切片 bs。传入 nil 表示不需要额外的字节切片来存储结果。 - bs := h.Sum(nil) - if string(bs) != sign { + // 1. 使用SHA256算法计算摘要 + hash := sha256.Sum256([]byte(keyStr)) + // 2. 将摘要转换为十六进制字符串 + signStr := hex.EncodeToString(hash[:]) + fmt.Println(signStr) + if strings.Contains(signStr, sign) == false { c.String(200, "{\"is_verify\":true,\"reason\":50002}") return }