修复支付网关地址空白字符

This commit is contained in:
yml
2026-06-15 00:53:05 +08:00
parent a275a006eb
commit 4a0d615926
4 changed files with 80 additions and 8 deletions
@@ -125,6 +125,14 @@ func TestCreatePaymentSetsCounterParamWhenPayModeConfigured(t *testing.T) {
}
}
func TestCreatePaymentTrimsGatewayURLWhitespace(t *testing.T) {
body := captureCreatePaymentBody(t, "", "\t")
reqData := body["req_data"].(map[string]any)
if reqData["out_order_no"] != "ORDER1" {
t.Fatalf("out_order_no = %#v, want ORDER1", reqData["out_order_no"])
}
}
func TestCreatePaymentUsesShanghaiTimeWhenLocalIsUTC(t *testing.T) {
oldLocal := time.Local
time.Local = time.UTC
@@ -179,7 +187,7 @@ func testKeyPairPEM(t *testing.T, key *rsa.PrivateKey) (string, string) {
return privatePEM, certPEM
}
func captureCreatePaymentBody(t *testing.T, payMode string) map[string]any {
func captureCreatePaymentBody(t *testing.T, payMode string, gatewaySuffix ...string) map[string]any {
t.Helper()
var captured map[string]any
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -199,8 +207,12 @@ func captureCreatePaymentBody(t *testing.T, payMode string) map[string]any {
t.Fatalf("generate key: %v", err)
}
privatePEM, certPEM := testKeyPairPEM(t, key)
gatewayURL := server.URL
if len(gatewaySuffix) > 0 {
gatewayURL += gatewaySuffix[0]
}
client := NewClient(Config{
GatewayURL: server.URL,
GatewayURL: gatewayURL,
AppID: "app-1",
SerialNo: "serial-1",
MerchantID: "merchant-1",