123
This commit is contained in:
7
pom.xml
7
pom.xml
@@ -317,6 +317,12 @@
|
|||||||
<version>${ruoyi-vue-plus.version}</version>
|
<version>${ruoyi-vue-plus.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>ruoyi-alipay</artifactId>
|
||||||
|
<version>${ruoyi-vue-plus.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- demo模块 -->
|
<!-- demo模块 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
@@ -339,6 +345,7 @@
|
|||||||
<module>ruoyi-yunxin</module>
|
<module>ruoyi-yunxin</module>
|
||||||
<module>ruoyi-websocket-boot</module>
|
<module>ruoyi-websocket-boot</module>
|
||||||
<module>ruoyi-sensitive-word</module>
|
<module>ruoyi-sensitive-word</module>
|
||||||
|
<module>ruoyi-alipay</module>
|
||||||
</modules>
|
</modules>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
|
|||||||
400
ruoyi-admin/src/main/java/com/ijpay/alipay/AliPayApiConfig.java
Normal file
400
ruoyi-admin/src/main/java/com/ijpay/alipay/AliPayApiConfig.java
Normal file
@@ -0,0 +1,400 @@
|
|||||||
|
package com.ijpay.alipay;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.alipay.api.AlipayApiException;
|
||||||
|
import com.alipay.api.AlipayClient;
|
||||||
|
import com.alipay.api.CertAlipayRequest;
|
||||||
|
import com.alipay.api.DefaultAlipayClient;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>IJPay 让支付触手可及,封装了微信支付、支付宝支付、银联支付常用的支付方式以及各种常用的接口。</p>
|
||||||
|
*
|
||||||
|
* <p>不依赖任何第三方 mvc 框架,仅仅作为工具使用简单快速完成支付模块的开发,可轻松嵌入到任何系统里。 </p>
|
||||||
|
*
|
||||||
|
* <p>IJPay 交流群: 723992875、864988890</p>
|
||||||
|
*
|
||||||
|
* <p>Node.js 版: https://gitee.com/javen205/TNWXX</p>
|
||||||
|
*
|
||||||
|
* <p>支付宝支付配置</p>
|
||||||
|
*
|
||||||
|
* @author Javen
|
||||||
|
*/
|
||||||
|
public class AliPayApiConfig implements Serializable {
|
||||||
|
private static final long serialVersionUID = -4736760736935998953L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用私钥
|
||||||
|
*/
|
||||||
|
private String privateKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付宝公钥
|
||||||
|
*/
|
||||||
|
private String aliPayPublicKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用编号
|
||||||
|
*/
|
||||||
|
private String appId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付宝支付网关
|
||||||
|
*/
|
||||||
|
private String serviceUrl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字符集,为空默认为 UTF-8
|
||||||
|
*/
|
||||||
|
private String charset;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 为空默认为 RSA2
|
||||||
|
*/
|
||||||
|
private String signType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 为空默认为 JSON
|
||||||
|
*/
|
||||||
|
private String format;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否为证书模式
|
||||||
|
*/
|
||||||
|
private boolean certModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用公钥证书 (证书模式必须)
|
||||||
|
*/
|
||||||
|
private String appCertPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用公钥证书文本内容
|
||||||
|
*/
|
||||||
|
private String appCertContent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付宝公钥证书 (证书模式必须)
|
||||||
|
*/
|
||||||
|
private String aliPayCertPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付宝公钥证书文本内容
|
||||||
|
*/
|
||||||
|
private String aliPayCertContent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付宝根证书 (证书模式必须)
|
||||||
|
*/
|
||||||
|
private String aliPayRootCertPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付宝根证书文本内容
|
||||||
|
*/
|
||||||
|
private String aliPayRootCertContent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付宝客户端
|
||||||
|
*/
|
||||||
|
private AlipayClient alipayClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 其他附加参数
|
||||||
|
*/
|
||||||
|
private Object exParams;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 域名
|
||||||
|
*/
|
||||||
|
private String domain;
|
||||||
|
|
||||||
|
private Integer proxyPort;
|
||||||
|
private String proxyIp;
|
||||||
|
|
||||||
|
private AliPayApiConfig() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AliPayApiConfig builder() {
|
||||||
|
return new AliPayApiConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 普通公钥方式
|
||||||
|
*
|
||||||
|
* @return AliPayApiConfig 支付宝配置
|
||||||
|
*/
|
||||||
|
public AliPayApiConfig build() {
|
||||||
|
this.alipayClient = new DefaultAlipayClient(getServiceUrl(), getAppId(), getPrivateKey(), getFormat(),
|
||||||
|
getCharset(), getAliPayPublicKey(), getSignType());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig buildProxy() {
|
||||||
|
this.alipayClient = new DefaultAlipayClient(getServiceUrl(), getAppId(), getPrivateKey(), getFormat(),
|
||||||
|
getCharset(), getAliPayPublicKey(), getSignType(), getProxyIp(),getProxyPort());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 证书模式
|
||||||
|
*
|
||||||
|
* @return AliPayApiConfig 支付宝配置
|
||||||
|
* @throws AlipayApiException 支付宝 Api 异常
|
||||||
|
*/
|
||||||
|
public AliPayApiConfig buildByCert() throws AlipayApiException {
|
||||||
|
return build(getAppCertPath(), getAliPayCertPath(), getAliPayRootCertPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 证书模式
|
||||||
|
*
|
||||||
|
* @return AliPayApiConfig 支付宝配置
|
||||||
|
* @throws AlipayApiException 支付宝 Api 异常
|
||||||
|
*/
|
||||||
|
public AliPayApiConfig buildByCertContent() throws AlipayApiException {
|
||||||
|
return buildByCertContent(getAppCertContent(), getAliPayCertContent(), getAliPayRootCertContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param appCertPath 应用公钥证书路径
|
||||||
|
* @param aliPayCertPath 支付宝公钥证书文件路径
|
||||||
|
* @param aliPayRootCertPath 支付宝CA根证书文件路径
|
||||||
|
* @return {@link AliPayApiConfig} 支付宝支付配置
|
||||||
|
* @throws AlipayApiException 支付宝 Api 异常
|
||||||
|
*/
|
||||||
|
public AliPayApiConfig build(String appCertPath, String aliPayCertPath, String aliPayRootCertPath) throws AlipayApiException {
|
||||||
|
CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
|
||||||
|
certAlipayRequest.setServerUrl(getServiceUrl());
|
||||||
|
certAlipayRequest.setAppId(getAppId());
|
||||||
|
certAlipayRequest.setPrivateKey(getPrivateKey());
|
||||||
|
certAlipayRequest.setFormat(getFormat());
|
||||||
|
certAlipayRequest.setCharset(getCharset());
|
||||||
|
certAlipayRequest.setSignType(getSignType());
|
||||||
|
certAlipayRequest.setCertPath(appCertPath);
|
||||||
|
certAlipayRequest.setAlipayPublicCertPath(aliPayCertPath);
|
||||||
|
certAlipayRequest.setRootCertPath(aliPayRootCertPath);
|
||||||
|
this.alipayClient = new DefaultAlipayClient(certAlipayRequest);
|
||||||
|
this.certModel = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param appCertContent 应用公钥证书
|
||||||
|
* @param aliPayCertContent 支付宝公钥证书
|
||||||
|
* @param aliPayRootCertContent 支付宝CA根证书
|
||||||
|
* @return {@link AliPayApiConfig} 支付宝支付配置
|
||||||
|
* @throws AlipayApiException 支付宝 Api 异常
|
||||||
|
*/
|
||||||
|
public AliPayApiConfig buildByCertContent(String appCertContent, String aliPayCertContent, String aliPayRootCertContent) throws AlipayApiException {
|
||||||
|
CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
|
||||||
|
certAlipayRequest.setServerUrl(getServiceUrl());
|
||||||
|
certAlipayRequest.setAppId(getAppId());
|
||||||
|
certAlipayRequest.setPrivateKey(getPrivateKey());
|
||||||
|
certAlipayRequest.setFormat(getFormat());
|
||||||
|
certAlipayRequest.setCharset(getCharset());
|
||||||
|
certAlipayRequest.setSignType(getSignType());
|
||||||
|
certAlipayRequest.setCertContent(appCertContent);
|
||||||
|
certAlipayRequest.setAlipayPublicCertContent(aliPayCertContent);
|
||||||
|
certAlipayRequest.setRootCertContent(aliPayRootCertContent);
|
||||||
|
this.alipayClient = new DefaultAlipayClient(certAlipayRequest);
|
||||||
|
this.certModel = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPrivateKey() {
|
||||||
|
if (StrUtil.isBlank(privateKey)) {
|
||||||
|
throw new IllegalStateException("privateKey 未被赋值");
|
||||||
|
}
|
||||||
|
return privateKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setPrivateKey(String privateKey) {
|
||||||
|
if (StrUtil.isEmpty(privateKey)) {
|
||||||
|
throw new IllegalArgumentException("privateKey 值不能为 null");
|
||||||
|
}
|
||||||
|
this.privateKey = privateKey;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAliPayPublicKey() {
|
||||||
|
return aliPayPublicKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setAliPayPublicKey(String aliPayPublicKey) {
|
||||||
|
this.aliPayPublicKey = aliPayPublicKey;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAppId() {
|
||||||
|
if (StrUtil.isEmpty(appId)) {
|
||||||
|
throw new IllegalStateException("appId 未被赋值");
|
||||||
|
}
|
||||||
|
return appId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setAppId(String appId) {
|
||||||
|
if (StrUtil.isEmpty(appId)) {
|
||||||
|
throw new IllegalArgumentException("appId 值不能为 null");
|
||||||
|
}
|
||||||
|
this.appId = appId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getServiceUrl() {
|
||||||
|
if (StrUtil.isEmpty(serviceUrl)) {
|
||||||
|
throw new IllegalStateException("serviceUrl 未被赋值");
|
||||||
|
}
|
||||||
|
return serviceUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setServiceUrl(String serviceUrl) {
|
||||||
|
if (StrUtil.isEmpty(serviceUrl)) {
|
||||||
|
serviceUrl = "https://openapi.alipay.com/gateway.do";
|
||||||
|
}
|
||||||
|
this.serviceUrl = serviceUrl;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCharset() {
|
||||||
|
if (StrUtil.isEmpty(charset)) {
|
||||||
|
charset = "UTF-8";
|
||||||
|
}
|
||||||
|
return charset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setCharset(String charset) {
|
||||||
|
if (StrUtil.isEmpty(charset)) {
|
||||||
|
charset = "UTF-8";
|
||||||
|
}
|
||||||
|
this.charset = charset;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSignType() {
|
||||||
|
if (StrUtil.isEmpty(signType)) {
|
||||||
|
signType = "RSA2";
|
||||||
|
}
|
||||||
|
return signType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setSignType(String signType) {
|
||||||
|
if (StrUtil.isEmpty(signType)) {
|
||||||
|
signType = "RSA2";
|
||||||
|
}
|
||||||
|
this.signType = signType;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFormat() {
|
||||||
|
if (StrUtil.isEmpty(format)) {
|
||||||
|
format = "json";
|
||||||
|
}
|
||||||
|
return format;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAppCertPath() {
|
||||||
|
return appCertPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setAppCertPath(String appCertPath) {
|
||||||
|
this.appCertPath = appCertPath;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAppCertContent() {
|
||||||
|
return appCertContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setAppCertContent(String appCertContent) {
|
||||||
|
this.appCertContent = appCertContent;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAliPayCertPath() {
|
||||||
|
return aliPayCertPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setAliPayCertPath(String aliPayCertPath) {
|
||||||
|
this.aliPayCertPath = aliPayCertPath;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAliPayCertContent() {
|
||||||
|
return aliPayCertContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setAliPayCertContent(String aliPayCertContent) {
|
||||||
|
this.aliPayCertContent = aliPayCertContent;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAliPayRootCertPath() {
|
||||||
|
return aliPayRootCertPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setAliPayRootCertPath(String aliPayRootCertPath) {
|
||||||
|
this.aliPayRootCertPath = aliPayRootCertPath;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAliPayRootCertContent() {
|
||||||
|
return aliPayRootCertContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setAliPayRootCertContent(String aliPayRootCertContent) {
|
||||||
|
this.aliPayRootCertContent = aliPayRootCertContent;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCertModel() {
|
||||||
|
return certModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setCertModel(boolean certModel) {
|
||||||
|
this.certModel = certModel;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AlipayClient getAliPayClient() {
|
||||||
|
if (alipayClient == null) {
|
||||||
|
throw new IllegalStateException("aliPayClient 未被初始化");
|
||||||
|
}
|
||||||
|
return alipayClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getExParams() {
|
||||||
|
return exParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setExParams(Object exParams) {
|
||||||
|
this.exParams = exParams;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDomain() {
|
||||||
|
return domain;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setDomain(String domain) {
|
||||||
|
this.domain = domain;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Integer getProxyPort() {
|
||||||
|
return proxyPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProxyPort(Integer proxyPort) {
|
||||||
|
this.proxyPort = proxyPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProxyIp() {
|
||||||
|
return proxyIp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProxyIp(String proxyIp) {
|
||||||
|
this.proxyIp = proxyIp;
|
||||||
|
}
|
||||||
|
}
|
||||||
53
ruoyi-alipay/pom.xml
Normal file
53
ruoyi-alipay/pom.xml
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>ruoyi-vue-plus</artifactId>
|
||||||
|
<version>4.8.2</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>ruoyi-alipay</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<alipay.version>4.38.149.ALL</alipay.version>
|
||||||
|
<fastjson.version>2.0.42</fastjson.version>
|
||||||
|
<hutool.version>5.8.23</hutool.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alipay.sdk</groupId>
|
||||||
|
<artifactId>alipay-sdk-java</artifactId>
|
||||||
|
<version>${alipay.version}</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<artifactId>fastjson</artifactId>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.servlet</groupId>
|
||||||
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
|
<version>4.0.1</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>fastjson</artifactId>
|
||||||
|
<version>${fastjson.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-crypto</artifactId>
|
||||||
|
<version>${hutool.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
2790
ruoyi-alipay/src/main/java/com/ijpay/alipay/AliPayApi.java
Normal file
2790
ruoyi-alipay/src/main/java/com/ijpay/alipay/AliPayApi.java
Normal file
File diff suppressed because it is too large
Load Diff
402
ruoyi-alipay/src/main/java/com/ijpay/alipay/AliPayApiConfig.java
Normal file
402
ruoyi-alipay/src/main/java/com/ijpay/alipay/AliPayApiConfig.java
Normal file
@@ -0,0 +1,402 @@
|
|||||||
|
package com.ijpay.alipay;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.alipay.api.AlipayApiException;
|
||||||
|
import com.alipay.api.AlipayClient;
|
||||||
|
import com.alipay.api.CertAlipayRequest;
|
||||||
|
import com.alipay.api.DefaultAlipayClient;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>IJPay 让支付触手可及,封装了微信支付、支付宝支付、银联支付常用的支付方式以及各种常用的接口。</p>
|
||||||
|
*
|
||||||
|
* <p>不依赖任何第三方 mvc 框架,仅仅作为工具使用简单快速完成支付模块的开发,可轻松嵌入到任何系统里。 </p>
|
||||||
|
*
|
||||||
|
* <p>IJPay 交流群: 723992875、864988890</p>
|
||||||
|
*
|
||||||
|
* <p>Node.js 版: https://gitee.com/javen205/TNWXX</p>
|
||||||
|
*
|
||||||
|
* <p>支付宝支付配置</p>
|
||||||
|
*
|
||||||
|
* @author Javen
|
||||||
|
*/
|
||||||
|
public class AliPayApiConfig implements Serializable {
|
||||||
|
private static final long serialVersionUID = -4736760736935998953L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用私钥
|
||||||
|
*/
|
||||||
|
private String privateKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付宝公钥
|
||||||
|
*/
|
||||||
|
private String aliPayPublicKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用编号
|
||||||
|
*/
|
||||||
|
private String appId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付宝支付网关
|
||||||
|
*/
|
||||||
|
private String serviceUrl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字符集,为空默认为 UTF-8
|
||||||
|
*/
|
||||||
|
private String charset;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 为空默认为 RSA2
|
||||||
|
*/
|
||||||
|
private String signType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 为空默认为 JSON
|
||||||
|
*/
|
||||||
|
private String format;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否为证书模式
|
||||||
|
*/
|
||||||
|
private boolean certModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用公钥证书 (证书模式必须)
|
||||||
|
*/
|
||||||
|
private String appCertPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用公钥证书文本内容
|
||||||
|
*/
|
||||||
|
private String appCertContent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付宝公钥证书 (证书模式必须)
|
||||||
|
*/
|
||||||
|
private String aliPayCertPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付宝公钥证书文本内容
|
||||||
|
*/
|
||||||
|
private String aliPayCertContent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付宝根证书 (证书模式必须)
|
||||||
|
*/
|
||||||
|
private String aliPayRootCertPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付宝根证书文本内容
|
||||||
|
*/
|
||||||
|
private String aliPayRootCertContent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付宝客户端
|
||||||
|
*/
|
||||||
|
private AlipayClient alipayClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 其他附加参数
|
||||||
|
*/
|
||||||
|
private Object exParams;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 域名
|
||||||
|
*/
|
||||||
|
private String domain;
|
||||||
|
|
||||||
|
private Integer proxyPort;
|
||||||
|
private String proxyIp;
|
||||||
|
|
||||||
|
private AliPayApiConfig() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AliPayApiConfig builder() {
|
||||||
|
return new AliPayApiConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 普通公钥方式
|
||||||
|
*
|
||||||
|
* @return AliPayApiConfig 支付宝配置
|
||||||
|
*/
|
||||||
|
public AliPayApiConfig build() {
|
||||||
|
this.alipayClient = new DefaultAlipayClient(getServiceUrl(), getAppId(), getPrivateKey(), getFormat(),
|
||||||
|
getCharset(), getAliPayPublicKey(), getSignType());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig buildProxy() {
|
||||||
|
this.alipayClient = new DefaultAlipayClient(getServiceUrl(), getAppId(), getPrivateKey(), getFormat(),
|
||||||
|
getCharset(), getAliPayPublicKey(), getSignType(), getProxyIp(),getProxyPort());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 证书模式
|
||||||
|
*
|
||||||
|
* @return AliPayApiConfig 支付宝配置
|
||||||
|
* @throws AlipayApiException 支付宝 Api 异常
|
||||||
|
*/
|
||||||
|
public AliPayApiConfig buildByCert() throws AlipayApiException {
|
||||||
|
return build(getAppCertPath(), getAliPayCertPath(), getAliPayRootCertPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 证书模式
|
||||||
|
*
|
||||||
|
* @return AliPayApiConfig 支付宝配置
|
||||||
|
* @throws AlipayApiException 支付宝 Api 异常
|
||||||
|
*/
|
||||||
|
public AliPayApiConfig buildByCertContent() throws AlipayApiException {
|
||||||
|
return buildByCertContent(getAppCertContent(), getAliPayCertContent(), getAliPayRootCertContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param appCertPath 应用公钥证书路径
|
||||||
|
* @param aliPayCertPath 支付宝公钥证书文件路径
|
||||||
|
* @param aliPayRootCertPath 支付宝CA根证书文件路径
|
||||||
|
* @return {@link AliPayApiConfig} 支付宝支付配置
|
||||||
|
* @throws AlipayApiException 支付宝 Api 异常
|
||||||
|
*/
|
||||||
|
public AliPayApiConfig build(String appCertPath, String aliPayCertPath, String aliPayRootCertPath) throws AlipayApiException {
|
||||||
|
CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
|
||||||
|
certAlipayRequest.setServerUrl(getServiceUrl());
|
||||||
|
certAlipayRequest.setAppId(getAppId());
|
||||||
|
certAlipayRequest.setPrivateKey(getPrivateKey());
|
||||||
|
certAlipayRequest.setFormat(getFormat());
|
||||||
|
certAlipayRequest.setCharset(getCharset());
|
||||||
|
certAlipayRequest.setSignType(getSignType());
|
||||||
|
certAlipayRequest.setCertPath(appCertPath);
|
||||||
|
certAlipayRequest.setAlipayPublicCertPath(aliPayCertPath);
|
||||||
|
certAlipayRequest.setRootCertPath(aliPayRootCertPath);
|
||||||
|
this.alipayClient = new DefaultAlipayClient(certAlipayRequest);
|
||||||
|
this.certModel = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param appCertContent 应用公钥证书
|
||||||
|
* @param aliPayCertContent 支付宝公钥证书
|
||||||
|
* @param aliPayRootCertContent 支付宝CA根证书
|
||||||
|
* @return {@link AliPayApiConfig} 支付宝支付配置
|
||||||
|
* @throws AlipayApiException 支付宝 Api 异常
|
||||||
|
*/
|
||||||
|
public AliPayApiConfig buildByCertContent(String appCertContent, String aliPayCertContent, String aliPayRootCertContent) throws AlipayApiException {
|
||||||
|
CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
|
||||||
|
certAlipayRequest.setServerUrl(getServiceUrl());
|
||||||
|
certAlipayRequest.setAppId(getAppId());
|
||||||
|
certAlipayRequest.setPrivateKey(getPrivateKey());
|
||||||
|
certAlipayRequest.setFormat(getFormat());
|
||||||
|
certAlipayRequest.setCharset(getCharset());
|
||||||
|
certAlipayRequest.setSignType(getSignType());
|
||||||
|
certAlipayRequest.setCertContent(appCertContent);
|
||||||
|
certAlipayRequest.setAlipayPublicCertContent(aliPayCertContent);
|
||||||
|
certAlipayRequest.setRootCertContent(aliPayRootCertContent);
|
||||||
|
this.alipayClient = new DefaultAlipayClient(certAlipayRequest);
|
||||||
|
this.certModel = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPrivateKey() {
|
||||||
|
if (StrUtil.isBlank(privateKey)) {
|
||||||
|
throw new IllegalStateException("privateKey 未被赋值");
|
||||||
|
}
|
||||||
|
return privateKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setPrivateKey(String privateKey) {
|
||||||
|
if (StrUtil.isEmpty(privateKey)) {
|
||||||
|
throw new IllegalArgumentException("privateKey 值不能为 null");
|
||||||
|
}
|
||||||
|
this.privateKey = privateKey;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAliPayPublicKey() {
|
||||||
|
return aliPayPublicKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setAliPayPublicKey(String aliPayPublicKey) {
|
||||||
|
this.aliPayPublicKey = aliPayPublicKey;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAppId() {
|
||||||
|
if (StrUtil.isEmpty(appId)) {
|
||||||
|
throw new IllegalStateException("appId 未被赋值");
|
||||||
|
}
|
||||||
|
return appId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setAppId(String appId) {
|
||||||
|
if (StrUtil.isEmpty(appId)) {
|
||||||
|
throw new IllegalArgumentException("appId 值不能为 null");
|
||||||
|
}
|
||||||
|
this.appId = appId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getServiceUrl() {
|
||||||
|
if (StrUtil.isEmpty(serviceUrl)) {
|
||||||
|
throw new IllegalStateException("serviceUrl 未被赋值");
|
||||||
|
}
|
||||||
|
return serviceUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setServiceUrl(String serviceUrl) {
|
||||||
|
if (StrUtil.isEmpty(serviceUrl)) {
|
||||||
|
serviceUrl = "https://openapi.alipay.com/gateway.do";
|
||||||
|
}
|
||||||
|
this.serviceUrl = serviceUrl;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCharset() {
|
||||||
|
if (StrUtil.isEmpty(charset)) {
|
||||||
|
charset = "UTF-8";
|
||||||
|
}
|
||||||
|
return charset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setCharset(String charset) {
|
||||||
|
if (StrUtil.isEmpty(charset)) {
|
||||||
|
charset = "UTF-8";
|
||||||
|
}
|
||||||
|
this.charset = charset;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSignType() {
|
||||||
|
if (StrUtil.isEmpty(signType)) {
|
||||||
|
signType = "RSA2";
|
||||||
|
}
|
||||||
|
return signType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setSignType(String signType) {
|
||||||
|
if (StrUtil.isEmpty(signType)) {
|
||||||
|
signType = "RSA2";
|
||||||
|
}
|
||||||
|
this.signType = signType;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFormat() {
|
||||||
|
if (StrUtil.isEmpty(format)) {
|
||||||
|
format = "json";
|
||||||
|
}
|
||||||
|
return format;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAppCertPath() {
|
||||||
|
return appCertPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setAppCertPath(String appCertPath) {
|
||||||
|
this.appCertPath = appCertPath;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAppCertContent() {
|
||||||
|
return appCertContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setAppCertContent(String appCertContent) {
|
||||||
|
this.appCertContent = appCertContent;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAliPayCertPath() {
|
||||||
|
return aliPayCertPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setAliPayCertPath(String aliPayCertPath) {
|
||||||
|
this.aliPayCertPath = aliPayCertPath;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAliPayCertContent() {
|
||||||
|
return aliPayCertContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setAliPayCertContent(String aliPayCertContent) {
|
||||||
|
this.aliPayCertContent = aliPayCertContent;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAliPayRootCertPath() {
|
||||||
|
return aliPayRootCertPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setAliPayRootCertPath(String aliPayRootCertPath) {
|
||||||
|
this.aliPayRootCertPath = aliPayRootCertPath;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAliPayRootCertContent() {
|
||||||
|
return aliPayRootCertContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setAliPayRootCertContent(String aliPayRootCertContent) {
|
||||||
|
this.aliPayRootCertContent = aliPayRootCertContent;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCertModel() {
|
||||||
|
return certModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setCertModel(boolean certModel) {
|
||||||
|
this.certModel = certModel;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AlipayClient getAliPayClient() {
|
||||||
|
if (alipayClient == null) {
|
||||||
|
throw new IllegalStateException("aliPayClient 未被初始化");
|
||||||
|
}
|
||||||
|
return alipayClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getExParams() {
|
||||||
|
return exParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setExParams(Object exParams) {
|
||||||
|
this.exParams = exParams;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDomain() {
|
||||||
|
return domain;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setDomain(String domain) {
|
||||||
|
this.domain = domain;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Integer getProxyPort() {
|
||||||
|
return proxyPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setProxyPort(Integer proxyPort) {
|
||||||
|
this.proxyPort = proxyPort;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProxyIp() {
|
||||||
|
return proxyIp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AliPayApiConfig setProxyIp(String proxyIp) {
|
||||||
|
this.proxyIp = proxyIp;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
package com.ijpay.alipay;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>IJPay 让支付触手可及,封装了微信支付、支付宝支付、银联支付常用的支付方式以及各种常用的接口。</p>
|
||||||
|
*
|
||||||
|
* <p>不依赖任何第三方 mvc 框架,仅仅作为工具使用简单快速完成支付模块的开发,可轻松嵌入到任何系统里。 </p>
|
||||||
|
*
|
||||||
|
* <p>IJPay 交流群: 723992875、864988890</p>
|
||||||
|
*
|
||||||
|
* <p>Node.js 版: <a href="https://gitee.com/javen205/TNWX">https://gitee.com/javen205/TNWX</a></p>
|
||||||
|
*
|
||||||
|
* @author Javen
|
||||||
|
*/
|
||||||
|
public class AliPayApiConfigKit {
|
||||||
|
private static final ThreadLocal<String> TL = new ThreadLocal<String>();
|
||||||
|
|
||||||
|
private static final Map<String, AliPayApiConfig> CFG_MAP = new ConcurrentHashMap<String, AliPayApiConfig>();
|
||||||
|
private static final String DEFAULT_CFG_KEY = "_default_key_";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>向缓存中设置 AliPayApiConfig </p>
|
||||||
|
* <p>每个 appId 只需添加一次,相同 appId 将被覆盖</p>
|
||||||
|
*
|
||||||
|
* @param aliPayApiConfig 支付宝支付配置
|
||||||
|
* @return {@link AliPayApiConfig}
|
||||||
|
*/
|
||||||
|
public static AliPayApiConfig putApiConfig(AliPayApiConfig aliPayApiConfig) {
|
||||||
|
if (CFG_MAP.size() == 0) {
|
||||||
|
CFG_MAP.put(DEFAULT_CFG_KEY, aliPayApiConfig);
|
||||||
|
}
|
||||||
|
CFG_MAP.put(aliPayApiConfig.getAppId(), aliPayApiConfig);
|
||||||
|
return aliPayApiConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 向当前线程中设置 {@link AliPayApiConfig}
|
||||||
|
*
|
||||||
|
* @param aliPayApiConfig {@link AliPayApiConfig} 支付宝配置对象
|
||||||
|
* @return {@link AliPayApiConfig}
|
||||||
|
*/
|
||||||
|
public static AliPayApiConfig setThreadLocalAliPayApiConfig(AliPayApiConfig aliPayApiConfig) {
|
||||||
|
if (StrUtil.isNotEmpty(aliPayApiConfig.getAppId())) {
|
||||||
|
setThreadLocalAppId(aliPayApiConfig.getAppId());
|
||||||
|
}
|
||||||
|
return putApiConfig(aliPayApiConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过 AliPayApiConfig 移除支付配置
|
||||||
|
*
|
||||||
|
* @param aliPayApiConfig {@link AliPayApiConfig} 支付宝配置对象
|
||||||
|
* @return {@link AliPayApiConfig}
|
||||||
|
*/
|
||||||
|
public static AliPayApiConfig removeApiConfig(AliPayApiConfig aliPayApiConfig) {
|
||||||
|
return removeApiConfig(aliPayApiConfig.getAppId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过 appId 移除支付配置
|
||||||
|
*
|
||||||
|
* @param appId 支付宝应用编号
|
||||||
|
* @return {@link AliPayApiConfig}
|
||||||
|
*/
|
||||||
|
public static AliPayApiConfig removeApiConfig(String appId) {
|
||||||
|
return CFG_MAP.remove(appId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 向当前线程中设置 appId
|
||||||
|
*
|
||||||
|
* @param appId 支付宝应用编号
|
||||||
|
*/
|
||||||
|
public static void setThreadLocalAppId(String appId) {
|
||||||
|
if (StrUtil.isEmpty(appId)) {
|
||||||
|
appId = CFG_MAP.get(DEFAULT_CFG_KEY).getAppId();
|
||||||
|
}
|
||||||
|
TL.set(appId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除当前线程中的 appId
|
||||||
|
*/
|
||||||
|
public static void removeThreadLocalAppId() {
|
||||||
|
TL.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前线程中的 appId
|
||||||
|
*
|
||||||
|
* @return 支付宝应用编号 appId
|
||||||
|
*/
|
||||||
|
public static String getAppId() {
|
||||||
|
String appId = TL.get();
|
||||||
|
if (StrUtil.isEmpty(appId)) {
|
||||||
|
appId = CFG_MAP.get(DEFAULT_CFG_KEY).getAppId();
|
||||||
|
}
|
||||||
|
return appId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前线程中的 AliPayApiConfig
|
||||||
|
*
|
||||||
|
* @return {@link AliPayApiConfig}
|
||||||
|
*/
|
||||||
|
public static AliPayApiConfig getAliPayApiConfig() {
|
||||||
|
String appId = getAppId();
|
||||||
|
return getApiConfig(appId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过 appId 获取 AliPayApiConfig
|
||||||
|
*
|
||||||
|
* @param appId 支付宝应用编号
|
||||||
|
* @return {@link AliPayApiConfig}
|
||||||
|
*/
|
||||||
|
public static AliPayApiConfig getApiConfig(String appId) {
|
||||||
|
AliPayApiConfig cfg = CFG_MAP.get(appId);
|
||||||
|
if (cfg == null) {
|
||||||
|
throw new IllegalStateException("需事先调用 AliPayApiConfigKit.putApiConfig(aliPayApiConfig) 将 appId对应的 aliPayApiConfig 对象存入,才可以使用 AliPayApiConfigKit.getAliPayApiConfig() 的系列方法");
|
||||||
|
}
|
||||||
|
return cfg;
|
||||||
|
}
|
||||||
|
}
|
||||||
139
ruoyi-alipay/src/main/java/com/ijpay/alipay/AliPayCore.java
Normal file
139
ruoyi-alipay/src/main/java/com/ijpay/alipay/AliPayCore.java
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
package com.ijpay.alipay;
|
||||||
|
|
||||||
|
import cn.hutool.crypto.SecureUtil;
|
||||||
|
import com.alipay.api.AlipayApiException;
|
||||||
|
import com.alipay.api.AlipayConstants;
|
||||||
|
import com.alipay.api.internal.util.AlipaySignature;
|
||||||
|
import com.alipay.api.internal.util.AntCertificationUtil;
|
||||||
|
import com.alipay.api.internal.util.codec.Base64;
|
||||||
|
import enums.SignType;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import static com.alipay.api.internal.util.AlipaySignature.rsaCheckV1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>IJPay 让支付触手可及,封装了微信支付、支付宝支付、银联支付常用的支付方式以及各种常用的接口。</p>
|
||||||
|
*
|
||||||
|
* <p>不依赖任何第三方 mvc 框架,仅仅作为工具使用简单快速完成支付模块的开发,可轻松嵌入到任何系统里。 </p>
|
||||||
|
*
|
||||||
|
* <p>IJPay 交流群: 723992875、864988890</p>
|
||||||
|
*
|
||||||
|
* <p>Node.js 版: <a href="https://gitee.com/javen205/TNWX">https://gitee.com/javen205/TNWX</a></p>
|
||||||
|
*
|
||||||
|
* @author Javen
|
||||||
|
*/
|
||||||
|
public class AliPayCore {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成签名结果
|
||||||
|
*
|
||||||
|
* @param params 要签名的数组
|
||||||
|
* @param key 签名密钥
|
||||||
|
* @param signType 签名类型
|
||||||
|
* @return 签名结果字符串
|
||||||
|
*/
|
||||||
|
public static String buildRequestMySign(Map<String, String> params, String key, String signType) throws AlipayApiException {
|
||||||
|
// 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
|
||||||
|
String preStr = createLinkString(params);
|
||||||
|
if (SignType.MD5.getType().equals(signType)) {
|
||||||
|
return SecureUtil.md5(preStr.concat(key));
|
||||||
|
} else if (SignType.RSA2.getType().equals(signType)) {
|
||||||
|
return AlipaySignature.rsa256Sign(preStr, key, AlipayConstants.CHARSET_UTF8);
|
||||||
|
} else if (SignType.RSA.getType().equals(signType)) {
|
||||||
|
return AlipaySignature.rsaSign(preStr, key, AlipayConstants.CHARSET_UTF8);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成要请求给支付宝的参数数组
|
||||||
|
*
|
||||||
|
* @param params 请求前的参数数组
|
||||||
|
* @param key 商户的私钥
|
||||||
|
* @param signType 签名类型
|
||||||
|
* @return 要请求的参数数组
|
||||||
|
*/
|
||||||
|
public static Map<String, String> buildRequestPara(Map<String, String> params, String key, String signType) {
|
||||||
|
// 除去数组中的空值和签名参数
|
||||||
|
Map<String, String> tempMap = paraFilter(params);
|
||||||
|
// 生成签名结果
|
||||||
|
String mySign;
|
||||||
|
try {
|
||||||
|
mySign = buildRequestMySign(params, key, signType);
|
||||||
|
} catch (AlipayApiException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// 签名结果与签名方式加入请求提交参数组中
|
||||||
|
tempMap.put("sign", mySign);
|
||||||
|
tempMap.put("sign_type", signType);
|
||||||
|
return tempMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 除去数组中的空值和签名参数
|
||||||
|
*
|
||||||
|
* @param params 签名参数组
|
||||||
|
* @return 去掉空值与签名参数后的新签名参数组
|
||||||
|
*/
|
||||||
|
public static Map<String, String> paraFilter(Map<String, String> params) {
|
||||||
|
if (params == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Map<String, String> result = new HashMap<>(params.size());
|
||||||
|
if (params.size() <= 0) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
for (String key : params.keySet()) {
|
||||||
|
String value = params.get(key);
|
||||||
|
if (value == null || "".equals(value) || "sign".equalsIgnoreCase(key)
|
||||||
|
|| "sign_type".equalsIgnoreCase(key)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
result.put(key, value);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 把数组所有元素排序
|
||||||
|
*
|
||||||
|
* @param params 需要排序并参与字符拼接的参数组
|
||||||
|
* @return 拼接后字符串
|
||||||
|
*/
|
||||||
|
public static String createLinkString(Map<String, String> params) {
|
||||||
|
List<String> keys = new ArrayList<>(params.keySet());
|
||||||
|
Collections.sort(keys);
|
||||||
|
StringBuilder content = new StringBuilder();
|
||||||
|
for (String key : keys) {
|
||||||
|
String value = params.get(key);
|
||||||
|
// 拼接时,不包括最后一个&字符
|
||||||
|
content.append(key).append("=").append(value).append("&");
|
||||||
|
}
|
||||||
|
if (content.lastIndexOf("&") == content.length() - 1) {
|
||||||
|
content.deleteCharAt(content.length() - 1);
|
||||||
|
}
|
||||||
|
return content.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从证书内容验签
|
||||||
|
* @param params 待验签的从支付宝接收到的参数Map
|
||||||
|
* @param alipayPublicCertContent 支付宝公钥证书内容
|
||||||
|
* @param charset 参数内容编码集
|
||||||
|
* @param signType 指定采用的签名方式,RSA或RSA2
|
||||||
|
* @return true:验签通过;false:验签不通过
|
||||||
|
* @throws AlipayApiException
|
||||||
|
*/
|
||||||
|
public static boolean rsaCertCheckV1ByContent(Map<String, String> params, String alipayPublicCertContent,
|
||||||
|
String charset, String signType) throws AlipayApiException {
|
||||||
|
String publicKey = Base64.encodeBase64String(
|
||||||
|
AntCertificationUtil
|
||||||
|
.getCertFromContent(alipayPublicCertContent)
|
||||||
|
.getPublicKey()
|
||||||
|
.getEncoded()
|
||||||
|
);
|
||||||
|
return rsaCheckV1(params, publicKey, charset, signType);
|
||||||
|
}
|
||||||
|
}
|
||||||
39
ruoyi-alipay/src/main/java/enums/SignType.java
Normal file
39
ruoyi-alipay/src/main/java/enums/SignType.java
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
package enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>IJPay 让支付触手可及,封装了微信支付、支付宝支付、银联支付常用的支付方式以及各种常用的接口。</p>
|
||||||
|
*
|
||||||
|
* <p>不依赖任何第三方 mvc 框架,仅仅作为工具使用简单快速完成支付模块的开发,可轻松嵌入到任何系统里。 </p>
|
||||||
|
*
|
||||||
|
* <p>IJPay 交流群: 723992875、864988890</p>
|
||||||
|
*
|
||||||
|
* <p>Node.js 版: <a href="https://gitee.com/javen205/TNWX">https://gitee.com/javen205/TNWX</a></p>
|
||||||
|
*
|
||||||
|
* <p>签名方式</p>
|
||||||
|
*
|
||||||
|
* @author Javen
|
||||||
|
*/
|
||||||
|
public enum SignType {
|
||||||
|
/**
|
||||||
|
* MD5 加密
|
||||||
|
*/
|
||||||
|
MD5("MD5"),
|
||||||
|
/**
|
||||||
|
* RSA2
|
||||||
|
*/
|
||||||
|
RSA2("RSA2"),
|
||||||
|
/**
|
||||||
|
* RSA
|
||||||
|
*/
|
||||||
|
RSA("RSA");
|
||||||
|
|
||||||
|
SignType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String type;
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
ruoyi-cai/lib/IJPay-AliPay-2.9.10.jar
Normal file
BIN
ruoyi-cai/lib/IJPay-AliPay-2.9.10.jar
Normal file
Binary file not shown.
@@ -40,10 +40,14 @@
|
|||||||
<artifactId>IJPay-WxPay</artifactId>
|
<artifactId>IJPay-WxPay</artifactId>
|
||||||
<version>${ijapy.version}</version>
|
<version>${ijapy.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<!--<dependency>
|
||||||
<groupId>com.github.javen205</groupId>
|
<groupId>com.github.javen205</groupId>
|
||||||
<artifactId>IJPay-AliPay</artifactId>
|
<artifactId>IJPay-AliPay</artifactId>
|
||||||
<version>${ijapy.version}</version>
|
<version>${ijapy.version}</version>
|
||||||
|
</dependency>-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.ruoyi</groupId>
|
||||||
|
<artifactId>ruoyi-alipay</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.ruoyi</groupId>
|
<groupId>com.ruoyi</groupId>
|
||||||
|
|||||||
@@ -87,14 +87,28 @@ public class PayConfigManager {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("实例化AliPayApiConfig...");
|
log.error("实例化AliPayApiConfig...");
|
||||||
// 如果Map中没有当前支付宝的实例就初始化并添加到Map中
|
// 如果Map中没有当前支付宝的实例就初始化并添加到Map中
|
||||||
aliPayApiConfig = AliPayApiConfig.builder()
|
if(caiProperties.isOpenPayProxy()){
|
||||||
.setAppId(payConfig.getAppid())
|
aliPayApiConfig = AliPayApiConfig.builder()
|
||||||
.setAliPayPublicKey(payConfig.getPublicKey())
|
.setAppId(payConfig.getAppid())
|
||||||
.setCharset("UTF-8")
|
.setAliPayPublicKey(payConfig.getPublicKey())
|
||||||
.setPrivateKey(payConfig.getPrivateKey())
|
.setCharset("UTF-8")
|
||||||
.setServiceUrl(payConfig.getNotifyUrl())
|
.setPrivateKey(payConfig.getPrivateKey())
|
||||||
.setSignType("RSA2")
|
.setServiceUrl(payConfig.getNotifyUrl())
|
||||||
.build();
|
.setSignType("RSA2")
|
||||||
|
.setProxyIp(caiProperties.getProxyIp())
|
||||||
|
.setProxyPort(caiProperties.getProxyHost())
|
||||||
|
.buildProxy();
|
||||||
|
}else{
|
||||||
|
aliPayApiConfig = AliPayApiConfig.builder()
|
||||||
|
.setAppId(payConfig.getAppid())
|
||||||
|
.setAliPayPublicKey(payConfig.getPublicKey())
|
||||||
|
.setCharset("UTF-8")
|
||||||
|
.setPrivateKey(payConfig.getPrivateKey())
|
||||||
|
.setServiceUrl(payConfig.getNotifyUrl())
|
||||||
|
.setSignType("RSA2")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
AliPayApiConfigKit.setThreadLocalAliPayApiConfig(aliPayApiConfig);
|
AliPayApiConfigKit.setThreadLocalAliPayApiConfig(aliPayApiConfig);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user