- Go 服务端:唯一金额/备注码/回填订单编号三路匹配、托管收银页、HMAC 回调七级重试、SQLite 单二进制 - SDK:Go / Java / PHP / Python,共享签名测试向量(docs/test_vectors.json) - 跨语言 e2e(真实二进制 × Python SDK × mock 币安)、GitHub Actions CI、Dockerfile - 协议文档 docs/protocol.md、调研与实测结论 docs/research.md Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
35 lines
757 B
Go
35 lines
757 B
Go
package bpaygate
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestVectors(t *testing.T) {
|
|
data, err := os.ReadFile("../../docs/test_vectors.json")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var vf struct {
|
|
Secret string `json:"secret"`
|
|
Cases []struct {
|
|
Type, Timestamp, Nonce, Method, Path, Body, Signature string
|
|
} `json:"cases"`
|
|
}
|
|
if err := json.Unmarshal(data, &vf); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for i, c := range vf.Cases {
|
|
var got string
|
|
if c.Type == "request" {
|
|
got = SignRequest(vf.Secret, c.Timestamp, c.Nonce, c.Method, c.Path, []byte(c.Body))
|
|
} else {
|
|
got = SignCallback(vf.Secret, c.Timestamp, c.Nonce, []byte(c.Body))
|
|
}
|
|
if got != c.Signature {
|
|
t.Errorf("case %d: got %s want %s", i, got, c.Signature)
|
|
}
|
|
}
|
|
}
|