package com.zsElectric.boot.sdk; /** * 众水电力SDK配置类 * * @author wzq */ public class ZsElectricConfig { /** * 服务端地址 (例: https://api.example.com) */ private String baseUrl; /** * 运营商ID (9位,由数字及大小写字符组成) */ private String operatorId; /** * 运营商密钥 */ private String operatorSecret; /** * 数据加密密钥 (16位) */ private String dataSecret; /** * 数据加密IV (16位) */ private String dataSecretIV; /** * 签名密钥 */ private String sigSecret; /** * 连接超时时间(毫秒),默认10秒 */ private int connectTimeout = 10000; /** * 读取超时时间(毫秒),默认30秒 */ private int readTimeout = 30000; private ZsElectricConfig() { } public static Builder builder() { return new Builder(); } public static class Builder { private final ZsElectricConfig config = new ZsElectricConfig(); public Builder baseUrl(String baseUrl) { config.baseUrl = baseUrl.endsWith("/") ? baseUrl.substring(0, baseUrl.length() - 1) : baseUrl; return this; } public Builder operatorId(String operatorId) { config.operatorId = operatorId; return this; } public Builder operatorSecret(String operatorSecret) { config.operatorSecret = operatorSecret; return this; } public Builder dataSecret(String dataSecret) { config.dataSecret = dataSecret; return this; } public Builder dataSecretIV(String dataSecretIV) { config.dataSecretIV = dataSecretIV; return this; } public Builder sigSecret(String sigSecret) { config.sigSecret = sigSecret; return this; } public Builder connectTimeout(int connectTimeout) { config.connectTimeout = connectTimeout; return this; } public Builder readTimeout(int readTimeout) { config.readTimeout = readTimeout; return this; } public ZsElectricConfig build() { // 参数校验 if (config.baseUrl == null || config.baseUrl.isEmpty()) { throw new IllegalArgumentException("baseUrl不能为空"); } if (config.operatorId == null || config.operatorId.isEmpty()) { throw new IllegalArgumentException("operatorId不能为空"); } if (config.operatorSecret == null || config.operatorSecret.isEmpty()) { throw new IllegalArgumentException("operatorSecret不能为空"); } if (config.dataSecret == null || config.dataSecret.length() != 16) { throw new IllegalArgumentException("dataSecret必须为16位"); } if (config.dataSecretIV == null || config.dataSecretIV.length() != 16) { throw new IllegalArgumentException("dataSecretIV必须为16位"); } if (config.sigSecret == null || config.sigSecret.isEmpty()) { throw new IllegalArgumentException("sigSecret不能为空"); } return config; } } // Getters public String getBaseUrl() { return baseUrl; } public String getOperatorId() { return operatorId; } public String getOperatorSecret() { return operatorSecret; } public String getDataSecret() { return dataSecret; } public String getDataSecretIV() { return dataSecretIV; } public String getSigSecret() { return sigSecret; } public int getConnectTimeout() { return connectTimeout; } public int getReadTimeout() { return readTimeout; } }