引入支付宝的支付功能

This commit is contained in:
YunaiV 2021-10-19 09:26:49 +08:00
parent 24f4fd4fee
commit 7ca756a234
14 changed files with 173 additions and 59 deletions

View File

@ -33,7 +33,7 @@ import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeCons
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
/** /**
* 短信模板Service实现类 * 短信模板 Service 实现类
* *
* @author zzf * @author zzf
* @date 2021/1/25 9:25 * @date 2021/1/25 9:25

View File

@ -0,0 +1,14 @@
package cn.iocoder.yudao.framework.pay.core;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
/**
* 支付客户端用于对接各支付渠道的 SDK实现发起支付退款等功能
*
* @author 芋道源码
*/
public interface PayClient {
CommonResult<String> unifiedOrder();
}

View File

@ -0,0 +1,10 @@
package cn.iocoder.yudao.framework.pay.core;
/**
* 支付客户端的配置本质是支付渠道的配置
* 每个不同的渠道需要不同的配置通过子类来定义
*
* @author 芋道源码
*/
public interface PayClientConfig {
}

View File

@ -1,8 +0,0 @@
/**
* @description
* @author Qingchen
* @version 1.0.0
* @date 2021-09-29 14:59
* @class cn.iocoder.yudao.framework.pay.core.aop.package-info.java
*/
package cn.iocoder.yudao.framework.pay.core.aop;

View File

@ -0,0 +1,15 @@
package cn.iocoder.yudao.framework.pay.core.client;
import cn.iocoder.yudao.framework.pay.core.PayClient;
import com.alipay.api.DefaultAlipayClient;
/**
* 支付客户端的抽象类提供模板方法减少子类的冗余代码
*
* @author 芋道源码
*/
public abstract class AbstractPayClient implements PayClient {
}

View File

@ -0,0 +1,42 @@
package cn.iocoder.yudao.framework.pay.core.client.alipay;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.pay.core.client.AbstractPayClient;
import com.alipay.api.AlipayApiException;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayTradePrecreateModel;
import com.alipay.api.request.AlipayTradePrecreateRequest;
import com.alipay.api.response.AlipayTradePrecreateResponse;
/**
* 支付宝的 PayClient 实现类
*/
public class AlipayPayClient extends AbstractPayClient {
private DefaultAlipayClient client = new DefaultAlipayClient("https://openapi.alipaydev.com/gateway.do","2021000118634035","MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCHsEV1cDupwJv890x84qbppUtRIfhaKSwSVN0thCcsDCaAsGR5MZslDkO8NCT9V4r2SVXjyY7eJUZlZd1M0C8T01Tg4UOx5LUbic0O3A1uJMy6V1n9IyYwbAW3AEZhBd5bSbPgrqvmv3NeWSTQT6Anxnllf+2iDH6zyA2fPl7cYyQtbZoDJQFGqr4F+cGh2R6akzRKNoBkAeMYwoY6es2lX8sJxCVPWUmxNUoL3tScwlSpd7Bxw0q9c/X01jMwuQ0+Va358zgFiGERTE6yD01eu40OBDXOYO3z++y+TAYHlQQ2toMO63trepo88X3xV3R44/1DH+k2pAm2IF5ixiLrAgMBAAECggEAPx3SoXcseaD7rmcGcE0p4SMfbsUDdkUSmBBbtfF0GzwnqNLkWa+mgE0rWt9SmXngTQH97vByAYmLPl1s3G82ht1V7Sk7yQMe74lhFllr8eEyTjeVx3dTK1EEM4TwN+936DTXdFsr4TELJEcJJdD0KaxcCcfBLRDs2wnitEFZ9N+GoZybVmY8w0e0MI7PLObUZ2l0X4RurQnfG9ZxjXjC7PkeMVv7cGGylpNFi3BbvkRhdhLPDC2E6wqnr9e7zk+hiENivAezXrtxtwKovzCtnWJ1r0IO14Rh47H509Ic0wFnj+o5YyUL4LdmpL7yaaH6fM7zcSLFjNZPHvZCKPwYcQKBgQDQFho98QvnL8ex4v6cry4VitGpjSXm1qP3vmMQk4rTsn8iPWtcxPjqGEqOQJjdi4Mi0VZKQOLFwlH0kl95wNrD/isJ4O1yeYfX7YAXApzHqYNINzM79HemO3Yx1qLMW3okRFJ9pPRzbQ9qkTpsaegsmyX316zOBhzGRYjKbutTYwKBgQCm7phr9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D3n5r8HSuseQIDAQAB","RSA2");
@Override
public CommonResult<String> unifiedOrder() {
AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest();
AlipayTradePrecreateModel model = new AlipayTradePrecreateModel();
request.setBizModel(model);
model.setOutTradeNo(String.valueOf(System.currentTimeMillis()));
model.setTotalAmount("88.88");
model.setSubject("Iphone6 16G");
AlipayTradePrecreateResponse response = null;
try {
response = client.execute(request);
} catch (AlipayApiException e) {
e.printStackTrace();
}
System.out.println(response.getBody());
System.out.println(response.getQrCode());
return null;
}
public static void main(String[] args) {
AlipayPayClient client = new AlipayPayClient();
client.unifiedOrder();
}
}

View File

@ -0,0 +1,88 @@
package cn.iocoder.yudao.framework.pay.core.client.alipay;
import lombok.Data;
// TODO 芋艿参数校验
/**
* 支付宝的 PayClientConfig 实现类
* 属性主要来自 {@link com.alipay.api.AlipayConfig} 的必要属性
*
* @author 芋道源码
*/
@Data
public class AlipayPayConfig {
/**
* 网关地址 - 线上
*/
private static final String SERVER_URL_PROD = "https://openapi.alipay.com/gateway.do";
/**
* 网关地址 - 沙箱
*/
private static final String SERVER_URL_SANDBOX = "https://openapi.alipay.com/gateway.do";
/**
* 公钥类型 - 公钥模式
*/
private static final Integer MODE_PUBLIC_KEY = 1;
/**
* 公钥类型 - 证书模式
*/
private static final Integer MODE_CERTIFICATE = 2;
/**
* 签名算法类型 - RSA
*/
private static final String SIGN_TYPE_DEFAULT = "RSA2";
/**
* 网关地址
* 1. {@link #SERVER_URL_PROD}
* 2. {@link #SERVER_URL_SANDBOX}
*/
private String serverUrl;
/**
* 开放平台上创建的应用的 ID
*/
private String appId;
/**
* 签名算法类型推荐RSA2
*
* {@link #SIGN_TYPE_DEFAULT}
*/
private String signType;
/**
* 公钥类型
* 1. {@link #MODE_PUBLIC_KEY} 情况privateKey + alipayPublicKey
* 2. {@link #MODE_CERTIFICATE} 情况appCertContent + alipayPublicCertContent + rootCertContent
*/
private Integer mode;
// ========== 公钥模式 ==========
/**
* 商户私钥
*/
private String privateKey;
/**
* 支付宝公钥字符串
*/
private String alipayPublicKey;
// ========== 证书模式 ==========
/**
* 指定商户公钥应用证书内容字符串
*/
private String appCertContent;
/**
* 指定支付宝公钥证书内容字符串
*/
private String alipayPublicCertContent;
/**
* 指定根证书内容字符串
*/
private String rootCertContent;
}

View File

@ -0,0 +1 @@
package cn.iocoder.yudao.framework.pay.core.client;

View File

@ -1,14 +0,0 @@
package cn.iocoder.yudao.framework.pay.core.gateway;
/**
* @description 渠道侧的通知网关服务分为同步跳转doReturn和异步回调(doNotify)
* @author Qingchen
* @version 1.0.0
* @date 2021-10-09 14:34
* @class cn.iocoder.yudao.framework.pay.core.gateway.ChannelNoticeService.java
*/
public interface ChannelNoticeService {
}

View File

@ -1,13 +0,0 @@
package cn.iocoder.yudao.framework.pay.core.gateway;
/**
* @description 退款网关服务
* @author Qingchen
* @version 1.0.0
* @date 2021-10-09 16:07
* @class cn.iocoder.yudao.framework.pay.core.gateway.RefundService.java
*/
public interface RefundService {
}

View File

@ -1,13 +0,0 @@
package cn.iocoder.yudao.framework.pay.core.gateway;
/**
* @description 统一下单网关服务
* @author Qingchen
* @version 1.0.0
* @date 2021-09-29 16:14
* @class cn.iocoder.yudao.framework.pay.core.gateway.UnifiedOrderService.java
*/
public interface UnifiedOrderService {
}

View File

@ -1,8 +0,0 @@
/**
* @description
* @author Qingchen
* @version 1.0.0
* @date 2021-09-29 14:34
* @class cn.iocoder.yudao.framework.pay.core.package-info.java
*/
package cn.iocoder.yudao.framework.pay.core;

View File

@ -8,7 +8,7 @@ import cn.iocoder.yudao.framework.sms.core.client.dto.SmsTemplateRespDTO;
import java.util.List; import java.util.List;
/** /**
* 短信客户端接口 * 短信客户端用于对接各短信平台的 SDK实现短信发送等功能
* *
* @author zzf * @author zzf
* @date 2021/1/25 14:14 * @date 2021/1/25 14:14

View File

@ -13,7 +13,7 @@ import lombok.extern.slf4j.Slf4j;
import java.util.List; import java.util.List;
/** /**
* 短信客户端抽象类 * 短信客户端抽象类提供模板方法减少子类的冗余代码
* *
* @author zzf * @author zzf
* @date 2021/2/1 9:28 * @date 2021/2/1 9:28