yeg
2026-09-14 81f4b6bb09fd7327f138ce34c3ad3a1e6b4de856
chore(scratch): 新增斗拱子商户档案查询探针

只读查询 v2.merchant.basicdata.query,打印子商户档案里的行业相关字段(mcc/ent_type/business_scope 等),用于确认存量商户在汇付侧登记的行业。
1个文件已添加
77 ■■■■■ 已修改文件
.scratch/automatic-withdrawal/tools/MerchantInfoProbe.java 77 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.scratch/automatic-withdrawal/tools/MerchantInfoProbe.java
New file
@@ -0,0 +1,77 @@
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
import com.huifu.bspay.sdk.opps.client.BasePayClient;
import com.huifu.bspay.sdk.opps.core.BasePay;
import com.huifu.bspay.sdk.opps.core.config.MerConfig;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
 * 读取斗拱子商户的完整档案(只读),用来确认它被登记成什么行业。
 *
 * <p>用法:java -cp "target/classes;&lt;deps&gt;;&lt;tools&gt;" MerchantInfoProbe &lt;huifu_id&gt;
 */
public class MerchantInfoProbe {
    public static void main(String[] args) throws Exception {
        System.setOut(new java.io.PrintStream(new java.io.FileOutputStream(java.io.FileDescriptor.out), true,
                java.nio.charset.StandardCharsets.UTF_8));
        String huifuId = args.length > 0 ? args[0] : "6666000226048687";
        JsonNode huifu = new YAMLMapper().readTree(Files.newInputStream(
                Path.of("src", "main", "resources", "application.yml")))
                .path("app").path("payment").path("huifu");
        BasePay.debug = false;
        BasePay.prodMode = "prod".equalsIgnoreCase(text(huifu, "environment", "prod")) ? BasePay.MODE_PROD : BasePay.MODE_TEST;
        MerConfig config = new MerConfig();
        config.setSysId(text(huifu, "system-id", "").trim());
        config.setProductId(text(huifu, "product-id", "").trim());
        config.setRsaPrivateKey(text(huifu, "private-key", "").trim());
        config.setRsaPublicKey(text(huifu, "platform-public-key", "").trim());
        BasePay.initWithMerConfig(config);
        Map<String, Object> request = new LinkedHashMap<>();
        request.put("req_seq_id", "MI" + System.currentTimeMillis());
        request.put("req_date", LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE));
        request.put("huifu_id", huifuId.trim());
        Map<String, Object> response = BasePayClient.request(request, "v2.merchant.basicdata.query", false);
        Object raw = response.get("data");
        Map<String, Object> data = raw instanceof Map<?, ?> map ? (Map<String, Object>) map
                : raw instanceof String json && !json.isBlank() ? JSON.parseObject(json, Map.class) : response;
        System.out.println("================ 子商户档案 " + huifuId + " ================");
        for (Map.Entry<String, Object> entry : data.entrySet()) {
            String key = entry.getKey();
            Object value = entry.getValue();
            if (value instanceof List<?> || value instanceof Map<?, ?>) continue;
            String text = String.valueOf(value);
            System.out.printf("  %-26s = %s%n", key, text.length() > 120 ? text.substring(0, 120) + "..." : text);
        }
        System.out.println();
        System.out.println("== 行业相关字段 ==");
        for (String key : List.of("mcc", "ent_type", "busi_type", "scene_type", "business_scope", "industry",
                "reg_name", "short_name", "receipt_name", "mer_stat", "out_settle_flag")) {
            if (data.containsKey(key)) System.out.printf("  %-26s = %s%n", key, data.get(key));
        }
        System.out.println("=========================================================");
    }
    private static String text(JsonNode node, String field, String fallback) {
        String value = node.path(field).asText("");
        if (value.isBlank()) return fallback;
        if (value.startsWith("${") && value.endsWith("}")) {
            String inner = value.substring(2, value.length() - 1);
            int separator = inner.indexOf(':');
            value = separator >= 0 ? inner.substring(separator + 1) : "";
        }
        return value.isBlank() ? fallback : value;
    }
}