Browse Source

[ADD] 新增国密sm3密码杂凑算法

pujielan 1 month ago
parent
commit
15b68fa9b7
1 changed files with 8 additions and 3 deletions
  1. 8 3
      handler/sms.go

+ 8 - 3
handler/sms.go

@@ -11,6 +11,7 @@ import (
 	"time"
 
 	"github.com/go-admin-team/go-admin-core/logger"
+	"github.com/tjfoc/gmsm/sm3"
 )
 
 type SingleMsg struct {
@@ -27,9 +28,13 @@ type SendMsg struct {
 	MsgList    []SingleMsg `json:"msgList"`
 }
 
-func sm3(data string) string {
+func SM3(data string) string {
 	// 这里应该实现SM3算法,由于Go标准库中没有直接支持,这里只是返回一个模拟的字符串
-	return "fake-sm3-hash"
+	h := sm3.New()
+	h.Write([]byte(data))
+	sum := h.Sum(nil)
+	logger.Debugf("digest value is: %x\n", sum)
+	return string(sum)
 }
 
 func (e *EventHandler) SendMsg() *EventHandler {
@@ -61,7 +66,7 @@ func (e *EventHandler) SendMsg() *EventHandler {
 	headers["x-system-key"] = appkey
 	headers["x-system-nonce"] = nonce.String()
 	headers["x-system-timestamp"] = fmt.Sprintf("%d", timestamp)
-	headers["x-system-token"] = sm3(appkey + fmt.Sprintf("%d", timestamp) + appsecret + nonce.String())
+	headers["x-system-token"] = SM3(appkey + fmt.Sprintf("%d", timestamp) + appsecret + nonce.String())
 
 	// set smsContent
 	// 所属系统:{{app_name}}