import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; import com.talentcard.server.business.payment.huifu.HuifuDelayAccountGateway; import com.talentcard.server.business.payment.huifu.HuifuDelayAccountGateway.HuifuDelayConfirmCommand; import com.talentcard.server.business.payment.huifu.HuifuDelayAccountGateway.HuifuDelayConfirmation; import com.talentcard.server.business.payment.huifu.HuifuPaymentProperties; import java.nio.file.Files; import java.nio.file.Path; /** * 真实调用一次交易确认,验证延迟户的钱能分账进商户基本户。 * *

这是会真实分配资金的调用,只用于人工验证一笔小额。 * *

用法:java -cp "target/classes;<deps>;<tools>" ConfirmProbe <huifu_id> <payment_no> <req_date> */ public class ConfirmProbe { public static void main(String[] args) throws Exception { String huifuId = args.length > 0 ? args[0] : "6666000226048687"; String paymentNo = args.length > 1 ? args[1] : ""; String reqDate = args.length > 2 ? args[2] : ""; String providerNo = args.length > 3 ? args[3] : ""; JsonNode huifu = new YAMLMapper().readTree(Files.newInputStream( Path.of("src", "main", "resources", "application.yml"))) .path("app").path("payment").path("huifu"); HuifuPaymentProperties properties = new HuifuPaymentProperties(); properties.setEnabled(true); properties.setEnvironment(text(huifu, "environment", "prod")); properties.setSystemId(text(huifu, "system-id", "")); properties.setProductId(text(huifu, "product-id", "")); properties.setPrivateKey(text(huifu, "private-key", "")); properties.setPlatformPublicKey(text(huifu, "platform-public-key", "")); HuifuDelayAccountGateway gateway = new HuifuDelayAccountGateway(properties); String confirmNo = "DCP" + System.currentTimeMillis(); System.out.println("== 交易确认请求 =="); System.out.println(" confirm_no = " + confirmNo); System.out.println(" huifu_id = " + huifuId); System.out.println(" payment_no = " + paymentNo); System.out.println(" org_hf_seq_id= " + (providerNo.isBlank() ? "(空,按 payment_no 定位)" : providerNo)); System.out.println(); try { HuifuDelayConfirmation result = gateway.confirm(new HuifuDelayConfirmCommand( confirmNo, huifuId, paymentNo, providerNo, reqDate, "人工验证:核销后确认资金")); System.out.println("================ 交易确认回执 ================"); System.out.println(" outcome = " + result.outcome()); System.out.println(" code = " + result.code()); System.out.println(" message = " + result.describe()); System.out.println(" unconfirm_amt = " + result.unconfirmedAmount()); System.out.println(" confirmed_amt = " + result.confirmedAmount()); System.out.println(" provider_trade_no = " + result.providerTransactionNo()); System.out.println("============================================="); } catch (Exception exception) { System.out.println("!! 调用失败: " + exception.getClass().getSimpleName() + " : " + exception.getMessage()); } } 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; } }