|
@@ -9,8 +9,6 @@ import com.qcloud.cos.http.HttpProtocol;
|
|
|
import com.qcloud.cos.region.Region;
|
|
|
import com.wechat.pay.contrib.apache.httpclient.WechatPayHttpClientBuilder;
|
|
|
import com.wechat.pay.contrib.apache.httpclient.auth.AutoUpdateCertificatesVerifier;
|
|
|
-import com.wechat.pay.contrib.apache.httpclient.auth.PrivateKeySigner;
|
|
|
-import com.wechat.pay.contrib.apache.httpclient.auth.WechatPay2Credentials;
|
|
|
import com.wechat.pay.contrib.apache.httpclient.auth.WechatPay2Validator;
|
|
|
import org.apache.http.client.HttpClient;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -20,15 +18,7 @@ import org.springframework.context.annotation.Configuration;
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
|
|
|
import java.io.File;
|
|
|
-import java.io.IOException;
|
|
|
-import java.nio.file.Files;
|
|
|
-import java.nio.file.Paths;
|
|
|
-import java.security.KeyFactory;
|
|
|
-import java.security.NoSuchAlgorithmException;
|
|
|
import java.security.PrivateKey;
|
|
|
-import java.security.spec.InvalidKeySpecException;
|
|
|
-import java.security.spec.PKCS8EncodedKeySpec;
|
|
|
-import java.util.Base64;
|
|
|
|
|
|
|
|
|
@Configuration
|
|
@@ -49,7 +39,13 @@ public class BeanConfig {
|
|
|
|
|
|
@Autowired
|
|
|
private WxpayConfig wxpayConfig;
|
|
|
+ @Autowired
|
|
|
+ private AutoUpdateCertificatesVerifier verifier;
|
|
|
|
|
|
+ /**
|
|
|
+ * 腾讯云 COS
|
|
|
+ * @return
|
|
|
+ */
|
|
|
|
|
|
@Bean
|
|
|
public COSClient configBean() {
|
|
@@ -69,17 +65,16 @@ public class BeanConfig {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 微信支付 httpclient 对象
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
@Bean
|
|
|
public HttpClient wxpayConfigBean() throws Exception{
|
|
|
File file = new ClassPathResource("wechatpay/apiclient_key.pem").getFile();
|
|
|
String realPath =file.getAbsolutePath();
|
|
|
PrivateKey privateKey = CommonUtils.getPrivateKey(realPath);
|
|
|
- // 加载平台证书(mchId:商户号,mchSerialNo:商户证书序列号,apiV3Key:V3密钥)
|
|
|
- AutoUpdateCertificatesVerifier verifier = new AutoUpdateCertificatesVerifier(
|
|
|
- new WechatPay2Credentials(wxpayConfig.getMerchantId(),
|
|
|
- new PrivateKeySigner(wxpayConfig.getSerialNumber(), privateKey)),
|
|
|
- wxpayConfig.getV3key().getBytes("utf-8"));
|
|
|
-
|
|
|
// 初始化httpClient
|
|
|
HttpClient httpClient = WechatPayHttpClientBuilder.create()
|
|
|
.withMerchant(wxpayConfig.getMerchantId(), wxpayConfig.getSerialNumber(), privateKey)
|
|
@@ -88,4 +83,7 @@ public class BeanConfig {
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|