add jiyi
This commit is contained in:
43
internal/infrastructure/external/jiyi/crypto_test.go
vendored
Normal file
43
internal/infrastructure/external/jiyi/crypto_test.go
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
package jiyi
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSign(t *testing.T) {
|
||||
// 与文档 Java 示例一致的待签字符串顺序
|
||||
body := map[string]string{
|
||||
"idNo": "440181199807041111",
|
||||
"mobile": "13000000000",
|
||||
"name": "黄雅莉",
|
||||
"encryptType": "0",
|
||||
"timestamp": "1720940866832",
|
||||
}
|
||||
secret := "a661a2728f2a54b71601d3e8a7f6210d650c2018"
|
||||
got := Sign(body, secret)
|
||||
want := genMD5("encryptType0idNo440181199807041111mobile13000000000name黄雅莉timestamp1720940866832" + secret)
|
||||
if got != want {
|
||||
t.Fatalf("sign mismatch: got %s want %s", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncryptBodyMD5(t *testing.T) {
|
||||
body := map[string]string{
|
||||
"idNo": "440181199807041111",
|
||||
"mobile": "13000000000",
|
||||
"name": "黄雅莉",
|
||||
"encryptType": "1",
|
||||
"timestamp": "1720940866832",
|
||||
}
|
||||
got := encryptBodyMD5(body)
|
||||
if got["encryptType"] != "1" || got["timestamp"] != "1720940866832" {
|
||||
t.Fatalf("meta fields should keep plaintext: %+v", got)
|
||||
}
|
||||
if got["idNo"] != MD5Encrypt("440181199807041111") {
|
||||
t.Fatalf("idNo not encrypted: %s", got["idNo"])
|
||||
}
|
||||
if got["mobile"] != MD5Encrypt("13000000000") {
|
||||
t.Fatalf("mobile not encrypted: %s", got["mobile"])
|
||||
}
|
||||
if got["name"] != MD5Encrypt("黄雅莉") {
|
||||
t.Fatalf("name not encrypted: %s", got["name"])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user