This commit is contained in:
孟帅
2023-05-10 23:54:50 +08:00
parent bbe655a4d8
commit 49a96750bf
314 changed files with 15138 additions and 6244 deletions

View File

@@ -7,35 +7,38 @@ import (
)
type Sign interface {
SetSign(traceID, appId, secretKey string)
SetSign(appId, secretKey string) *msgin.RpcMsg
SetTraceID(traceID string)
}
// SetSign 设置签名
func SetSign(data interface{}, traceID, appId, secretKey string) {
// PkgSign 打包签名
func PkgSign(data interface{}, appId, secretKey, traceID string) *msgin.RpcMsg {
if c, ok := data.(Sign); ok {
c.SetSign(traceID, appId, secretKey)
return
c.SetTraceID(traceID)
return c.SetSign(appId, secretKey)
}
return nil
}
// VerifySign 验证签名
func VerifySign(data interface{}, appId, secretKey string) (err error) {
func VerifySign(data interface{}, appId, secretKey string) (in *msgin.RpcMsg, err error) {
// 无密钥,无需签名
if secretKey == "" {
return
}
var in *msgin.Request
if err = gconv.Scan(data, &in); err != nil {
return
}
if appId != in.AppId {
return gerror.New("appId invalid")
err = gerror.New("appId invalid")
return
}
if in.Sign != in.GetSign(secretKey) {
return gerror.New("sign invalid")
err = gerror.New("sign invalid")
return
}
return
}