1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.talentcard.server.business.payment.huifu;
 
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Random;
import java.util.Map;
import org.yaml.snakeyaml.Yaml;
 
/**
 * Ticket02 真实配置:复用仓库真实网关 {@link HuifuMerchantWechatConfigGateway} 为已进件商户
 * 绑定人才端小程序 AppID(微信商户配置 v2.merchant.busi.config)。
 *
 * <p>不启动 Spring、不连数据库。加 {@code --dry-run} 只打印配置、不发送。
 *
 * 用法:java com.talentcard.server.business.payment.huifu.ConfigureExistingMerchantWechat <huifu_id> [--dry-run]
 */
public class ConfigureExistingMerchantWechat {
 
  public static void main(String[] args) throws Exception {
    String huifuId = args.length > 0 ? args[0] : "6666000241335656";
    boolean dryRun = args.length > 1 && "--dry-run".equals(args[1]);
 
    Map root = new Yaml().load(Files.readString(Path.of("talent-card-server/src/main/resources/application.yml")));
    HuifuPaymentProperties properties = OpenExistingMerchantWechat.properties(find(root));
 
    String requestNo = "T02WC" + LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE)
        + String.format("%06d", new Random().nextInt(1_000_000));
 
    System.out.println("### identity sys_id=" + properties.getSystemId()
        + ", product_id=" + properties.getProductId());
    System.out.println("### applet_app_id=" + properties.getMiniProgramAppId());
    System.out.println("### requestNo=" + requestNo + ", huifu_id=" + huifuId);
 
    if (dryRun) {
      System.out.println("Dry run: no API request sent");
      return;
    }
 
    HuifuMerchantWechatConfigGateway.Result result =
        new HuifuMerchantWechatConfigGateway(properties).configure(requestNo, huifuId);
    System.out.println("result accepted=" + result.accepted()
        + ", code=" + result.code()
        + ", message=" + result.message());
  }
 
  private static Map find(Map root) {
    if (root.containsKey("system-id") && root.containsKey("private-key")) return root;
    for (Object value : root.values()) {
      if (value instanceof Map nested) {
        Map found = find(nested);
        if (found != null) return found;
      }
    }
    return null;
  }
}