liujie
2026-09-09 39f6fca28e3f78abe48f08e474ec011abb990b36
backend/src/main/java/com/tourguide/modules/order/payment/HuifuPaymentRefundGateway.java
@@ -1,5 +1,6 @@
package com.tourguide.modules.order.payment;
import com.alibaba.fastjson.JSONObject;
import com.tourguide.common.huifu.biz.DouGongRefundBiz;
import com.tourguide.modules.order.entity.TourOrder;
import com.tourguide.modules.order.entity.TourOrderPaymentAttempt;
@@ -39,9 +40,9 @@
        try {
            Map<String, Object> response = refundBiz.refund(order.getRefundOrderNo(), amount,
                    paymentAttempt.getReqDate(), paymentAttempt.getReqSeqId());
            String responseCode = stringValue(response.get("resp_code"));
            String responseCode = responseValue(response, "resp_code", "code");
            if (!SUCCESS_CODE.equals(responseCode)) {
                String description = stringValue(response.get("resp_desc"));
                String description = responseValue(response, "resp_desc", "msg");
                throw new IllegalStateException(StringUtils.hasText(description)
                        ? description : "Huifu refund request failed");
            }
@@ -56,4 +57,28 @@
    private String stringValue(Object value) {
        return value == null ? null : String.valueOf(value);
    }
    private String responseValue(Map<String, Object> response, String... keys) {
        if (response == null) return null;
        for (String key : keys) {
            String value = stringValue(response.get(key));
            if (StringUtils.hasText(value)) return value;
        }
        for (String nestedKey : new String[]{"data", "resp_data"}) {
            Object nested = response.get(nestedKey);
            if (nested instanceof Map) {
                @SuppressWarnings("unchecked")
                Map<String, Object> nestedMap = (Map<String, Object>) nested;
                String value = responseValue(nestedMap, keys);
                if (StringUtils.hasText(value)) return value;
            } else if (nested instanceof String && StringUtils.hasText((String) nested)) {
                try {
                    String value = responseValue(JSONObject.parseObject((String) nested), keys);
                    if (StringUtils.hasText(value)) return value;
                } catch (RuntimeException ignored) {
                }
            }
        }
        return null;
    }
}