90 lines
2.2 KiB
Go
90 lines
2.2 KiB
Go
package payment
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
|
|
"hfb_sys/backend/internal/model"
|
|
)
|
|
|
|
// sanitizeConfigTestPayload 对测试报文中的签名、用户标识和凭证类字段打码。
|
|
func sanitizeConfigTestPayload(raw map[string]string) map[string]string {
|
|
if raw == nil {
|
|
return nil
|
|
}
|
|
out := make(map[string]string, len(raw))
|
|
for key, value := range raw {
|
|
if configTestSensitiveKey(key) {
|
|
out[key] = "***"
|
|
continue
|
|
}
|
|
out[key] = value
|
|
}
|
|
return out
|
|
}
|
|
|
|
func configTestSensitiveKey(key string) bool {
|
|
lower := strings.ToLower(strings.TrimSpace(key))
|
|
if lower == "sign" || strings.HasSuffix(lower, "_sign") || strings.Contains(lower, "signature") {
|
|
return true
|
|
}
|
|
for _, token := range []string{"openid", "auth_code", "access_token", "secret", "private_key", "cert", "token"} {
|
|
if strings.Contains(lower, token) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func configTestQueryRequest(row model.PaymentConfigTestOrder) map[string]string {
|
|
return map[string]string{
|
|
"provider": row.Provider,
|
|
"merchant_id": row.MerchantID,
|
|
"pay_way": row.PayWay,
|
|
"third_order_id": row.ThirdOrderID,
|
|
"provider_order_id": row.ProviderOrderID,
|
|
}
|
|
}
|
|
|
|
func configTestNotifyRequest(params map[string]string, contentType string) map[string]string {
|
|
out := sanitizeConfigTestPayload(params)
|
|
if out == nil {
|
|
out = map[string]string{}
|
|
}
|
|
out["_content_type"] = contentType
|
|
return out
|
|
}
|
|
|
|
func configTestNotifyResult(verified bool, status string, row model.PaymentConfigTestOrder, message string) map[string]string {
|
|
out := map[string]string{
|
|
"verified": strconv.FormatBool(verified),
|
|
"status": status,
|
|
"amount_cent": strconv.FormatInt(row.AmountCent, 10),
|
|
"provider_order_id": row.ProviderOrderID,
|
|
}
|
|
if message != "" {
|
|
out["message"] = message
|
|
}
|
|
return out
|
|
}
|
|
|
|
func configTestNotifyAck(provider string, success bool) string {
|
|
switch provider {
|
|
case "lakala":
|
|
if success {
|
|
return `{"code":"SUCCESS","message":"执行成功"}`
|
|
}
|
|
return `{"code":"FAIL","message":"失败"}`
|
|
case "saobei":
|
|
if success {
|
|
return `{"return_code":"01","return_msg":"success"}`
|
|
}
|
|
return `{"return_code":"02","return_msg":"失败"}`
|
|
default:
|
|
if success {
|
|
return "000000"
|
|
}
|
|
return "FAIL"
|
|
}
|
|
}
|