修改支付相关
This commit is contained in:
@@ -418,23 +418,10 @@ func newWechatV3Client(c map[string]any, endpointKey string) (*gopayWechatV3.Cli
|
||||
return nil, err
|
||||
}
|
||||
|
||||
platformCert := firstAny(c, "platform_cert", "platform_certificate", "wechatpay_platform_cert")
|
||||
if platformCert == "" {
|
||||
return nil, errors.New("微信支付 v3 缺少 platform_cert")
|
||||
}
|
||||
platformSerial := firstAny(c, "platform_serial_no", "platform_cert_serial", "wechatpay_serial_no")
|
||||
if platformSerial == "" {
|
||||
platformSerial, err = wechatV3PlatformSerial(platformCert)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if err = client.AutoVerifySignByCert([]byte(platformCert), platformSerial); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
client.SetBodySize(8)
|
||||
client.GetHttpClient().SetTimeout(20 * time.Second)
|
||||
|
||||
endpointConfigured := false
|
||||
if endpointKey != "" {
|
||||
if endpoint := strings.TrimSpace(text(c, endpointKey)); endpoint != "" {
|
||||
parsed, parseErr := url.Parse(endpoint)
|
||||
@@ -446,15 +433,37 @@ func newWechatV3Client(c map[string]any, endpointKey string) (*gopayWechatV3.Cli
|
||||
}
|
||||
httpClient := client.GetHttpClient()
|
||||
httpClient.SetTransport(&wechatV3EndpointTransport{base: httpClient.HttpClient.Transport, endpoint: parsed})
|
||||
return client, nil
|
||||
endpointConfigured = true
|
||||
}
|
||||
}
|
||||
if baseURL := strings.TrimRight(firstAny(c, "base_url", "api_base_url", "proxy_url"), "/"); baseURL != "" {
|
||||
parsed, parseErr := url.Parse(baseURL)
|
||||
if parseErr != nil || parsed.Scheme == "" || parsed.Host == "" {
|
||||
return nil, errors.New("微信支付 v3 base_url 配置无效")
|
||||
if !endpointConfigured {
|
||||
if baseURL := strings.TrimRight(firstAny(c, "base_url", "api_base_url", "proxy_url"), "/"); baseURL != "" {
|
||||
parsed, parseErr := url.Parse(baseURL)
|
||||
if parseErr != nil || parsed.Scheme == "" || parsed.Host == "" {
|
||||
return nil, errors.New("微信支付 v3 base_url 配置无效")
|
||||
}
|
||||
client.SetProxyHost(baseURL)
|
||||
}
|
||||
}
|
||||
|
||||
platformCert := firstAny(c, "platform_cert", "platform_certificate", "wechatpay_platform_cert")
|
||||
if platformCert == "" {
|
||||
// Fetch the current platform certificates using the merchant credentials.
|
||||
// This client is request-scoped, so avoid starting a background refresher.
|
||||
if err = client.AutoVerifySign(false); err != nil {
|
||||
return nil, fmt.Errorf("微信支付 v3 自动获取平台证书失败: %w", err)
|
||||
}
|
||||
} else {
|
||||
platformSerial := firstAny(c, "platform_serial_no", "platform_cert_serial", "wechatpay_serial_no")
|
||||
if platformSerial == "" {
|
||||
platformSerial, err = wechatV3PlatformSerial(platformCert)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if err = client.AutoVerifySignByCert([]byte(platformCert), platformSerial); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
client.SetProxyHost(baseURL)
|
||||
}
|
||||
return client, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user