优化结构

This commit is contained in:
Yvan
2026-08-22 22:34:33 +08:00
parent 0126995090
commit b18baf1547
26 changed files with 501 additions and 80 deletions
+11 -1
View File
@@ -3,8 +3,10 @@ package payment
import (
"bytes"
"context"
"crypto/rand"
"crypto/tls"
"crypto/x509"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
@@ -570,7 +572,15 @@ func paymentHTTPClient(c map[string]any) (*http.Client, error) {
return &http.Client{Timeout: 20 * time.Second, Transport: &http.Transport{TLSClientConfig: &tls.Config{Certificates: []tls.Certificate{cert}, RootCAs: pool, MinVersion: tls.VersionTLS12}}}, nil
}
func nonce() string { return fmt.Sprintf("%d", time.Now().UnixNano()) }
// nonce returns a compact request token. Clock-only values can collide when
// several payment requests are prepared in the same scheduler tick.
func nonce() string {
var raw [8]byte
if _, err := rand.Read(raw[:]); err == nil {
return hex.EncodeToString(raw[:])
}
return fmt.Sprintf("%d", time.Now().UnixNano())
}
func stringOr(extra map[string]any, key, fallback string) string {
if value, ok := extra[key].(string); ok {
return value