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; /** * 读取斗拱子商户的完整档案(只读),用来确认它被登记成什么行业。 * *

用法:java -cp "target/classes;<deps>;<tools>" MerchantInfoProbe <huifu_id> */ 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 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 response = BasePayClient.request(request, "v2.merchant.basicdata.query", false); Object raw = response.get("data"); Map data = raw instanceof Map map ? (Map) map : raw instanceof String json && !json.isBlank() ? JSON.parseObject(json, Map.class) : response; System.out.println("================ 子商户档案 " + huifuId + " ================"); for (Map.Entry 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; } }