完善商福通接口通知字段;提供一个环境变量以决定是否打印原始 http 报文

This commit is contained in:
2025-06-23 11:27:28 +08:00
parent 546e81fee3
commit fda1a2de0e
2 changed files with 45 additions and 9 deletions

View File

@@ -82,12 +82,16 @@ func initSft() {
func (s *SftClient) PaymentScanPay(req *PaymentScanPayReq) (*PaymentScanPayResp, error) {
const url = "https://pay.rscygroup.com/api/open/payment/scanpay"
req.ReturnUrl = env.SftReturnUrl
req.NotifyUrl = env.SftNotifyUrl
req.RouteNo = u.P(s.routeId)
return call[PaymentScanPayResp](s, url, req)
}
func (s *SftClient) PaymentH5Pay(req *PaymentH5PayReq) (*PaymentH5PayResp, error) {
const url = "https://pay.rscygroup.com/api/open/payment/h5pay"
req.ReturnUrl = env.SftReturnUrl
req.NotifyUrl = env.SftNotifyUrl
req.RouteNo = u.P(s.routeId)
return call[PaymentH5PayResp](s, url, req)
}
@@ -265,22 +269,26 @@ func call[T any](s *SftClient, url string, req any) (*T, error) {
}
request.Header.Set("Content-Type", "application/json")
reqDump, err := httputil.DumpRequest(request, true)
if err != nil {
return nil, fmt.Errorf("请求内容转储失败:%w", err)
if env.LogHttpDump == true {
reqDump, err := httputil.DumpRequest(request, true)
if err != nil {
return nil, fmt.Errorf("请求内容转储失败:%w", err)
}
println(string(reqDump) + "\n\n")
}
println(string(reqDump) + "\n\n")
response, err := http.DefaultClient.Do(request)
if err != nil {
return nil, fmt.Errorf("请求失败:%w", err)
}
respDump, err := httputil.DumpResponse(response, true)
if err != nil {
return nil, fmt.Errorf("响应内容转储失败:%w", err)
if env.LogHttpDump == true {
respDump, err := httputil.DumpResponse(response, true)
if err != nil {
return nil, fmt.Errorf("响应内容转储失败:%w", err)
}
println(string(respDump) + "\n\n")
}
println(string(respDump) + "\n\n")
if response.StatusCode != http.StatusOK {
return nil, fmt.Errorf("请求响应失败:%d", response.StatusCode)