or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

advanced-services.mdconfiguration-security.mdcore-payment.mdenterprise-services.mdindex.mdnotification-processing.mdpayment-methods.mdrefund-management.md

configuration-security.mddocs/

0

# Configuration and Security

1

2

Configuration management, certificate handling, signature processing, and multi-merchant support for enterprise deployments.

3

4

## Capabilities

5

6

### Basic Configuration

7

8

Core configuration setup for WeChat Pay integration.

9

10

```java { .api }

11

/**

12

* Set payment configuration

13

* @param config WeChat Pay configuration

14

*/

15

void setConfig(WxPayConfig config);

16

17

/**

18

* Get current configuration

19

* @return Current WeChat Pay configuration

20

*/

21

WxPayConfig getConfig();

22

```

23

24

**Usage Example:**

25

26

```java

27

// Create and configure WxPayConfig

28

WxPayConfig config = new WxPayConfig();

29

config.setAppId("your-app-id");

30

config.setMchId("your-merchant-id");

31

config.setMchKey("your-merchant-key");

32

config.setKeyPath("/path/to/cert.p12");

33

34

// API v3 configuration

35

config.setApiV3Key("your-api-v3-key");

36

config.setCertSerialNo("certificate-serial-number");

37

config.setPrivateKeyPath("/path/to/private-key.pem");

38

39

// Set configuration

40

wxPayService.setConfig(config);

41

```

42

43

### Multi-Merchant Support

44

45

Manage multiple merchant configurations in a single application.

46

47

```java { .api }

48

/**

49

* Add merchant configuration

50

* @param mchId Merchant ID

51

* @param wxPayConfig Merchant configuration

52

*/

53

void addConfig(String mchId, WxPayConfig wxPayConfig);

54

55

/**

56

* Remove merchant configuration

57

* @param mchId Merchant ID to remove

58

*/

59

void removeConfig(String mchId);

60

61

/**

62

* Switch to specific merchant

63

* @param mchId Target merchant ID

64

* @return true if switch successful

65

*/

66

boolean switchover(String mchId);

67

68

/**

69

* Switch to specific merchant with exception on failure

70

* @param mchId Target merchant ID

71

* @return Service instance for chaining

72

* @throws WxPayException if switch fails

73

*/

74

WxPayService switchoverTo(String mchId);

75

```

76

77

### Certificate Management

78

79

Handle WeChat Pay certificates for secure communication.

80

81

```java { .api }

82

/**

83

* Initialize V3 HTTP client with certificates

84

* @throws WxPayException if initialization fails

85

*/

86

void initV3HttpClient() throws WxPayException;

87

88

/**

89

* Get certificate serial number

90

* @return Certificate serial number

91

*/

92

String getCertSerialNo();

93

```

94

95

### Signature Operations

96

97

Generate and verify signatures for API security.

98

99

```java { .api }

100

/**

101

* Create signature for parameters

102

* @param params Parameter map

103

* @param signType Signature type

104

* @return Generated signature

105

* @throws WxPayException if signature generation fails

106

*/

107

String createSign(Map<String, String> params, SignType signType) throws WxPayException;

108

109

/**

110

* Verify signature of parameters

111

* @param params Parameter map with signature

112

* @return true if signature is valid

113

* @throws WxPayException if verification fails

114

*/

115

boolean checkSign(Map<String, String> params) throws WxPayException;

116

```

117

118

## Configuration Types

119

120

### WxPayConfig

121

122

```java { .api }

123

class WxPayConfig {

124

// Basic configuration

125

String appId; // Application ID

126

String mchId; // Merchant ID

127

String mchKey; // Merchant key

128

String keyPath; // Certificate path (.p12)

129

130

// API v3 configuration

131

String apiV3Key; // API v3 key

132

String certSerialNo; // Certificate serial number

133

String privateKeyPath; // Private key path

134

String privateCertPath; // Private certificate path

135

136

// HTTP configuration

137

Integer httpConnectionTimeout; // Connection timeout

138

Integer httpTimeout; // Request timeout

139

WxPayHttpProxy httpProxy; // Proxy configuration

140

141

// Environment settings

142

boolean useSandbox; // Use sandbox environment

143

boolean autoReport; // Auto error reporting

144

145

// Methods

146

void setKeyContent(byte[] keyContent);

147

void setPrivateKeyContent(byte[] privateKeyContent);

148

void setSandbox(boolean sandbox);

149

}

150

```

151

152

### Security Features

153

154

```java { .api }

155

// Signature types

156

enum SignType {

157

MD5,

158

HMAC_SHA256

159

}

160

161

// Certificate utilities

162

class CertificateUtils {

163

static X509Certificate loadCertificate(String certPath);

164

static PrivateKey loadPrivateKey(String keyPath);

165

}

166

```