6
0
gaore-common-sdk-go/services/chat/open_sign.go

18 lines
547 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package chat
import (
"crypto/md5"
"encoding/hex"
"strconv"
"time"
)
// signOpenApi 生成 chat open 接口验签三参数(对齐 chat 侧 ControllerBase::authorizedByConfig
// sign = md5(gkey + time + key)time 为当前 Unix 秒,与服务器差 >3600s 会被拒。
// 密钥 key 由调用方从自身配置传入SDK 不落任何密钥。
func signOpenApi(gkey, key string) (g, t, s string) {
t = strconv.FormatInt(time.Now().Unix(), 10)
sum := md5.Sum([]byte(gkey + t + key))
return gkey, t, hex.EncodeToString(sum[:])
}