处理退款带证书请求
This commit is contained in:
22
pom.xml
22
pom.xml
@ -194,6 +194,28 @@
|
||||
<version>1.15</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Apache HttpClient依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.13</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Apache HttpCore依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpcore</artifactId>
|
||||
<version>4.4.14</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Apache HttpClient SSL支持 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpmime</artifactId>
|
||||
<version>4.5.13</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<!-- Build Configuration -->
|
||||
|
||||
@ -1,173 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="web" name="Web">
|
||||
<configuration>
|
||||
<webroots />
|
||||
</configuration>
|
||||
</facet>
|
||||
<facet type="Spring" name="Spring">
|
||||
<configuration />
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:2.3.12.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:2.3.12.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-context:5.2.15.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-autoconfigure:2.3.12.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-logging:2.3.12.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.2.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.2.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-to-slf4j:2.13.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.13.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:jul-to-slf4j:1.7.30" level="project" />
|
||||
<orderEntry type="library" name="Maven: jakarta.annotation:jakarta.annotation-api:1.3.5" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-core:5.2.15.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.2.15.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.26" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-web:2.3.12.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-json:2.3.12.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.11.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.11.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.11.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.module:jackson-module-parameter-names:2.11.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-tomcat:2.3.12.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-core:9.0.46" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.glassfish:jakarta.el:3.0.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-websocket:9.0.46" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-web:5.2.15.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-beans:5.2.15.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-webmvc:5.2.15.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-expression:5.2.15.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-actuator:2.3.12.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-actuator-autoconfigure:2.3.12.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-actuator:2.3.12.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.micrometer:micrometer-core:1.5.14" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.hdrhistogram:HdrHistogram:2.1.12" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: org.latencyutils:LatencyUtils:2.0.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery:2.2.9.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.alibaba.cloud:spring-cloud-alibaba-commons:2.2.9.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.alibaba.nacos:nacos-client:2.1.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.alibaba.nacos:nacos-auth-plugin:2.1.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.alibaba.nacos:nacos-encryption-plugin:2.1.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.11.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpasyncclient:4.1.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.14" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore-nio:4.4.14" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.13" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.prometheus:simpleclient:0.5.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.alibaba.spring:spring-context-support:1.0.11" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.cloud:spring-cloud-context:2.2.9.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.cloud:spring-cloud-starter-netflix-ribbon:2.2.9.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.cloud:spring-cloud-starter:2.2.9.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.security:spring-security-rsa:1.0.9.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.bouncycastle:bcpkix-jdk15on:1.64" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.bouncycastle:bcprov-jdk15on:1.64" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.cloud:spring-cloud-netflix-ribbon:2.2.9.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.cloud:spring-cloud-netflix-archaius:2.2.9.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.cloud:spring-cloud-starter-netflix-archaius:2.2.9.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.netflix.archaius:archaius-core:0.7.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-configuration:commons-configuration:1.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.netflix.ribbon:ribbon:2.3.0" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: com.netflix.ribbon:ribbon-transport:2.3.0" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: io.reactivex:rxnetty-contexts:0.4.9" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: io.reactivex:rxnetty-servo:0.4.9" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: com.netflix.hystrix:hystrix-core:1.5.18" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: javax.inject:javax.inject:1" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: io.reactivex:rxnetty:0.4.9" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.netflix.ribbon:ribbon-core:2.3.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-lang:commons-lang:2.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.netflix.ribbon:ribbon-httpclient:2.3.0" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: commons-collections:commons-collections:3.2.2" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: com.sun.jersey:jersey-client:1.19.1" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: com.sun.jersey:jersey-core:1.19.1" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: javax.ws.rs:jsr311-api:1.1.1" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: com.sun.jersey.contribs:jersey-apache-client4:1.19.1" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: com.netflix.servo:servo-core:0.12.21" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: com.netflix.netflix-commons:netflix-commons-util:0.3.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.netflix.ribbon:ribbon-loadbalancer:2.3.0" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: com.netflix.netflix-commons:netflix-statistics:0.1.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.reactivex:rxjava:1.3.8" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-configuration-processor:2.3.12.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.cloud:spring-cloud-commons:2.2.9.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.security:spring-security-crypto:5.3.9.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.projectlombok:lombok:1.18.30" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.retry:spring-retry:1.3.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.annotation:javax.annotation-api:1.3.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-aop:2.3.12.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-aop:5.2.15.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.aspectj:aspectjweaver:1.9.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-starter:2.3.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-jdbc:2.3.12.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.zaxxer:HikariCP:3.4.5" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-jdbc:5.2.15.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-autoconfigure:2.3.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis:mybatis:3.5.13" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mybatis:mybatis-spring:2.1.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.baomidou:mybatis-plus-boot-starter:3.5.3.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.baomidou:mybatis-plus:3.5.3.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.baomidou:mybatis-plus-extension:3.5.3.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.baomidou:mybatis-plus-core:3.5.3.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.baomidou:mybatis-plus-annotation:3.5.3.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.jsqlparser:jsqlparser:4.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-data-redis:2.3.12.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-redis:2.3.9.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-keyvalue:2.3.9.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-commons:2.3.9.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-tx:5.2.15.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-oxm:5.2.15.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework:spring-context-support:5.2.15.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.lettuce:lettuce-core:5.3.7.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.netty:netty-common:4.1.65.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.netty:netty-handler:4.1.65.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.netty:netty-resolver:4.1.65.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.netty:netty-buffer:4.1.65.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.netty:netty-codec:4.1.65.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.netty:netty-transport:4.1.65.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.mysql:mysql-connector-j:8.0.33" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.springfox:springfox-swagger2:2.9.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.swagger:swagger-annotations:1.5.20" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.swagger:swagger-models:1.5.20" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.11.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.springfox:springfox-spi:2.9.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.springfox:springfox-core:2.9.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: net.bytebuddy:byte-buddy:1.10.22" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.springfox:springfox-schema:2.9.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.springfox:springfox-swagger-common:2.9.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.springfox:springfox-spring-web:2.9.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.guava:guava:30.0-jre" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.guava:failureaccess:1.0.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:3.0.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.checkerframework:checker-qual:3.5.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.3.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml:classmate:1.5.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.30" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.plugin:spring-plugin-core:1.2.0.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.springframework.plugin:spring-plugin-metadata:1.2.0.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.springfox:springfox-swagger-ui:2.9.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.xml.bind:jaxb-api:2.3.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.activation:javax.activation-api:1.2.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: io.projectreactor:reactor-core:3.2.2.RELEASE" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.reactivestreams:reactive-streams:1.0.3" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mapstruct:mapstruct:1.5.5.Final" level="project" />
|
||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.mapstruct:mapstruct-processor:1.5.5.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.alibaba:fastjson:1.2.83" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.wechatpay-apiv3:wechatpay-java:0.2.14" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.github.wechatpay-apiv3:wechatpay-java-core:0.2.14" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: com.squareup.okhttp3:okhttp:3.14.9" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: com.squareup.okio:okio:1.17.2" level="project" />
|
||||
<orderEntry type="library" scope="RUNTIME" name="Maven: com.google.code.gson:gson:2.8.7" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.15" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@ -47,7 +47,7 @@ public interface OrderPayMapper {
|
||||
"where payment_id = #{paymentId} and del_flag = '0')")
|
||||
OrderMain getOrderStatusByOrderNo(@Param("paymentId") String paymentId);
|
||||
|
||||
@Update("update zc_order_main as om,zc_order_sub as os set os.transaction_id = #{refundId},os.pay_status = #{payStatus} os.amount = #{refundFee},os.update_time = #{updateTime}" +
|
||||
@Update("update zc_order_main as om,zc_order_sub as os set os.transaction_id = #{refundId},os.pay_status = #{payStatus}, os.amount = #{refundFee},os.update_time = #{updateTime}" +
|
||||
" where om.order_id = os.order_id and os.payment_id = #{outTradeNo} and os.suborder_type = 'FD_DEPOSIT'" )
|
||||
int updateSubOrderRefundStatus(@Param("outTradeNo") String outTradeNo,
|
||||
@Param("payStatus") String payStatus,
|
||||
|
||||
@ -1,11 +1,27 @@
|
||||
package com.sczx.pay.sdk;
|
||||
|
||||
import com.sczx.pay.utils.WXPayUtil;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.ssl.SSLContexts;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.security.KeyStore;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
||||
|
||||
/**
|
||||
* 微信支付接口
|
||||
*/
|
||||
@ -180,7 +196,7 @@ public class WXPay {
|
||||
String xml = WXPayUtil.mapToXml(reqData);
|
||||
logger.info("微信支付请求URL: {}, 请求数据: {}", url, xml);
|
||||
|
||||
String response = httpRequest(url, xml, connectTimeoutMs, readTimeoutMs);
|
||||
String response = httpsRequestWithCert(url, xml, connectTimeoutMs, readTimeoutMs);
|
||||
logger.info("微信支付响应数据: {}", response);
|
||||
|
||||
return response;
|
||||
@ -230,6 +246,59 @@ public class WXPay {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 带证书的HTTPS请求
|
||||
*/
|
||||
private String httpsRequestWithCert(String url, String requestData, int connectTimeoutMs, int readTimeoutMs) throws Exception {
|
||||
// 加载证书
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
FileInputStream instream = new FileInputStream(new File(this.config.getCertPath()));
|
||||
try {
|
||||
keyStore.load(instream, this.config.getMchID().toCharArray());
|
||||
} finally {
|
||||
instream.close();
|
||||
}
|
||||
|
||||
// 创建SSL上下文
|
||||
SSLContext sslcontext = SSLContexts.custom()
|
||||
.loadKeyMaterial(keyStore, this.config.getMchID().toCharArray())
|
||||
.build();
|
||||
|
||||
// 创建SSL连接工厂
|
||||
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
|
||||
sslcontext,
|
||||
new String[]{"TLSv1", "TLSv1.1", "TLSv1.2"},
|
||||
null,
|
||||
(hostname, session) -> true);
|
||||
|
||||
// 创建HTTP客户端
|
||||
CloseableHttpClient httpclient = HttpClients.custom()
|
||||
.setSSLSocketFactory(sslsf)
|
||||
.build();
|
||||
|
||||
try {
|
||||
// 创建POST请求
|
||||
HttpPost httpost = new HttpPost(url);
|
||||
httpost.addHeader("Content-Type", "application/xml;charset=UTF-8");
|
||||
httpost.setEntity(new StringEntity(requestData, "UTF-8"));
|
||||
|
||||
// 执行请求
|
||||
CloseableHttpResponse response = httpclient.execute(httpost);
|
||||
try {
|
||||
HttpEntity entity = response.getEntity();
|
||||
String result = EntityUtils.toString(response.getEntity(), "UTF-8");
|
||||
EntityUtils.consume(entity);
|
||||
return result;
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
} finally {
|
||||
httpclient.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 判断支付结果
|
||||
*/
|
||||
@ -241,4 +310,6 @@ public class WXPay {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -22,6 +22,8 @@ public abstract class WXPayConfig {
|
||||
*/
|
||||
public abstract String getKey();
|
||||
|
||||
private String certPath;
|
||||
|
||||
/**
|
||||
* 获取证书内容
|
||||
*/
|
||||
@ -40,4 +42,13 @@ public abstract class WXPayConfig {
|
||||
public int getHttpReadTimeoutMs() {
|
||||
return 8*1000;
|
||||
}
|
||||
|
||||
|
||||
public String getCertPath() {
|
||||
return certPath;
|
||||
}
|
||||
|
||||
public void setCertPath(String certPath) {
|
||||
this.certPath = certPath;
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.io.File;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
@ -248,27 +249,35 @@ public class WechatPayService {
|
||||
return errorResult;
|
||||
}
|
||||
|
||||
Map<String, String> reqData = new HashMap<>();
|
||||
reqData.put("transaction_id",String.valueOf(paymentRecord.getTransactionId()));
|
||||
reqData.put("out_trade_no", request.getOutTradeNo());
|
||||
reqData.put("out_refund_no", request.getOutRefundNo());
|
||||
reqData.put("total_fee", String.valueOf(paymentRecord.getTotalFee()));
|
||||
reqData.put("refund_fee", String.valueOf(request.getRefundFee()));
|
||||
reqData.put("notify_url",refundNotifyUrl);
|
||||
|
||||
|
||||
// 创建动态配置
|
||||
DynamicWXPayConfig wxPayConfig = new DynamicWXPayConfig(
|
||||
appId,
|
||||
companyConfig.getMchId(),
|
||||
companyConfig.getApikey(),
|
||||
notifyUrl
|
||||
refundNotifyUrl
|
||||
);
|
||||
|
||||
String certPath = "classpath*:cert/"+companyConfig.getMchId()+".p12";
|
||||
String certAbsolutePath = getCertAbsolutePath(certPath);
|
||||
wxPayConfig.setCertPath(certAbsolutePath);
|
||||
|
||||
|
||||
|
||||
WXPay wxPay = new WXPay(wxPayConfig);
|
||||
|
||||
Map<String, String> reqData = new HashMap<>();
|
||||
reqData.put("out_trade_no", request.getOutTradeNo());
|
||||
reqData.put("out_refund_no", request.getOutRefundNo());
|
||||
reqData.put("total_fee", String.valueOf(paymentRecord.getTotalFee()));
|
||||
reqData.put("refund_fee", String.valueOf(request.getRefundFee()));
|
||||
reqData.put("notify_url", refundNotifyUrl);
|
||||
|
||||
|
||||
if (request.getRefundDesc() != null) {
|
||||
reqData.put("refund_desc", request.getRefundDesc());
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 退款需要证书,这里调用带证书的接口
|
||||
Map<String, String> result = wxPay.refund(reqData);
|
||||
@ -509,4 +518,43 @@ public class WechatPayService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取证书文件的绝对路径
|
||||
*/
|
||||
private String getCertAbsolutePath(String certPath) {
|
||||
try {
|
||||
// 如果certPath是绝对路径,直接返回
|
||||
if (new File(certPath).isAbsolute()) {
|
||||
return certPath;
|
||||
}
|
||||
|
||||
// 如果是相对路径,则从classpath下获取
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
java.net.URL resource = classLoader.getResource(certPath);
|
||||
|
||||
if (resource != null) {
|
||||
return resource.getPath();
|
||||
} else {
|
||||
// 如果在classpath中找不到,则尝试从当前类的classpath下获取
|
||||
resource = WechatPayService.class.getClassLoader().getResource(certPath);
|
||||
if (resource != null) {
|
||||
return resource.getPath();
|
||||
} else {
|
||||
// 如果还找不到,则使用默认路径
|
||||
String defaultPath = "cert/1679965261.p12";
|
||||
resource = classLoader.getResource(defaultPath);
|
||||
if (resource != null) {
|
||||
return resource.getPath();
|
||||
} else {
|
||||
throw new RuntimeException("无法找到证书文件: " + certPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("获取证书路径失败", e);
|
||||
throw new RuntimeException("获取证书路径失败: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BIN
src/main/resources/cert/1679965261.p12
Normal file
BIN
src/main/resources/cert/1679965261.p12
Normal file
Binary file not shown.
BIN
src/main/resources/cert/1685128771.p12
Normal file
BIN
src/main/resources/cert/1685128771.p12
Normal file
Binary file not shown.
BIN
src/main/resources/cert/1699979689.p12
Normal file
BIN
src/main/resources/cert/1699979689.p12
Normal file
Binary file not shown.
BIN
src/main/resources/cert/1702736781.p12
Normal file
BIN
src/main/resources/cert/1702736781.p12
Normal file
Binary file not shown.
BIN
src/main/resources/cert/1704580401.p12
Normal file
BIN
src/main/resources/cert/1704580401.p12
Normal file
Binary file not shown.
Reference in New Issue
Block a user