feat(osi): 实现 MD5 头签名与请求头组装(T-002)
password=md5("ts=<ts>&ask=<ask>") 32 位小写;ask 仅参与签名不进 headers
测试向量与本地 Python 联调脚本对齐
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+30
@@ -0,0 +1,30 @@
|
||||
package osi
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
)
|
||||
|
||||
type HeaderInput struct {
|
||||
OrgCode string
|
||||
DeviceSN string
|
||||
UserName string
|
||||
Ask string
|
||||
TS string
|
||||
}
|
||||
|
||||
func SignPassword(ts, ask string) string {
|
||||
sum := md5.Sum([]byte("ts=" + ts + "&ask=" + ask))
|
||||
return hex.EncodeToString(sum[:])
|
||||
}
|
||||
|
||||
func BuildHeaders(input HeaderInput) map[string]string {
|
||||
return map[string]string{
|
||||
"Content-Type": "application/json",
|
||||
"orgCode": input.OrgCode,
|
||||
"deviceSN": input.DeviceSN,
|
||||
"ts": input.TS,
|
||||
"userName": input.UserName,
|
||||
"password": SignPassword(input.TS, input.Ask),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user