优化结构
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user