mirror of
https://github.com/dromara/payment-spring-boot.git
synced 2026-03-13 21:33:41 +08:00
'init'
This commit is contained in:
@@ -12,8 +12,8 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>7</source>
|
||||
<target>7</target>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
@@ -70,14 +70,17 @@
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15to18</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.enongm.dianji.payment.alipay.configuration;
|
||||
package com.enongm.dianji.payment.autoconfigure;
|
||||
|
||||
import com.enongm.dianji.payment.autoconfigure.AliPayProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.enongm.dianji.payment.alipay.configuration;
|
||||
package com.enongm.dianji.payment.autoconfigure;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.enongm.dianji.payment.autoconfigure;
|
||||
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
/**
|
||||
* @author Dax
|
||||
* @since 9:49
|
||||
*/
|
||||
@Import(WechatPayConfiguration.class)
|
||||
public @interface EnableWechatPay {
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import com.enongm.dianji.payment.wechat.WechatPayV3Service;
|
||||
import com.enongm.dianji.payment.wechat.v2.WechatPayV2Service;
|
||||
import com.enongm.dianji.payment.wechat.v3.SignatureProvider;
|
||||
import com.enongm.dianji.payment.wechat.v3.model.WechatMetaBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -14,12 +15,13 @@ import org.springframework.context.annotation.Configuration;
|
||||
* The type Wechat pay configuration.
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnProperty(prefix = "wechat.pay",havingValue = "v3")
|
||||
@EnableConfigurationProperties(WechatPayProperties.class)
|
||||
public class WechatPayConfiguration {
|
||||
private static final String CERT_ALIAS = "Tenpay Certificate";
|
||||
|
||||
/**
|
||||
* 微信支付公私钥 以及序列号.
|
||||
* 微信支付公私钥 以及序列号等元数据.
|
||||
*
|
||||
* @param wechatPayProperties the wechat pay properties
|
||||
* @return the wechat cert bean
|
||||
@@ -35,13 +37,13 @@ public class WechatPayConfiguration {
|
||||
}
|
||||
|
||||
/**
|
||||
* Signature provider signature provider.
|
||||
* 微信支付V3签名工具.
|
||||
*
|
||||
* @param wechatMetaBean the wechat meta bean
|
||||
* @return the signature provider
|
||||
*/
|
||||
@Bean
|
||||
public SignatureProvider signatureProvider(WechatMetaBean wechatMetaBean) {
|
||||
SignatureProvider signatureProvider(WechatMetaBean wechatMetaBean) {
|
||||
return new SignatureProvider(wechatMetaBean);
|
||||
}
|
||||
|
||||
@@ -58,7 +60,7 @@ public class WechatPayConfiguration {
|
||||
}
|
||||
|
||||
/**
|
||||
* Wechat pay service wechat pay service.
|
||||
* 微信支付V3 全量支持.
|
||||
*
|
||||
* @param signatureProvider the signature provider
|
||||
* @return the wechat pay service
|
||||
|
||||
@@ -5,22 +5,37 @@ import com.enongm.dianji.payment.autoconfigure.WechatPayProperties;
|
||||
import com.enongm.dianji.payment.wechat.v2.model.BaseModel;
|
||||
|
||||
/**
|
||||
* The type Wechat pay v 2 service.
|
||||
*
|
||||
* @author Dax
|
||||
* @since 15:15
|
||||
* @since 15 :15
|
||||
*/
|
||||
public class WechatPayV2Service {
|
||||
|
||||
private final WechatPayProperties wechatPayProperties;
|
||||
|
||||
/**
|
||||
* Instantiates a new Wechat pay v 2 service.
|
||||
*
|
||||
* @param wechatPayProperties the wechat pay properties
|
||||
*/
|
||||
public WechatPayV2Service(WechatPayProperties wechatPayProperties) {
|
||||
this.wechatPayProperties = wechatPayProperties;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Model base model.
|
||||
*
|
||||
* @param <M> the type parameter
|
||||
* @param model the model
|
||||
* @return the base model
|
||||
*/
|
||||
public <M extends BaseModel> BaseModel model(M model) {
|
||||
WechatPayProperties.V3 v3 = wechatPayProperties.getV3();
|
||||
return model.appId(v3.getAppId())
|
||||
.mchId(v3.getMchId());
|
||||
.mchId(v3.getMchId())
|
||||
.appSecret(v3.getAppSecret());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.bouncycastle.crypto.Digest;
|
||||
import org.bouncycastle.crypto.digests.MD5Digest;
|
||||
import org.bouncycastle.util.encoders.Hex;
|
||||
import org.springframework.util.AlternativeJdkIdGenerator;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.IdGenerator;
|
||||
|
||||
|
||||
@@ -52,7 +53,7 @@ public class BaseModel {
|
||||
private String mchid;
|
||||
private String sign;
|
||||
@JsonIgnore
|
||||
private String key;
|
||||
private String appSecret;
|
||||
@JsonIgnore
|
||||
private V2PayType payType;
|
||||
|
||||
@@ -72,6 +73,11 @@ public class BaseModel {
|
||||
return this;
|
||||
}
|
||||
|
||||
public BaseModel appSecret(String appSecret) {
|
||||
this.appSecret = appSecret;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Xml string.
|
||||
*
|
||||
@@ -79,15 +85,8 @@ public class BaseModel {
|
||||
*/
|
||||
@SneakyThrows
|
||||
public String xml() {
|
||||
|
||||
|
||||
|
||||
this.key = "Djkjchina19491001";
|
||||
String link = link(this, key);
|
||||
|
||||
String link = link(this);
|
||||
this.sign = this.bouncyCastleMD5(link);
|
||||
|
||||
|
||||
return MAPPER.writer()
|
||||
.withRootName("xml")
|
||||
.writeValueAsString(this);
|
||||
@@ -116,8 +115,10 @@ public class BaseModel {
|
||||
* @return the map
|
||||
*/
|
||||
@SneakyThrows
|
||||
private <T> String link(T t, String apiKey) {
|
||||
|
||||
private <T> String link(T t) {
|
||||
Assert.hasText(this.mchAppid, "wechat pay appId is required");
|
||||
Assert.hasText(this.mchid, "wechat pay mchId is required");
|
||||
Assert.hasText(appSecret, "wechat pay appSecret is required");
|
||||
return new ObjectMapper()
|
||||
.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true)
|
||||
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
|
||||
@@ -128,13 +129,13 @@ public class BaseModel {
|
||||
.replaceAll("\",\"", "&")
|
||||
.replaceAll("\\{\"", "")
|
||||
.replaceAll("\"}", "")
|
||||
.concat("&key=").concat(apiKey);
|
||||
.concat("&key=").concat(this.appSecret);
|
||||
}
|
||||
|
||||
|
||||
@SneakyThrows
|
||||
public WechatResponseBody request() {
|
||||
|
||||
Assert.notNull(payType, "wechat pay payType is required");
|
||||
Request request = new Request.Builder()
|
||||
.method(payType.method(), RequestBody.create(MediaType.parse("application/x-www-form-urlencoded"), this.xml()))
|
||||
.url(payType.defaultUri(WeChatServer.CHINA))
|
||||
|
||||
@@ -38,6 +38,18 @@
|
||||
<groupId>com.enongm.dianji</groupId>
|
||||
<artifactId>payment-spring-boot-autoconfigure</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15to18</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
Reference in New Issue
Block a user