开始增加支付-1
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package leshua
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"hfb_sys/backend/internal/config"
|
||||
)
|
||||
|
||||
func TestSignUsesASCIISortedNonEmptyParams(t *testing.T) {
|
||||
params := map[string]string{
|
||||
"service": "get_tdcode",
|
||||
"merchant_id": "1234567890",
|
||||
"third_order_id": "NO1",
|
||||
"amount": "100",
|
||||
"nonce_str": "abc",
|
||||
"empty": "",
|
||||
"sign": "ignored",
|
||||
}
|
||||
|
||||
got := Sign(params, "secret", SignOptions{})
|
||||
want := "1E7892034AA77899E8DD609C4FA09E76"
|
||||
if got != want {
|
||||
t.Fatalf("Sign() = %s, want %s", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVerifyNotifyIncludesEmptyAndExcludesErrorCode(t *testing.T) {
|
||||
client := NewClient(config.LeshuaPaymentConfig{NotifyKey: "notify-secret"})
|
||||
params := map[string]string{
|
||||
"merchant_id": "1234567890",
|
||||
"third_order_id": "NO1",
|
||||
"leshua_order_id": "LS1",
|
||||
"amount": "100",
|
||||
"status": "2",
|
||||
"attach": "",
|
||||
"error_code": "-20001",
|
||||
}
|
||||
params["sign"] = Sign(params, "notify-secret", SignOptions{
|
||||
IncludeEmpty: true,
|
||||
ExcludeKeys: []string{"error_code", "sign"},
|
||||
})
|
||||
|
||||
if !client.VerifyNotify(params) {
|
||||
t.Fatal("VerifyNotify() = false, want true")
|
||||
}
|
||||
|
||||
params["amount"] = "101"
|
||||
if client.VerifyNotify(params) {
|
||||
t.Fatal("VerifyNotify() = true after amount changed, want false")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParsePayloadSupportsFormAndXML(t *testing.T) {
|
||||
form, err := ParsePayload([]byte("third_order_id=NO1&status=2&amount=100"))
|
||||
if err != nil {
|
||||
t.Fatalf("ParsePayload(form) error = %v", err)
|
||||
}
|
||||
if form["third_order_id"] != "NO1" || form["status"] != "2" || form["amount"] != "100" {
|
||||
t.Fatalf("ParsePayload(form) = %#v", form)
|
||||
}
|
||||
|
||||
xml, err := ParsePayload([]byte("<xml><third_order_id>NO2</third_order_id><status>6</status></xml>"))
|
||||
if err != nil {
|
||||
t.Fatalf("ParsePayload(xml) error = %v", err)
|
||||
}
|
||||
if xml["third_order_id"] != "NO2" || xml["status"] != "6" {
|
||||
t.Fatalf("ParsePayload(xml) = %#v", xml)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user