8
8
import static org .junit .Assert .assertTrue ;
9
9
10
10
import com .wechat .pay .contrib .apache .httpclient .auth .PrivateKeySigner ;
11
+ import com .wechat .pay .contrib .apache .httpclient .auth .Verifier ;
11
12
import com .wechat .pay .contrib .apache .httpclient .auth .WechatPay2Credentials ;
12
13
import com .wechat .pay .contrib .apache .httpclient .auth .WechatPay2Validator ;
13
14
import com .wechat .pay .contrib .apache .httpclient .cert .CertificatesManager ;
@@ -37,7 +38,7 @@ public class RsaCryptoTest {
37
38
38
39
private CloseableHttpClient httpClient ;
39
40
private CertificatesManager certificatesManager ;
40
-
41
+ private Verifier verifier ;
41
42
42
43
@ Before
43
44
public void setup () throws Exception {
@@ -48,6 +49,7 @@ public void setup() throws Exception {
48
49
certificatesManager .putMerchant (mchId , new WechatPay2Credentials (mchId ,
49
50
new PrivateKeySigner (mchSerialNo , merchantPrivateKey )), apiV3Key .getBytes (StandardCharsets .UTF_8 ));
50
51
// 从证书管理器中获取verifier
52
+ verifier = certificatesManager .getVerifier (mchId );
51
53
httpClient = WechatPayHttpClientBuilder .create ()
52
54
.withMerchant (mchId , mchSerialNo , merchantPrivateKey )
53
55
.withValidator (new WechatPay2Validator (certificatesManager .getVerifier (mchId )))
@@ -62,7 +64,8 @@ public void after() throws IOException {
62
64
@ Test
63
65
public void encryptTest () throws Exception {
64
66
String text = "helloworld" ;
65
- String ciphertext = RsaCryptoUtil .encryptOAEP (text , certificatesManager .getLatestCertificate (mchId ));
67
+ String ciphertext = RsaCryptoUtil
68
+ .encryptOAEP (text , verifier .getValidCertificate ());
66
69
System .out .println ("ciphertext: " + ciphertext );
67
70
}
68
71
@@ -71,7 +74,8 @@ public void postEncryptDataTest() throws Exception {
71
74
HttpPost httpPost = new HttpPost ("https://api.mch.weixin.qq.com/v3/smartguide/guides" );
72
75
73
76
String text = "helloworld" ;
74
- String ciphertext = RsaCryptoUtil .encryptOAEP (text , certificatesManager .getLatestCertificate (mchId ));
77
+ String ciphertext = RsaCryptoUtil
78
+ .encryptOAEP (text , verifier .getValidCertificate ());
75
79
76
80
String data = "{\n "
77
81
+ " \" store_id\" : 1234,\n "
0 commit comments