支付宝插件 , 更换地图 , 支付订单入账佣金账号

This commit is contained in:
2026-03-25 15:24:30 +08:00
parent 1c593d1dfb
commit b355f0364c
150 changed files with 10846 additions and 265 deletions

View File

@@ -0,0 +1,15 @@
package org.springblade.plugin.pay.api;
import org.springblade.plugin.pay.dto.APPPayDto;
import org.springblade.plugin.pay.dto.APPQueryDto;
import org.springblade.plugin.pay.response.APPPayResult;
public interface PaymentFacade {
APPPayResult appPay(APPPayDto dto) throws Exception;
Boolean query(APPQueryDto dto);
Boolean closeOrder(APPQueryDto dto);
}

View File

@@ -0,0 +1,98 @@
package org.springblade.plugin.pay.api.alipay;
import com.alipay.api.response.AlipayTradeCloseResponse;
import com.alipay.api.response.AlipayTradeQueryResponse;
import com.alipay.api.response.AlipayTradeRefundResponse;
import org.springblade.plugin.pay.entity.AliPayAccountConfig;
import org.springblade.plugin.pay.entity.Order;
import org.springblade.plugin.pay.entity.Refund;
import org.springblade.plugin.pay.entityBiz.AliPayBiz;
/**
* 支付宝API接口
*
* @author YunGouOS技术部-029
* @time 2022/4/28 14:56
*/
public interface IAliPayApiService {
/**
* 付款码支付(当面付产品)返回支付结果
*
* @param order
* @param aliPayAccountConfig
* @param authCode
* @param attach
* @return
*/
public AliPayBiz codePay(Order order, AliPayAccountConfig aliPayAccountConfig, String authCode, String attach);
/**
* 支付宝扫码支付(当面付产品)返回二维码地址
*
* @param order
* @param aliPayAccountConfig
* @param attach
* @return
*/
public String nativePay(Order order, AliPayAccountConfig aliPayAccountConfig, String attach);
/**
* 支付宝js支付,适合支付宝小程序使用 返回支付宝付款对象,前端按照支付宝JSAPI进行调用
*
* @param order
* @param aliPayAccountConfig
* @param attach
* @return
*/
public AliPayBiz jsPay(Order order, AliPayAccountConfig aliPayAccountConfig, String attach);
/**
* 电脑网站支付 返回form表单字符串,输出跳转
*
* @param order
* @param aliPayAccountConfig
* @param attach
*/
public String webPay(Order order, AliPayAccountConfig aliPayAccountConfig, String attach, String returnUrl);
/**
* 手机网站支付
*
* @param order
* @param aliPayAccountConfig
* @param attach
* @param returnUrl
* @return
*/
public String mobilePay(Order order, AliPayAccountConfig aliPayAccountConfig, String attach, String returnUrl);
/**
* APP支付
*
* @param order
* @param aliPayAccountConfig
* @param attach
*/
public String appPay(Order order, AliPayAccountConfig aliPayAccountConfig, String attach);
/**
* 发起退款
*
* @param refund
* @param aliPayAccountConfig
* @return
*/
public AlipayTradeRefundResponse refund(Refund refund, AliPayAccountConfig aliPayAccountConfig);
public AlipayTradeQueryResponse query(String orderNo, AliPayAccountConfig aliPayAccountConfig) throws Exception;
public AlipayTradeCloseResponse closeOrder(String orderNo, AliPayAccountConfig aliPayAccountConfig) throws Exception;
}

View File

@@ -0,0 +1,233 @@
package org.springblade.plugin.pay.api.alipay.impl;
import cn.hutool.core.date.DateUtil;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayResponse;
import com.alipay.api.domain.*;
import com.alipay.api.request.*;
import com.alipay.api.response.*;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.plugin.pay.api.alipay.IAliPayApiService;
import org.springblade.plugin.pay.constant.PayConstant;
import org.springblade.plugin.pay.entity.AliPayAccountConfig;
import org.springblade.plugin.pay.entity.Order;
import org.springblade.plugin.pay.entity.Refund;
import org.springblade.plugin.pay.entityBiz.AliPayBiz;
import org.springblade.plugin.pay.service.IOrderService;
import org.springblade.plugin.pay.util.AliPayHttpUtil;
import org.springblade.plugin.pay.util.AliPayParamsUtil;
import org.springframework.stereotype.Service;
/**
* 支付宝API接口实现类
*
* @author YunGouOS技术部-029
* @time 2022/4/28 14:56
*/
@Service
@AllArgsConstructor
public class AliPayApiServiceImpl implements IAliPayApiService {
private static final Logger log = LoggerFactory.getLogger(AliPayApiServiceImpl.class);
private final AliPayParamsUtil aliPayParamsUtil;
private final AliPayHttpUtil aliPayHttpUtil;
private final IOrderService orderService;
@Override
public AliPayBiz codePay(Order order, AliPayAccountConfig aliPayAccountConfig, String authCode, String attach) {
AliPayBiz aliPayBiz = null;
try {
String body = order.getBody();
String money = order.getMoney();
String orderNo = order.getOrderNo();
AlipayTradePayModel alipayTradePayModel = aliPayParamsUtil.getAliPayTradePayParams(aliPayAccountConfig, PayConstant.CODEPAY, body, money, orderNo, authCode);
AlipayTradePayRequest request = new AlipayTradePayRequest();
request.setBizModel(alipayTradePayModel);
AlipayTradePayResponse response = (AlipayTradePayResponse) aliPayHttpUtil.doPost(aliPayAccountConfig, request, aliPayAccountConfig.getAppAuthToken(), true);
aliPayBiz = new AliPayBiz();
aliPayBiz.setOrderNo(orderNo);
aliPayBiz.setPayNo(response.getTradeNo());
aliPayBiz.setMoney(response.getReceiptAmount());
aliPayBiz.setPayTime(DateUtil.formatDateTime(response.getGmtPayment()));
} catch (AlipayApiException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
return aliPayBiz;
}
@Override
public String nativePay(Order order, AliPayAccountConfig aliPayAccountConfig, String attach) {
String codeUrl = null;
try {
String body = order.getBody();
String money = order.getMoney();
String orderNo = order.getOrderNo();
AlipayTradePrecreateModel model = aliPayParamsUtil.getAliPayServicePushOrderParam(aliPayAccountConfig, body, money, orderNo);
AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest();
request.setBizModel(model);
AlipayTradePrecreateResponse response = (AlipayTradePrecreateResponse) aliPayHttpUtil.doPost(aliPayAccountConfig, request, aliPayAccountConfig.getAppAuthToken(), true);
codeUrl = response.getQrCode();
} catch (AlipayApiException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
return codeUrl;
}
@Override
public AliPayBiz jsPay(Order order, AliPayAccountConfig aliPayAccountConfig, String attach) {
AliPayBiz aliPayBiz = null;
try {
String body = order.getBody();
String money = order.getMoney();
String orderNo = order.getOrderNo();
String buyerId = order.getBuyerId();
if (StringUtils.isBlank(buyerId)) {
throw new ServiceException("buyerId不能为空");
}
AlipayTradeCreateModel alipayTradeCreateModel = aliPayParamsUtil.getAliPayServicePushOrderCreateParam(aliPayAccountConfig, buyerId, body, money, orderNo);
AlipayTradeCreateRequest request = new AlipayTradeCreateRequest();
request.setBizModel(alipayTradeCreateModel);
AlipayTradeCreateResponse response = (AlipayTradeCreateResponse) aliPayHttpUtil.doPost(aliPayAccountConfig, request, aliPayAccountConfig.getAppAuthToken(), true);
aliPayBiz = new AliPayBiz();
aliPayBiz.setPayNo(response.getTradeNo());
aliPayBiz.setOrderNo(orderNo);
} catch (AlipayApiException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
return aliPayBiz;
}
@Override
public String webPay(Order order, AliPayAccountConfig aliPayAccountConfig, String attach, String returnUrl) {
String form = null;
try {
String body = order.getBody();
String money = order.getMoney();
String orderNo = order.getOrderNo();
AlipayTradePagePayModel alipayTradeCreateModel = aliPayParamsUtil.getAliPayServiceWebParam(orderNo, money, body);
AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
request.setBizModel(alipayTradeCreateModel);
if (!StringUtils.isBlank(returnUrl)) {
request.setReturnUrl(returnUrl);
}
AlipayResponse response = aliPayHttpUtil.doPostPage(aliPayAccountConfig, request, true);
form = response.getBody();
} catch (AlipayApiException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
return form;
}
@Override
public String mobilePay(Order order, AliPayAccountConfig aliPayAccountConfig, String attach, String returnUrl) {
String wapPayStr = null;
try {
String body = order.getBody();
String money = order.getMoney();
String orderNo = order.getOrderNo();
AlipayTradeWapPayModel alipayTradeWapPayModel = aliPayParamsUtil.getAliPayServiceH5Param(aliPayAccountConfig, body, money, orderNo, returnUrl);
AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
request.setBizModel(alipayTradeWapPayModel);
if (!StringUtils.isBlank(returnUrl)) {
request.setReturnUrl(returnUrl);
}
AlipayResponse response = aliPayHttpUtil.doPostPage(aliPayAccountConfig, request, true);
wapPayStr = response.getBody();
} catch (AlipayApiException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
return wapPayStr;
}
@Override
public String appPay(Order order, AliPayAccountConfig aliPayAccountConfig, String attach) {
String appStr = null;
try {
String body = order.getBody();
String money = order.getMoney();
String orderNo = order.getOrderNo();
AlipayTradeAppPayModel alipayTradeAppPayModel = aliPayParamsUtil.getAliPayServiceAppParam(orderNo, money, body);
AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
request.setBizModel(alipayTradeAppPayModel);
AlipayResponse response = aliPayHttpUtil.doPostSdk(aliPayAccountConfig, request, aliPayAccountConfig.getAppAuthToken(), true);
appStr = response.getBody();
} catch (AlipayApiException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
return appStr;
}
@Override
public AlipayTradeRefundResponse refund(Refund refund, AliPayAccountConfig aliPayAccountConfig) {
AlipayTradeRefundResponse refundResult = null;
try {
String refundNo = refund.getRefundNo();
String orderNo = refund.getOrderNo();
String payNo = refund.getPayNo();
String refundMoney = refund.getRefundMoney();
String refundDesc = refund.getRefundDesc();
AlipayTradeRefundModel alipayTradeRefundModel = aliPayParamsUtil.getAliPayRefundParam(refundNo, orderNo, payNo, refundMoney, refundDesc);
AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
request.setBizModel(alipayTradeRefundModel);
refundResult = (AlipayTradeRefundResponse) aliPayHttpUtil.doPost(aliPayAccountConfig, request, aliPayAccountConfig.getAppAuthToken(), true);
} catch (AlipayApiException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
return refundResult;
}
@Override
public AlipayTradeQueryResponse query(String orderNo, AliPayAccountConfig aliPayAccountConfig) throws Exception{
AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
AlipayTradeQueryModel model = new AlipayTradeQueryModel();
model.setOutTradeNo(orderNo);
model.setOrgPid(aliPayAccountConfig.getAppId());
request.setBizModel(model);
return (AlipayTradeQueryResponse) aliPayHttpUtil.doPost(aliPayAccountConfig, request, aliPayAccountConfig.getAppAuthToken(), true);
}
@Override
public AlipayTradeCloseResponse closeOrder(String orderNo, AliPayAccountConfig aliPayAccountConfig) throws Exception {
AlipayTradeCloseRequest request = new AlipayTradeCloseRequest();
AlipayTradeCloseModel model = new AlipayTradeCloseModel();
model.setOutTradeNo(orderNo);
request.setBizModel(model);
return (AlipayTradeCloseResponse) aliPayHttpUtil.doPost(aliPayAccountConfig, request, aliPayAccountConfig.getAppAuthToken(), true);
}
}

View File

@@ -0,0 +1,118 @@
package org.springblade.plugin.pay.api.impl;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.modules.common.eums.BusinessModule;
import org.springblade.modules.common.eums.PaymentType;
import org.springblade.plugin.pay.api.PaymentFacade;
import org.springblade.plugin.pay.config.AliPayConfiguration;
import org.springblade.plugin.pay.config.WxPayConfiguration;
import org.springblade.plugin.pay.dto.APPPayDto;
import org.springblade.plugin.pay.dto.APPQueryDto;
import org.springblade.plugin.pay.response.APPPayResult;
import org.springblade.plugin.pay.service.IAliPayService;
import org.springblade.plugin.pay.service.IWxPayService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Map;
@Slf4j
@Service
@AllArgsConstructor
public class PaymentFacadeImpl implements PaymentFacade {
private final IAliPayService aliPayService;
private final AliPayConfiguration aliPayConfig;
private final IWxPayService wxPayService;
private final WxPayConfiguration wxPayConfig;
@Override
@Transactional(rollbackFor = Exception.class)
public APPPayResult appPay(APPPayDto dto) {
PaymentType paymentType = dto.getPaymentType();
BusinessModule businessModule = dto.getBusinessModule();
APPPayResult result = new APPPayResult();
String content = "success";
switch (paymentType) {
case ALI:
content = aliPayService.appPay(
aliPayConfig.getAppId(),
aliPayConfig.getMachId(),
dto.getBody(),
String.valueOf(dto.getAmount()),
aliPayConfig.getNotifyUrl(),
dto.getRemark(),
paymentType.getAbbr() + businessModule.getAbbr(),
dto.getOrderId()
);
break;
case WECHAT:
Map<String, String> stringStringMap = wxPayService.appPay(
wxPayConfig.getAppId(),
wxPayConfig.getMachId(),
dto.getBody(),
String.valueOf(dto.getAmount()),
wxPayConfig.getNotifyUrl(),
dto.getRemark(),
paymentType.getAbbr() + businessModule.getAbbr(),
dto.getOrderId()
);
log.info("微信APP支付结果:{}", stringStringMap);
//todo 微信app支付结果处理
break;
default:
throw new RuntimeException("支付类型错误");
}
return result
.setSuccess(Boolean.TRUE)
.setContent(content)
.setPaymentTypeEnum(paymentType);
}
@Override
public Boolean query(APPQueryDto dto){
PaymentType paymentType = dto.getPaymentType();
Boolean result = false;
switch (paymentType) {
case ALI:
result = aliPayService.query(dto.getOrderNo(),aliPayConfig.getAppId(), aliPayConfig.getMachId());
break;
case WECHAT:
//todo 微信app查询支付结果
break;
default:
throw new RuntimeException("支付类型错误");
}
return result;
}
@Override
public Boolean closeOrder(APPQueryDto dto) {
PaymentType paymentType = dto.getPaymentType();
Boolean result = false;
switch (paymentType) {
case ALI:
result = aliPayService.closeOrder(dto.getOrderNo(),aliPayConfig.getAppId(), aliPayConfig.getMachId());
break;
case WECHAT:
//todo 微信app查询支付结果
break;
default:
throw new RuntimeException("支付类型错误");
}
return result;
}
}

View File

@@ -0,0 +1,110 @@
package org.springblade.plugin.pay.api.wxpay;
import com.alibaba.fastjson.JSONObject;
import org.springblade.plugin.pay.entity.Order;
import org.springblade.plugin.pay.entity.Refund;
import org.springblade.plugin.pay.entity.WxPayAccountConfig;
import org.springblade.plugin.pay.entityBiz.WxPayRefundBiz;
import java.util.Map;
/**
* 微信支付API接口
*
* @author YunGouOS技术部-029
* @time 2021/12/28 22:47
*/
public interface IWxPayApiService {
/**
* 获取证书公钥
*
* @author YunGouOS
* @date 2020年12月2日 下午6:39:26
*/
public String getPublicKey(String path, String mchId, String v3Key, String certficatesNo);
/**
* 微信回调通知解密
* @param wxPayAccountConfig
* @param data
* @return
*/
public JSONObject decryptCallback(WxPayAccountConfig wxPayAccountConfig,JSONObject data);
/**
* 微信付款码支付
* @param authCode
* @param order
* @param wxPayAccountConfig
* @param attach
* @return
*/
public Map<String, Object> codePay(String authCode, Order order, WxPayAccountConfig wxPayAccountConfig, String attach);
/**
* 微信扫码支付
*
* @param order
* @param wxPayAccountConfig
* @return
*/
public String nativePay(Order order, WxPayAccountConfig wxPayAccountConfig, String attach);
/**
* 微信jsapi支付
*
* @param openId
* @param order
* @param wxPayAccountConfig
* @param attach
* @return
*/
public String jsPay(String openId, Order order, WxPayAccountConfig wxPayAccountConfig, String attach);
/**
* 微信H5支付
*
* @param order
* @param wxPayAccountConfig
* @param returnUrl
* @param attach
* @return
*/
public String h5Pay(Order order, WxPayAccountConfig wxPayAccountConfig, String returnUrl, String attach);
/**
* 微信APP支付
*
* @param appId
* @param order
* @param wxPayAccountConfig
* @param attach
* @return
*/
public String appPay(String appId, Order order, WxPayAccountConfig wxPayAccountConfig, String attach);
/**
* 发起退款
* @param refund
* @param wxPayAccountConfig
* @return
*/
public WxPayRefundBiz refund(Refund refund, WxPayAccountConfig wxPayAccountConfig,String orderMoney);
/**
* 查询微信订单详情
* @param orderNo
* @param payNo
* @param wxPayAccountConfig
*/
public JSONObject getOrderInfo(String orderNo, String payNo, WxPayAccountConfig wxPayAccountConfig);
}

View File

@@ -0,0 +1,269 @@
package org.springblade.plugin.pay.api.wxpay.impl;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ijpay.core.enums.RequestMethodEnum;
import com.ijpay.core.kit.AesUtil;
import com.ijpay.wxpay.WxPayApi;
import com.ijpay.wxpay.enums.WxApiType;
import com.ijpay.wxpay.enums.WxDomainEnum;
import lombok.AllArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.core.tool.utils.WebUtil;
import org.springblade.plugin.pay.api.wxpay.IWxPayApiService;
import org.springblade.plugin.pay.common.Common;
import org.springblade.plugin.pay.common.WxPayException;
import org.springblade.plugin.pay.entity.Order;
import org.springblade.plugin.pay.entity.Refund;
import org.springblade.plugin.pay.entity.WxPayAccountConfig;
import org.springblade.plugin.pay.entityBiz.WxPayRefundBiz;
import org.springblade.plugin.pay.service.IOrderService;
import org.springblade.plugin.pay.util.WxPayInitUtil;
import org.springblade.plugin.pay.util.WxPayV2ParamsUtil;
import org.springblade.plugin.pay.util.WxPayV3ApiHttpUtil;
import org.springblade.plugin.pay.util.WxPayV3ParamsUtil;
import org.springframework.stereotype.Service;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
/**
* 微信支付API接口对接
*
* @author YunGouOS技术部-029
* @time 2021/12/28 22:48
*/
@Service
@AllArgsConstructor
public class WxPayApiServiceImpl implements IWxPayApiService {
private final WxPayV3ParamsUtil wxPayV3ParamsUtil;
private final WxPayV2ParamsUtil wxPayV2ParamsUtil;
private final WxPayV3ApiHttpUtil wxPayV3ApiHttpUtil;
private final IOrderService orderService;
@Override
public String getPublicKey(String path, String mchId, String v3Key, String certficatesNo) {
String wxPayPublicKey = null;
try {
// 获取证书url
String url = WxApiType.GET_CERTIFICATES.toString();
// 证书公钥
Map<String, Object> result = WxPayApi.v3Execution(RequestMethodEnum.GET, WxDomainEnum.CHINA.toString(), url, mchId, certficatesNo, path, "");
Integer status = (Integer) result.get("status");
if (status != null && 404 == status.intValue()) {
//无平台证书,可能是新版的 微信支付公钥方式
return null;
}
Map<String, String> params = new HashMap<String, String>();
params.put("mchId", mchId);
params.put("certficatesNo", certficatesNo);
JSONObject body = Common.doWxPayApiV3Result(result);
if (body == null) {
throw new ServiceException("初始化失败。请先生成微信V3证书");
}
JSONArray certList = body.getJSONArray("data");
if (certList == null || certList.size() <= 0) {
throw new ServiceException("初始化失败。请先生成微信V3证书");
}
JSONObject certJson = certList.getJSONObject(0);
if (certJson == null) {
throw new ServiceException("初始化失败。请先生成微信V3证书");
}
JSONObject certInfoJson = certJson.getJSONObject("encrypt_certificate");
if (certInfoJson == null) {
throw new ServiceException("初始化失败。请先生成微信V3证书");
}
String associatedData = certInfoJson.getString("associated_data");
String cipherText = certInfoJson.getString("ciphertext");
String nonce = certInfoJson.getString("nonce");
wxPayPublicKey = WxPayInitUtil.getWxPayPublicKey(associatedData, nonce, cipherText, v3Key);
} catch (WxPayException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
return wxPayPublicKey;
}
@Override
public JSONObject decryptCallback(WxPayAccountConfig wxPayAccountConfig, JSONObject data) {
try {
if (data == null) {
throw new ServiceException("通知数据为空");
}
JSONObject resourceJson = data.getJSONObject("resource");
if (resourceJson == null) {
throw new ServiceException("通知数据转json对象失败");
}
AesUtil aesUtil = new AesUtil(wxPayAccountConfig.getV3Key().getBytes(StandardCharsets.UTF_8));
String associatedData = resourceJson.getString("associated_data");
String nonce = resourceJson.getString("nonce");
String cipherText = resourceJson.getString("ciphertext");
if (StringUtils.isBlank(associatedData) || StringUtils.isBlank(nonce) || StringUtils.isBlank(cipherText)) {
throw new ServiceException("通知参数解密失败");
}
String resource = aesUtil.decryptToString(associatedData.getBytes(StandardCharsets.UTF_8), nonce.getBytes(StandardCharsets.UTF_8), cipherText);
if (StringUtil.isBlank(resource)) {
throw new ServiceException("通知参数解密失败");
}
JSONObject notifyJson = JSONObject.parseObject(resource);
return notifyJson;
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
}
@Override
public Map<String, Object> codePay(String authCode, Order order, WxPayAccountConfig wxPayAccountConfig, String attach) {
Map<String, Object> map = new HashMap<String, Object>();
try {
Map<String, String> codePayParam = wxPayV2ParamsUtil.getCodePayParam(authCode, order, wxPayAccountConfig, attach);
String xmlResult = WxPayApi.doPost(WxApiType.MICRO_PAY.toString(), codePayParam);
Map<String, String> resultMap = Common.doWxPayApiResult(xmlResult);
map.put("status", "NONE");
map.put("orderNo", order.getOrderNo());
if ("USERPAYING".equals(resultMap.get("err_code"))) {
map.put("status", "PAYING");
} else {
map.put("status", "SUCCESS");
String payNo = resultMap.get("transaction_id");
String payTime = resultMap.get("time_end");
if (!StringUtils.isBlank(payTime)) {
payTime = DateUtil.formatDateTime(DateUtil.parse(payTime, DatePattern.NORM_DATETIME_FORMAT));
}
String openId = resultMap.get("openid");
orderService.paySuccess(order.getOrderNo(), order.getMchId(), payNo, payTime, openId);
}
} catch (WxPayException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
return map;
}
@Override
public String nativePay(Order order, WxPayAccountConfig wxPayAccountConfig, String attach) {
String codeUrl = null;
try {
Map<String, Object> nativePayParams = wxPayV3ParamsUtil.getNativePayParams(order.getOrderNo(), order.getAppId(), order.getMchId(), order.getBody(), order.getMoney(), attach, order.getNotifyUrl());
String url = WxApiType.NATIVE_PAY.toString();
JSONObject body = wxPayV3ApiHttpUtil.doPost(url, nativePayParams, wxPayAccountConfig);
codeUrl = body.getString("code_url");
} catch (WxPayException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
return codeUrl;
}
@Override
public String jsPay(String openId, Order order, WxPayAccountConfig wxPayAccountConfig, String attach) {
String prepayId = null;
try {
Map<String, Object> jsApiParams = wxPayV3ParamsUtil.getJsApiParams(order.getOrderNo(), order.getAppId(), order.getMchId(), openId, order.getBody(), order.getMoney(), attach, order.getNotifyUrl());
String url = WxApiType.JS_API_PAY.toString();
JSONObject body = wxPayV3ApiHttpUtil.doPost(url,jsApiParams, wxPayAccountConfig);
prepayId = body.getString("prepay_id");
} catch (WxPayException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
return prepayId;
}
@Override
public String h5Pay(Order order, WxPayAccountConfig wxPayAccountConfig, String returnUrl, String attach) {
String h5Url = null;
try {
Map<String, Object> h5PayParams = wxPayV3ParamsUtil.getH5PayParams(order.getOrderNo(), order.getAppId(), order.getMchId(), order.getBody(), order.getMoney(), attach, order.getNotifyUrl(), returnUrl, WebUtil.getIP());
String url = WxApiType.H5_PAY.toString();
JSONObject body = wxPayV3ApiHttpUtil.doPost(url, h5PayParams, wxPayAccountConfig);
h5Url = body.getString("h5_url");
} catch (WxPayException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
return h5Url;
}
@Override
public String appPay(String appId, Order order, WxPayAccountConfig wxPayAccountConfig, String attach) {
String prepayId = null;
try {
Map<String, Object> appPayParams = wxPayV3ParamsUtil.getAppPayParams(order.getOrderNo(), order.getAppId(), order.getMchId(), order.getBody(), order.getMoney(), attach, order.getNotifyUrl());
String url = WxApiType.APP_PAY.toString();
JSONObject body = wxPayV3ApiHttpUtil.doPost(url, appPayParams, wxPayAccountConfig);
prepayId = body.getString("prepay_id");
} catch (WxPayException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
return prepayId;
}
@Override
public WxPayRefundBiz refund(Refund refund, WxPayAccountConfig wxPayAccountConfig, String orderMoney) {
WxPayRefundBiz wxPayRefundBiz = null;
try {
Map<String, Object> refundParams = wxPayV3ParamsUtil.getRefundParams(refund.getOrderNo(), refund.getPayNo(), refund.getRefundNo(), orderMoney, refund.getRefundMoney(), refund.getRefundDesc(), refund.getNotifyUrl());
String url = WxApiType.DOMESTIC_REFUNDS.toString();
JSONObject body = wxPayV3ApiHttpUtil.doPost(url, refundParams, wxPayAccountConfig);
wxPayRefundBiz = JSON.toJavaObject(body, WxPayRefundBiz.class);
} catch (WxPayException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
return wxPayRefundBiz;
}
@Override
public JSONObject getOrderInfo(String orderNo, String payNo, WxPayAccountConfig wxPayAccountConfig) {
try {
Map<String, String> params = wxPayV3ParamsUtil.getOrderInfoParams(wxPayAccountConfig.getMchId());
String url = String.format(WxApiType.ORDER_QUERY_BY_NO.toString(), orderNo);
if (!StringUtil.isBlank(payNo)) {
url = String.format(WxApiType.ORDER_QUERY_BY_ID.toString(), payNo);
}
JSONObject body = wxPayV3ApiHttpUtil.doGet(url, params, wxPayAccountConfig);
return body;
} catch (WxPayException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
}
}

View File

@@ -0,0 +1,22 @@
package org.springblade.plugin.pay.api.yungouos;
import org.springblade.plugin.pay.entity.MergePayConfig;
import org.springblade.plugin.pay.entity.Order;
/**
* YunGouOS聚合支付接口
*
* @author YunGouOS技术部-029
* @time 2022/6/28 15:05
*/
public interface IMergePayApiService {
/**
* 微信扫码支付
*
* @param order
* @return
*/
public String nativePay(Order order, MergePayConfig mergePayConfig, String type, String attach, String returnUrl, String configNo, String auto, String autoNode);
}

View File

@@ -0,0 +1,29 @@
package org.springblade.plugin.pay.api.yungouos.impl;
import com.yungouos.pay.common.PayException;
import com.yungouos.pay.merge.MergePay;
import lombok.AllArgsConstructor;
import org.springblade.plugin.pay.api.yungouos.IMergePayApiService;
import org.springblade.plugin.pay.entity.MergePayConfig;
import org.springblade.plugin.pay.entity.Order;
import org.springframework.stereotype.Service;
/**
* @author YunGouOS技术部-029
* @time 2022/6/28 15:05
*/
@Service
@AllArgsConstructor
public class MergePayApiServiceImpl implements IMergePayApiService {
@Override
public String nativePay(Order order, MergePayConfig mergePayConfig, String type, String attach, String returnUrl, String configNo, String auto, String autoNode) {
String url = null;
try {
url = MergePay.nativePay(order.getOrderNo(), order.getMoney(), order.getMchId(), order.getBody(), type, attach, order.getNotifyUrl(), returnUrl, configNo, auto, autoNode,null,null, mergePayConfig.getPayKey());
} catch (PayException e) {
e.printStackTrace();
throw new PayException(e.getMessage());
}
return url;
}
}

View File

@@ -0,0 +1,121 @@
package org.springblade.plugin.pay.common;
/**
* 自定义支付宝处理异常
*
* @description
*
* @author YunGouOS技术部-029
*
* @time 2018年12月14日 下午8:16:15
*
*
*/
public class AliPayException extends RuntimeException {
private static final long serialVersionUID = 7973713189507995958L;
/**
* 错误编码
*/
private String errorCode;
/**
* 消息是否为属性文件中的Key
*/
private boolean propertiesKey = true;
/**
* 构造一个基本异常.
*
* @param message
* 信息描述
*/
public AliPayException(String message) {
super(message);
}
/**
* 构造一个基本异常.
*
* @param errorCode
* 错误编码
* @param message
* 信息描述
*/
public AliPayException(String errorCode, String message) {
this(errorCode, message, true);
}
/**
* 构造一个基本异常.
*
* @param errorCode
* 错误编码
* @param message
* 信息描述
*/
public AliPayException(String errorCode, String message, Throwable cause) {
this(errorCode, message, cause, true);
}
/**
* 构造一个基本异常.
*
* @param errorCode
* 错误编码
* @param message
* 信息描述
* @param propertiesKey
* 消息是否为属性文件中的Key
*/
public AliPayException(String errorCode, String message, boolean propertiesKey) {
super(message);
this.setErrorCode(errorCode);
this.setPropertiesKey(propertiesKey);
}
/**
* 构造一个基本异常.
*
* @param errorCode
* 错误编码
* @param message
* 信息描述
*/
public AliPayException(String errorCode, String message, Throwable cause, boolean propertiesKey) {
super(message, cause);
this.setErrorCode(errorCode);
this.setPropertiesKey(propertiesKey);
}
/**
* 构造一个基本异常.
*
* @param message
* 信息描述
* @param cause
* 根异常类(可以存入任何异常)
*/
public AliPayException(String message, Throwable cause) {
super(message, cause);
}
public String getErrorCode() {
return errorCode;
}
public void setErrorCode(String errorCode) {
this.errorCode = errorCode;
}
public boolean isPropertiesKey() {
return propertiesKey;
}
public void setPropertiesKey(boolean propertiesKey) {
this.propertiesKey = propertiesKey;
}
}

View File

@@ -0,0 +1,101 @@
package org.springblade.plugin.pay.common;
import cn.hutool.core.map.MapUtil;
import com.alibaba.fastjson.JSONObject;
import com.ijpay.core.kit.PayKit;
import org.apache.commons.lang.StringUtils;
import org.springblade.core.tool.utils.StringUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @author YunGouOS技术部-029
* @time 2021/12/31 11:28
*/
public class Common {
/**
* 解析微信支付V3api返回结果
*
* @author YunGouOS
* @date 2020年3月9日 上午10:07:57
*/
public static JSONObject doWxPayApiV3Result(Map<String, Object> resultMap) {
if (resultMap == null || resultMap.size() <= 0) {
throw new WxPayException("请求微信API无响应,请稍候再试!");
}
Integer status = MapUtil.getInt(resultMap, "status");
String body = MapUtil.getStr(resultMap, "body");
JSONObject data = null;
if (!StringUtils.isBlank(body)) {
data = JSONObject.parseObject(body);
}
List<Integer> list = getWxV3ApiSuccessStatusList();
if (!list.contains(status)) {
if (data == null) {
throw new WxPayException("请求微信API无响应数据,请稍后再试!");
}
String code = data.getString("code");
if (!StringUtils.isBlank(code)) {
throw new WxPayException(data.getString("message"));
}
}
return data;
}
public static List<Integer> getWxV3ApiSuccessStatusList() {
List<Integer> list = new ArrayList<Integer>();
list.add(200);// 处理成功有消息体
list.add(204);// 处理成功 无消息体
list.add(202);// 处理中
return list;
}
/**
* 解析支付宝API返回结果
*
* @title
* @author YunGouOS
* @date 2019年12月29日 下午1:53:47
*/
public static JSONObject doAliPayApiResult(String jsonResult) {
if (StringUtils.isBlank(jsonResult)) {
throw new AliPayException("请求支付宝API无响应,请稍候再试!");
}
JSONObject resultJsonObj = (JSONObject) JSONObject.parse(jsonResult);
if (resultJsonObj == null) {
throw new AliPayException("支付宝API返回结果转换失败,请稍候再试!");
}
return resultJsonObj;
}
/**
* 解析微信支付API返回结果
*
* @author YunGouOS
* @date 2019年3月4日 下午4:03:55
*/
public static Map<String, String> doWxPayApiResult(String xmlResult) {
if (StringUtils.isBlank(xmlResult)) {
throw new WxPayException("请求微信API无响应,请稍候再试!");
}
Map<String, String> resultMap = PayKit.xmlToMap(xmlResult);
String return_code = resultMap.get("return_code");
String return_msg = resultMap.get("return_msg");
if (StringUtil.isBlank(return_code) || !"SUCCESS".equals(return_code)) {
throw new WxPayException(return_msg);
}
String result_code = resultMap.get("result_code");
if (StringUtil.isBlank(result_code) || !"SUCCESS".equals(result_code)) {
// 付款码支付,等待用户输入密码
if ("USERPAYING".equals(resultMap.get("err_code"))) {
return resultMap;
}
throw new WxPayException(resultMap.get("err_code_des"));
}
return resultMap;
}
}

View File

@@ -0,0 +1,121 @@
package org.springblade.plugin.pay.common;
/**
* 自定义微信支付处理异常
*
* @description
*
* @author YunGouOS技术部-029
*
* @time 2018年12月14日 下午8:16:15
*
*
*/
public class WxPayException extends RuntimeException {
private static final long serialVersionUID = 7973713189507995958L;
/**
* 错误编码
*/
private String errorCode;
/**
* 消息是否为属性文件中的Key
*/
private boolean propertiesKey = true;
/**
* 构造一个基本异常.
*
* @param message
* 信息描述
*/
public WxPayException(String message) {
super(message);
}
/**
* 构造一个基本异常.
*
* @param errorCode
* 错误编码
* @param message
* 信息描述
*/
public WxPayException(String errorCode, String message) {
this(errorCode, message, true);
}
/**
* 构造一个基本异常.
*
* @param errorCode
* 错误编码
* @param message
* 信息描述
*/
public WxPayException(String errorCode, String message, Throwable cause) {
this(errorCode, message, cause, true);
}
/**
* 构造一个基本异常.
*
* @param errorCode
* 错误编码
* @param message
* 信息描述
* @param propertiesKey
* 消息是否为属性文件中的Key
*/
public WxPayException(String errorCode, String message, boolean propertiesKey) {
super(message);
this.setErrorCode(errorCode);
this.setPropertiesKey(propertiesKey);
}
/**
* 构造一个基本异常.
*
* @param errorCode
* 错误编码
* @param message
* 信息描述
*/
public WxPayException(String errorCode, String message, Throwable cause, boolean propertiesKey) {
super(message, cause);
this.setErrorCode(errorCode);
this.setPropertiesKey(propertiesKey);
}
/**
* 构造一个基本异常.
*
* @param message
* 信息描述
* @param cause
* 根异常类(可以存入任何异常)
*/
public WxPayException(String message, Throwable cause) {
super(message, cause);
}
public String getErrorCode() {
return errorCode;
}
public void setErrorCode(String errorCode) {
this.errorCode = errorCode;
}
public boolean isPropertiesKey() {
return propertiesKey;
}
public void setPropertiesKey(boolean propertiesKey) {
this.propertiesKey = propertiesKey;
}
}

View File

@@ -0,0 +1,17 @@
package org.springblade.plugin.pay.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Data
@Component
@ConfigurationProperties(prefix = "alipay")
public class AliPayConfiguration {
private String appId;
private String machId;
private String notifyUrl;
}

View File

@@ -0,0 +1,16 @@
package org.springblade.plugin.pay.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Data
@Component
@ConfigurationProperties(prefix = "wechatpay")
public class WxPayConfiguration {
private String appId;
private String machId;
private String notifyUrl;
}

View File

@@ -0,0 +1,48 @@
package org.springblade.plugin.pay.constant;
/**
* 支付通用常量
*
* @author YunGouOS技术部-029
* @time 2022/1/2 22:45
*/
public interface PayConstant {
//服务名
String SERVICE_NAME = "blade-pay";
//微信支付
String WXPAY = "wxpay";
//支付宝
String ALIPAY = "alipay";
//聚合支付
String MERGE = "merge";
//扫码支付
String NATIVEPAY = "native";
//公众号支付
String JSPAY = "jsapi";
//微信小程序支付
String WXMAPPPAY = "wxapp";
//H5支付
String H5PAY = "h5";
//APP支付
String APPPAY = "app";
// 条码支付
String CODEPAY = "code";
// 人脸支付
String FACEPAY = "face";
// 电脑支付
String PCPAY = "pc";
}

View File

@@ -0,0 +1,145 @@
package org.springblade.plugin.pay.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.plugin.pay.constant.PayConstant;
import org.springblade.plugin.pay.entity.AliPayAccountConfig;
import org.springblade.plugin.pay.service.IAliPayAccountConfigService;
import org.springblade.plugin.pay.vo.AliPayAccountConfigVO;
import org.springframework.web.bind.annotation.*;
/**
* 支付宝商户配置控制器
*/
@RestController
@AllArgsConstructor
@RequestMapping(PayConstant.SERVICE_NAME + "/" + PayConstant.ALIPAY + "/config")
@Tag(name = "", description = "接口")
public class AliPayAccountConfigController extends BladeController {
private final IAliPayAccountConfigService aliPayAccountConfigService;
/**
* 详情
*/
@GetMapping("/detail")
@ApiOperationSupport(order = 1)
@Operation(summary = "详情", description = "传入aliPayAccountConfig")
public R<AliPayAccountConfig> detail(AliPayAccountConfig aliPayAccountConfig) {
AliPayAccountConfig detail = aliPayAccountConfigService.getOne(Condition.getQueryWrapper(aliPayAccountConfig));
return R.data(detail);
}
/**
* 分页
*/
@GetMapping("/list")
@ApiOperationSupport(order = 2)
@Operation(summary = "分页", description = "传入aliPayAccountConfig")
public R<IPage<AliPayAccountConfig>> list(AliPayAccountConfig aliPayAccountConfig, Query query) {
IPage<AliPayAccountConfig> pages = aliPayAccountConfigService.page(Condition.getPage(query.setDescs("create_time")), Condition.getQueryWrapper(aliPayAccountConfig));
return R.data(pages);
}
/**
* 自定义分页
*/
@GetMapping("/page")
@ApiOperationSupport(order = 3)
@Operation(summary = "分页", description = "传入aliPayAccountConfig")
public R<IPage<AliPayAccountConfigVO>> page(AliPayAccountConfigVO aliPayAccountConfig, Query query) {
IPage<AliPayAccountConfigVO> pages = aliPayAccountConfigService.selectAliPayAccountConfigPage(Condition.getPage(query.setDescs("create_time")), aliPayAccountConfig);
return R.data(pages);
}
/**
* 新增
*/
@PostMapping("/save")
@ApiOperationSupport(order = 4)
@Operation(summary = "新增", description = "传入aliPayAccountConfig")
public R save(@Valid @RequestBody AliPayAccountConfig aliPayAccountConfig) {
if (!StringUtil.isBlank(aliPayAccountConfig.getAlipayPubCert())) {
aliPayAccountConfig.setAlipayPubCert(null);
}
if (!StringUtil.isBlank(aliPayAccountConfig.getPrivateKey())) {
aliPayAccountConfig.setPrivateKey(null);
}
if (!StringUtil.isBlank(aliPayAccountConfig.getRootCert())) {
aliPayAccountConfig.setRootCert(null);
}
if (!StringUtil.isBlank(aliPayAccountConfig.getAppCert())) {
aliPayAccountConfig.setAppCert(null);
}
return R.status(aliPayAccountConfigService.save(aliPayAccountConfig));
}
/**
* 修改
*/
@PostMapping("/update")
@ApiOperationSupport(order = 5)
@Operation(summary = "修改", description = "传入aliPayAccountConfig")
public R update(@Valid @RequestBody AliPayAccountConfig aliPayAccountConfig) {
if (!StringUtil.isBlank(aliPayAccountConfig.getAlipayPubCert())) {
aliPayAccountConfig.setAlipayPubCert(null);
}
if (!StringUtil.isBlank(aliPayAccountConfig.getPrivateKey())) {
aliPayAccountConfig.setPrivateKey(null);
}
if (!StringUtil.isBlank(aliPayAccountConfig.getRootCert())) {
aliPayAccountConfig.setRootCert(null);
}
if (!StringUtil.isBlank(aliPayAccountConfig.getAppCert())) {
aliPayAccountConfig.setAppCert(null);
}
return R.status(aliPayAccountConfigService.updateById(aliPayAccountConfig));
}
/**
* 新增或修改
*/
@PostMapping("/submit")
@ApiOperationSupport(order = 6)
@Operation(summary = "新增或修改", description = "传入aliPayAccountConfig")
public R submit(@Valid @RequestBody AliPayAccountConfig aliPayAccountConfig) {
if (!StringUtil.isBlank(aliPayAccountConfig.getAlipayPubCert())) {
aliPayAccountConfig.setAlipayPubCert(null);
}
if (!StringUtil.isBlank(aliPayAccountConfig.getPrivateKey())) {
aliPayAccountConfig.setPrivateKey(null);
}
if (!StringUtil.isBlank(aliPayAccountConfig.getRootCert())) {
aliPayAccountConfig.setRootCert(null);
}
if (!StringUtil.isBlank(aliPayAccountConfig.getAppCert())) {
aliPayAccountConfig.setAppCert(null);
}
return R.status(aliPayAccountConfigService.saveOrUpdate(aliPayAccountConfig));
}
/**
* 删除
*/
@PostMapping("/remove")
@ApiOperationSupport(order = 8)
@Operation(summary = "删除", description = "传入ids")
public R remove(@Parameter(name = "主键集合", required = true) @RequestParam String ids) {
return R.status(aliPayAccountConfigService.removeByIds(Func.toLongList(ids)));
}
}

View File

@@ -0,0 +1,154 @@
package org.springblade.plugin.pay.controller;
import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.tool.api.R;
import org.springblade.plugin.pay.constant.PayConstant;
import org.springblade.plugin.pay.entityBiz.AliPayBiz;
import org.springblade.plugin.pay.entityBiz.AliPayPageApiBiz;
import org.springblade.plugin.pay.service.IAliPayService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
/**
* 支付宝支付接口控制器
*
* @author YunGouOS技术部-029
* @time 2022/1/1 17:57
*/
@RestController
@AllArgsConstructor
@RequestMapping(PayConstant.SERVICE_NAME + "/alipay")
public class AliPayController extends BladeController {
private final IAliPayService aliPayService;
/**
* 付款码支付
*
* @param json
* @return
*/
@RequestMapping("/codePay")
public R<Boolean> codePay(@RequestBody JSONObject json) {
String appId = json.getString("appId");
String mchId = json.getString("mchId");
String body = json.getString("body");
String authCode = json.getString("authCode");
String money = json.getString("money");
String notify = json.getString("notifyUrl");
String attach = json.getString("attach");
String orderPrefix = "S";
boolean result = aliPayService.codePay(appId, mchId, body, money, notify, authCode, attach ,orderPrefix);
return R.data(result);
}
/**
* 支付宝扫码支付
*
* @param json
* @return
*/
@RequestMapping("/nativePay")
public R<Map<String, Object>> nativePay(@RequestBody JSONObject json) {
String appId = json.getString("appId");
String mchId = json.getString("mchId");
String body = json.getString("body");
String money = json.getString("money");
String notify = json.getString("notifyUrl");
String attach = json.getString("attach");
String orderPrefix = "S";
Map<String, Object> map = aliPayService.nativePay(appId, mchId, body, money, notify, attach ,orderPrefix);
return R.data(map);
}
/**
* 支付宝jsapi支付
*
* @param json
* @return
*/
@RequestMapping("/jsPay")
public R<AliPayBiz> jsPay(@RequestBody JSONObject json) {
String appId = json.getString("appId");
String mchId = json.getString("mchId");
String buyerId = json.getString("buyerId");
String body = json.getString("body");
String money = json.getString("money");
String notify = json.getString("notifyUrl");
String attach = json.getString("attach");
String orderPrefix = "S";
AliPayBiz aliPayBiz = aliPayService.jsPay(appId, mchId, buyerId, body, money, notify, attach ,orderPrefix);
return R.data(aliPayBiz);
}
/**
* 电脑网站支付
* @param json
* @return
*/
@RequestMapping("/pcPay")
public R<AliPayPageApiBiz> pcPay(@RequestBody JSONObject json) {
String appId = json.getString("appId");
String mchId = json.getString("mchId");
String body = json.getString("body");
String money = json.getString("money");
String notify = json.getString("notifyUrl");
String returnUrl = json.getString("returnUrl");
String attach = json.getString("attach");
String orderPrefix = "S";
AliPayPageApiBiz aliPayPageApiBiz = aliPayService.pcPay(appId, mchId, body, money, notify, returnUrl, attach ,orderPrefix);
return R.data(aliPayPageApiBiz);
}
/**
* 支付宝H5支付
*
* @param json
* @return
*/
@RequestMapping("/h5Pay")
public R<AliPayPageApiBiz> h5Pay(@RequestBody JSONObject json) {
String appId = json.getString("appId");
String mchId = json.getString("mchId");
String body = json.getString("body");
String money = json.getString("money");
String notify = json.getString("notifyUrl");
String returnUrl = json.getString("returnUrl");
String attach = json.getString("attach");
String orderPrefix = "S";
AliPayPageApiBiz aliPayPageApiBiz = aliPayService.h5Pay(appId, mchId, body, money, notify, returnUrl, attach , orderPrefix);
return R.data(aliPayPageApiBiz);
}
/**
* 支付宝APP支付
*
* @param json
* @return
*/
@RequestMapping("/appPay")
public R<String> appPay(@RequestBody JSONObject json) {
String appId = json.getString("appId");
String mchId = json.getString("mchId");
String body = json.getString("body");
String money = json.getString("money");
String notify = json.getString("notifyUrl");
String attach = json.getString("attach");
String orderPrefix = "S";
Long orderId = 12736612836182L;
String appPayStr = aliPayService.appPay(appId, mchId , body, money, notify, attach, orderPrefix ,orderId);
return R.data(appPayStr);
}
}

View File

@@ -0,0 +1,382 @@
package org.springblade.plugin.pay.controller;
import cn.hutool.http.ContentType;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException;
import com.alipay.api.internal.util.AlipaySignature;
import com.ijpay.core.utils.DateTimeZoneUtil;
import com.yungouos.pay.util.PaySignUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.plugin.pay.api.wxpay.IWxPayApiService;
import org.springblade.plugin.pay.common.WxPayException;
import org.springblade.plugin.pay.constant.PayConstant;
import org.springblade.plugin.pay.entity.AliPayAccountConfig;
import org.springblade.plugin.pay.entity.MergePayConfig;
import org.springblade.plugin.pay.entity.WxPayAccountConfig;
import org.springblade.plugin.pay.service.*;
import org.springblade.plugin.pay.util.AliPayApiUtil;
import org.springblade.plugin.pay.util.WxPayUtil;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
/**
* 支付回调
*
* @author YunGouOS技术部-029
* @time 2021/12/31 22:18
*/
@RestController
@AllArgsConstructor
@RequestMapping(PayConstant.SERVICE_NAME + "/callback")
public class CallbackController {
private final IWxPayApiService wxPayApiService;
private final IWxPayAccountConfigService wxPayAccountConfigService;
private final IOrderService orderService;
private final IRefundService refundService;
private final IAliPayAccountConfigService aliPayAccountConfigService;
private final IMergePayConfigService mergePayConfigService;
/**
* 微信支付回调
*
* @param mchId
* @param jsonParam
* @return
*/
@RequestMapping("/wxpay/{mchId}")
public ResponseEntity wxCallback(@PathVariable String mchId, @RequestBody JSONObject jsonParam, HttpServletRequest request) {
JSONObject result = new JSONObject();
result.put("code", "fail");
result.put("message", "支付失败");
try {
WxPayAccountConfig wxPayAccountConfig = wxPayAccountConfigService.getInfoByMchId(mchId);
if (wxPayAccountConfig == null) {
throw new WxPayException("商户号尚未接入");
}
//签名验证
WxPayUtil.checkNotifySign(request, wxPayAccountConfig);
JSONObject notifyJson = wxPayApiService.decryptCallback(wxPayAccountConfig, jsonParam);
String orderNo = notifyJson.getString("out_trade_no");
String payNo = notifyJson.getString("transaction_id");
String payTime = notifyJson.getString("success_time");
if (!StringUtil.isBlank(payTime)) {
payTime = DateTimeZoneUtil.timeZoneDateToStr(payTime);
}
String openId = notifyJson.getJSONObject("payer").getString("openid");
boolean success = orderService.paySuccess(orderNo, mchId, payNo, payTime, openId);
if (success) {
//返回给微信告诉处理完成,不需要再回调。
return new ResponseEntity(null, HttpStatus.OK);
}
} catch (WxPayException e) {
e.printStackTrace();
result.put("message", e.getMessage());
} catch (Exception e) {
e.printStackTrace();
result.put("message", e.getMessage());
}
return new ResponseEntity<JSONObject>(result, HttpStatus.INTERNAL_SERVER_ERROR);
}
/**
* 微信支付退款回调
*
* @param mchId
* @param jsonParam
* @return
*/
@RequestMapping("/wxpay/refund/{mchId}")
public ResponseEntity wxPayRefundCallback(@PathVariable String mchId, @RequestBody JSONObject jsonParam, HttpServletRequest request) {
JSONObject result = new JSONObject();
result.put("code", "fail");
result.put("message", "退款失败");
try {
WxPayAccountConfig wxPayAccountConfig = wxPayAccountConfigService.getInfoByMchId(mchId);
if (wxPayAccountConfig == null) {
throw new ServiceException("商户号尚未接入");
}
//签名验证
WxPayUtil.checkNotifySign(request, wxPayAccountConfig);
JSONObject notifyJson = wxPayApiService.decryptCallback(wxPayAccountConfig, jsonParam);
String orderNo = notifyJson.getString("out_trade_no");
String payNo = notifyJson.getString("transaction_id");
String refundNo = notifyJson.getString("out_refund_no");
String refundId = notifyJson.getString("refund_id");
String refundStatus = notifyJson.getString("refund_status");
String refundTime = notifyJson.getString("success_time");
JSONObject amount = notifyJson.getJSONObject("amount");
Integer refund = amount.getInteger("refund");
if (!StringUtil.isBlank(refundTime)) {
refundTime = DateTimeZoneUtil.timeZoneDateToStr(refundTime);
}
boolean success = refundService.refundSuccess(refundNo, mchId);
if (success) {
//返回给微信告诉处理完成,不需要再回调。
return new ResponseEntity(null, HttpStatus.OK);
}
} catch (WxPayException e) {
e.printStackTrace();
result.put("message", e.getMessage());
} catch (Exception e) {
e.printStackTrace();
result.put("message", e.getMessage());
}
return new ResponseEntity<JSONObject>(result, HttpStatus.INTERNAL_SERVER_ERROR);
}
/**
* 支付宝支付回调
*
* @param request
*/
@RequestMapping(value = "/alipay")
public void alipay(HttpServletRequest request, HttpServletResponse response) {
String result = "支付失败";
try {
// 获取支付宝POST过来反馈信息
Map<String, String> params = AliPayApiUtil.toMap(request);
System.out.println("支付宝回调参数:" + params.toString());
String mchId = params.get("seller_id");
String appId = params.get("app_id");
if (StringUtils.isBlank(mchId)) {
result = "seller_id is not null";
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), result, new String[]{"encoding:UTF-8"});
return;
}
AliPayAccountConfig aliPayAccountConfig = aliPayAccountConfigService.getInfoByMchIdAndAppId(mchId, appId);
if (aliPayAccountConfig == null) {
result = "该商户号尚未接入";
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), result, new String[]{"encoding:UTF-8"});
return;
}
String signType = aliPayAccountConfig.getSignType();
String pubKey = aliPayAccountConfig.getPubKey();
boolean verify_result = AlipaySignature.rsaCheckV1(params, pubKey, "UTF-8", signType);
if (!verify_result) {
result = "签名验证失败";
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), result, new String[]{"encoding:UTF-8"});
return;
}
//支付状态
String trade_status = params.get("trade_status");
// 总金额
String money = params.get("total_amount");
// 支付宝订单号
String payNo = params.get("trade_no");
// 商户订单号
String orderNo = params.get("out_trade_no");
//买家ID
String openId = params.get("buyer_id");
//支付时间
String payTime = params.get("gmt_payment");
//退款金额
String refund_fee = params.get("refund_fee");
//退款时间
String gmt_refund = params.get("gmt_refund");
//退款单号
String refundNo = params.get("out_biz_no");
switch (trade_status) {
case "WAIT_BUYER_PAY":
result = "wait buyer pay";
break;
case "TRADE_CLOSED":
//全额退款成功回调
if (refundService.refundSuccess(refundNo, mchId)) {
result = "success";
}
break;
case "TRADE_SUCCESS":
if (StringUtils.isBlank(refund_fee) && StringUtils.isBlank(gmt_refund)) {
//支付成功回调
if (orderService.paySuccess(orderNo, mchId, payNo, payTime, openId)) {
result = "success";
}
} else {
//部分退款回调
if (refundService.refundSuccess(refundNo, mchId)) {
result = "success";
}
}
break;
case "TRADE_FINISHED":
//交易结束,不可退款
result = "success";
break;
default:
break;
}
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), result, new String[]{"encoding:UTF-8"});
} catch (AlipayApiException e) {
e.printStackTrace();
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), e.getMessage(), new String[]{"encoding:UTF-8"});
} catch (Exception e) {
e.printStackTrace();
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), e.getMessage(), new String[]{"encoding:UTF-8"});
}
}
/**
* YunGouOS服务商支付回调
* 回调文档:https://open.pay.yungouos.com/#/callback/notify
*
* @param data
* @param response
*/
@RequestMapping(value = "/yungouos")
public void yungouos(@RequestParam Map<String, String> data, HttpServletResponse response, String appId) {
String result = "faild";
try {
String channel = data.get("payChannel");
String mchId = data.get("mchId");
if (StringUtils.isBlank(channel) || StringUtils.isBlank(mchId)) {
result = "参数错误";
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), result, new String[]{"encoding:UTF-8"});
return;
}
String payKey = null;
switch (channel) {
case "wxpay":
//微信交易回调
WxPayAccountConfig wxPayAccountConfig = wxPayAccountConfigService.getInfoByMchId(mchId);
if (wxPayAccountConfig == null) {
result = "商户号尚未接入";
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), result, new String[]{"encoding:UTF-8"});
return;
}
payKey = wxPayAccountConfig.getPayKey();
break;
case "alipay":
//支付宝交易回调
AliPayAccountConfig aliPayAccountConfig = aliPayAccountConfigService.getInfoByMchIdAndAppId(mchId, null);
if (aliPayAccountConfig == null) {
result = "商户号尚未接入";
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), result, new String[]{"encoding:UTF-8"});
return;
}
payKey = aliPayAccountConfig.getPayKey();
break;
default:
break;
}
boolean check = PaySignUtil.checkRefundNotifySign(data, payKey);
if (!check) {
result = "验签失败,签名错误";
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), result, new String[]{"encoding:UTF-8"});
return;
}
//TODO 处理你自己的业务
String orderNo = data.get("outTradeNo");
String payNo = data.get("payNo");
String payTime = data.get("time");
String openId = data.get("openId");
boolean success = false;
if (!StringUtil.isBlank(appId)) {
//聚合支付
success = orderService.paySuccessMerge(orderNo, appId, mchId, payNo, payTime, openId);
} else {
success = orderService.paySuccess(orderNo, mchId, payNo, payTime, openId);
}
if (success) {
result = "SUCCESS";
}
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), result, new String[]{"encoding:UTF-8"});
} catch (Exception e) {
e.printStackTrace();
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), e.getMessage(), new String[]{"encoding:UTF-8"});
}
}
/**
* YunGouOS服务商退款回调
* 文档地址:https://open.pay.yungouos.com/#/callback/refund
*
* @param data
* @param response
*/
@RequestMapping(value = "/yungouos/refund")
public void yungouosRefund(@RequestParam Map<String, String> data, HttpServletResponse response) {
String result = "faild";
try {
String channel = data.get("channel");
String mchId = data.get("mchId");
String refundNo = data.get("outTradeRefundNo");
if (StringUtils.isBlank(channel) || StringUtils.isBlank(mchId)) {
result = "参数错误";
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), result, new String[]{"encoding:UTF-8"});
return;
}
String payKey = null;
switch (channel) {
case "wxpay":
//微信交易回调
WxPayAccountConfig wxPayAccountConfig = wxPayAccountConfigService.getInfoByMchId(mchId);
if (wxPayAccountConfig == null) {
result = "商户号尚未接入";
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), result, new String[]{"encoding:UTF-8"});
return;
}
payKey = wxPayAccountConfig.getPayKey();
break;
case "alipay":
//支付宝交易回调
AliPayAccountConfig aliPayAccountConfig = aliPayAccountConfigService.getInfoByMchIdAndAppId(mchId, null);
if (aliPayAccountConfig == null) {
result = "商户号尚未接入";
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), result, new String[]{"encoding:UTF-8"});
return;
}
payKey = aliPayAccountConfig.getPayKey();
break;
default:
break;
}
boolean check = PaySignUtil.checkRefundNotifySign(data, payKey);
if (!check) {
result = "验签失败,签名错误";
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), result, new String[]{"encoding:UTF-8"});
return;
}
//TODO 处理你自己的业务
boolean success = refundService.refundSuccess(refundNo, mchId);
if (success) {
result = "SUCCESS";
}
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), result, new String[]{"encoding:UTF-8"});
} catch (Exception e) {
e.printStackTrace();
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), e.getMessage(), new String[]{"encoding:UTF-8"});
}
}
/**
* YunGouOS服务商聚合支付回调
*
* @param mchId
* @param data
* @param response
*/
@RequestMapping(value = "/yungouos/merge/{mchId}")
public void yungouosMerge(@PathVariable String mchId, @RequestParam Map<String, String> data, HttpServletResponse response) {
MergePayConfig payConfig = mergePayConfigService.getInfoByMchId(mchId);
if (payConfig == null) {
AliPayApiUtil.render(response, ContentType.TEXT_PLAIN.getValue(), "商户号尚未接入", new String[]{"encoding:UTF-8"});
return;
}
yungouos(data, response, mchId);
}
}

View File

@@ -0,0 +1,132 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.plugin.pay.constant.PayConstant;
import org.springblade.plugin.pay.entity.MergePayConfig;
import org.springblade.plugin.pay.service.IMergePayConfigService;
import org.springblade.plugin.pay.vo.MergePayConfigVO;
import org.springframework.web.bind.annotation.*;
/**
* 控制器
*
* @author BladeX
* @since 2022-06-27
*/
@RestController
@AllArgsConstructor
@RequestMapping(PayConstant.SERVICE_NAME + "/merge/config")
@Tag(name = "", description = "接口")
public class MergePayConfigController extends BladeController {
private final IMergePayConfigService mergePayConfigService;
/**
* 详情
*/
@GetMapping("/detail")
@ApiOperationSupport(order = 1)
@Operation(summary = "详情", description = "传入mergePayConfig")
public R<MergePayConfig> detail(MergePayConfig mergePayConfig) {
MergePayConfig detail = mergePayConfigService.getOne(Condition.getQueryWrapper(mergePayConfig));
return R.data(detail);
}
/**
* 分页
*/
@GetMapping("/list")
@ApiOperationSupport(order = 2)
@Operation(summary = "分页", description = "传入mergePayConfig")
public R<IPage<MergePayConfig>> list(MergePayConfig mergePayConfig, Query query) {
IPage<MergePayConfig> pages = mergePayConfigService.page(Condition.getPage(query), Condition.getQueryWrapper(mergePayConfig));
return R.data(pages);
}
/**
* 自定义分页
*/
@GetMapping("/page")
@ApiOperationSupport(order = 3)
@Operation(summary = "分页", description = "传入mergePayConfig")
public R<IPage<MergePayConfigVO>> page(MergePayConfigVO mergePayConfig, Query query) {
IPage<MergePayConfigVO> pages = mergePayConfigService.selectMergePayConfigPage(Condition.getPage(query), mergePayConfig);
return R.data(pages);
}
/**
* 新增
*/
@PostMapping("/save")
@ApiOperationSupport(order = 4)
@Operation(summary = "新增", description = "传入mergePayConfig")
public R save(@Valid @RequestBody MergePayConfig mergePayConfig) {
if (mergePayConfig != null) {
mergePayConfig.setIsDeleted(0);
}
return R.status(mergePayConfigService.save(mergePayConfig));
}
/**
* 修改
*/
@PostMapping("/update")
@ApiOperationSupport(order = 5)
@Operation(summary = "修改", description = "传入mergePayConfig")
public R update(@Valid @RequestBody MergePayConfig mergePayConfig) {
return R.status(mergePayConfigService.updateById(mergePayConfig));
}
/**
* 新增或修改
*/
@PostMapping("/submit")
@ApiOperationSupport(order = 6)
@Operation(summary = "新增或修改", description = "传入mergePayConfig")
public R submit(@Valid @RequestBody MergePayConfig mergePayConfig) {
if (mergePayConfig != null) {
mergePayConfig.setIsDeleted(0);
}
return R.status(mergePayConfigService.saveOrUpdate(mergePayConfig));
}
/**
* 删除
*/
@PostMapping("/remove")
@ApiOperationSupport(order = 8)
@Operation(summary = "删除", description = "传入ids")
public R remove(@Parameter(name = "主键集合", required = true) @RequestParam String ids) {
return R.status(mergePayConfigService.removeByIds(Func.toLongList(ids)));
}
}

View File

@@ -0,0 +1,75 @@
package org.springblade.plugin.pay.controller;
import com.alibaba.fastjson.JSONObject;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.tool.api.R;
import org.springblade.plugin.pay.constant.PayConstant;
import org.springblade.plugin.pay.service.IMergePayService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
/**
* 聚合支付控制类
*
* @author YunGouOS技术部-029
* @time 2022/6/28 11:10
*/
@RestController
@AllArgsConstructor
@RequestMapping(PayConstant.SERVICE_NAME + "/merge")
@Tag(name = "", description = "接口")
public class MergePayController extends BladeController {
private final IMergePayService mergePayService;
/**
* 聚合支付一码付,适合展示二维码 用户扫码支付
*
* @param json
* @return
*/
@RequestMapping("/nativePay")
public R<Map<String, Object>> nativePay(@RequestBody JSONObject json) {
String appId = json.getString("appId");
String mchId = json.getString("mchId");
String body = json.getString("body");
String money = json.getString("money");
String notifyUrl = json.getString("notifyUrl");
String returnUrl = json.getString("returnUrl");
String attach = json.getString("attach");
String configNo = json.getString("configNo");
String auto = json.getString("auto");
String autoNode = json.getString("autoNode");
String orderPrefix = "S";
Map<String, Object> map = mergePayService.nativePay(mchId, body, money, notifyUrl, returnUrl, attach, configNo, auto, autoNode, orderPrefix);
return R.data(map);
}
/**
* 聚合支付手机端,返回URL,在手机端重定向即可
*
* @param json
* @return
*/
@RequestMapping("/mobilePay")
public R<Map<String, Object>> mobilePay(@RequestBody JSONObject json) {
String appId = json.getString("appId");
String mchId = json.getString("mchId");
String body = json.getString("body");
String money = json.getString("money");
String notifyUrl = json.getString("notifyUrl");
String returnUrl = json.getString("returnUrl");
String attach = json.getString("attach");
String configNo = json.getString("configNo");
String auto = json.getString("auto");
String autoNode = json.getString("autoNode");
String orderPrefix = "S";
Map<String, Object> map = mergePayService.mobilePay(mchId, body, money, notifyUrl, returnUrl, attach, configNo, auto, autoNode, orderPrefix);
return R.data(map);
}
}

View File

@@ -0,0 +1,148 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.plugin.pay.constant.PayConstant;
import org.springblade.plugin.pay.entity.Order;
import org.springblade.plugin.pay.service.IOrderService;
import org.springblade.plugin.pay.vo.OrderVO;
import org.springframework.web.bind.annotation.*;
/**
* 控制器
*
* @author BladeX
* @since 2021-12-31
*/
@RestController
@AllArgsConstructor
@RequestMapping(PayConstant.SERVICE_NAME + "/order")
@Tag(name = "", description = "接口")
public class OrderController extends BladeController {
private final IOrderService orderService;
/**
* 详情
*/
@GetMapping("/detail")
@ApiOperationSupport(order = 1)
@Operation(summary = "详情", description ="传入order")
public R<Order> detail(Order order) {
Order detail = orderService.getOne(Condition.getQueryWrapper(order));
return R.data(detail);
}
/**
* 分页
*/
@GetMapping("/list")
@ApiOperationSupport(order = 2)
@Operation(summary = "分页", description ="传入order")
public R<IPage<Order>> list(Order order, Query query) {
IPage<Order> pages = orderService.page(Condition.getPage(query.setDescs("create_time")), Condition.getQueryWrapper(order));
return R.data(pages);
}
/**
* 自定义分页
*/
@GetMapping("/page")
@ApiOperationSupport(order = 3)
@Operation(summary = "分页", description ="传入order")
public R<IPage<OrderVO>> page(OrderVO order, Query query) {
IPage<OrderVO> pages = orderService.selectOrderPage(Condition.getPage(query.setDescs("create_time")), order);
return R.data(pages);
}
/**
* 新增
*/
@PostMapping("/save")
@ApiOperationSupport(order = 4)
@Operation(summary = "新增", description ="传入order")
public R save(@Valid @RequestBody Order order) {
return R.status(orderService.save(order));
}
/**
* 修改
*/
@PostMapping("/update")
@ApiOperationSupport(order = 5)
@Operation(summary = "修改", description ="传入order")
public R update(@Valid @RequestBody Order order) {
return R.status(orderService.updateById(order));
}
/**
* 新增或修改
*/
@PostMapping("/submit")
@ApiOperationSupport(order = 6)
@Operation(summary = "新增或修改", description ="传入order")
public R submit(@Valid @RequestBody Order order) {
return R.status(orderService.saveOrUpdate(order));
}
/**
* 删除
*/
@PostMapping("/remove")
@ApiOperationSupport(order = 8)
@Operation(summary = "删除", description ="传入ids")
public R remove(@Parameter(name = "主键集合", required = true) @RequestParam String ids) {
return R.status(orderService.removeByIds(Func.toLongList(ids)));
}
/**
* 检查订单状态
*
* @return
*/
@GetMapping("/checkOrderStatus")
public R checkOrderStatus(@RequestParam String orderNo) {
try {
Order order = orderService.getOrderInfoByOrderNoAndMchId(orderNo,null);
if (order == null) {
return R.data(false);
}
Integer status = order.getStatus();
if (1 != status.intValue()) {
return R.data(false);
}
} catch (Exception e) {
e.printStackTrace();
}
return R.data(true);
}
}

View File

@@ -0,0 +1,126 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.plugin.pay.constant.PayConstant;
import org.springblade.plugin.pay.entity.Refund;
import org.springblade.plugin.pay.service.IRefundService;
import org.springblade.plugin.pay.vo.RefundVO;
import org.springframework.web.bind.annotation.*;
/**
* 订单退款表 控制器
*
* @author BladeX
* @since 2022-01-03
*/
@RestController
@AllArgsConstructor
@RequestMapping(PayConstant.SERVICE_NAME + "/refund")
@Tag(name = "订单退款表", description = "订单退款表接口")
public class RefundController extends BladeController {
private final IRefundService refundService;
/**
* 详情
*/
@GetMapping("/detail")
@ApiOperationSupport(order = 1)
@Operation(summary = "详情", description ="传入refund")
public R<Refund> detail(Refund refund) {
Refund detail = refundService.getOne(Condition.getQueryWrapper(refund));
return R.data(detail);
}
/**
* 分页 订单退款表
*/
@GetMapping("/list")
@ApiOperationSupport(order = 2)
@Operation(summary = "分页", description ="传入refund")
public R<IPage<Refund>> list(Refund refund, Query query) {
IPage<Refund> pages = refundService.page(Condition.getPage(query.setDescs("create_time")), Condition.getQueryWrapper(refund));
return R.data(pages);
}
/**
* 自定义分页 订单退款表
*/
@GetMapping("/page")
@ApiOperationSupport(order = 3)
@Operation(summary = "分页", description ="传入refund")
public R<IPage<RefundVO>> page(RefundVO refund, Query query) {
IPage<RefundVO> pages = refundService.selectRefundPage(Condition.getPage(query), refund);
return R.data(pages);
}
/**
* 新增 订单退款表
*/
@PostMapping("/save")
@ApiOperationSupport(order = 4)
@Operation(summary = "新增", description ="传入refund")
public R save(@Valid @RequestBody Refund refund) {
return R.status(refundService.save(refund));
}
/**
* 修改 订单退款表
*/
@PostMapping("/update")
@ApiOperationSupport(order = 5)
@Operation(summary = "修改", description ="传入refund")
public R update(@Valid @RequestBody Refund refund) {
return R.status(refundService.updateById(refund));
}
/**
* 新增或修改 订单退款表
*/
@PostMapping("/submit")
@ApiOperationSupport(order = 6)
@Operation(summary = "新增或修改", description ="传入refund")
public R submit(@Valid @RequestBody Refund refund) {
return R.status(refundService.saveOrUpdate(refund));
}
/**
* 删除 订单退款表
*/
@PostMapping("/remove")
@ApiOperationSupport(order = 8)
@Operation(summary = "删除", description ="传入ids")
public R remove(@Parameter(name = "主键集合", required = true) @RequestParam String ids) {
return R.status(refundService.removeByIds(Func.toLongList(ids)));
}
}

View File

@@ -0,0 +1,201 @@
package org.springblade.plugin.pay.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.plugin.pay.constant.PayConstant;
import org.springblade.plugin.pay.entity.WxPayAccountConfig;
import org.springblade.plugin.pay.service.IWxPayAccountConfigService;
import org.springblade.plugin.pay.vo.WxPayAccountConfigVO;
import org.springframework.web.bind.annotation.*;
/**
* 控制器
*
* @author BladeX
* @since 2021-12-31
*/
@RestController
@AllArgsConstructor
@RequestMapping(PayConstant.SERVICE_NAME +"/wxconfig")
@Tag(name = "", description = "接口")
public class WxPayAccountConfigController extends BladeController {
private final IWxPayAccountConfigService wxpayAccountConfigService;
/**
* 详情
*/
@GetMapping("/detail")
@ApiOperationSupport(order = 1)
@Operation(summary ="详情", description ="传入wxpayAccountConfig")
public R<WxPayAccountConfig> detail(WxPayAccountConfig wxpayAccountConfig) {
WxPayAccountConfig detail = wxpayAccountConfigService.getOne(Condition.getQueryWrapper(wxpayAccountConfig));
return R.data(detail);
}
/**
* 分页
*/
@GetMapping("/list")
@ApiOperationSupport(order = 2)
@Operation(summary ="分页", description ="传入wxpayAccountConfig")
public R<IPage<WxPayAccountConfig>> list(WxPayAccountConfig wxpayAccountConfig, Query query) {
IPage<WxPayAccountConfig> pages = wxpayAccountConfigService.page(Condition.getPage(query.setDescs("create_time")), Condition.getQueryWrapper(wxpayAccountConfig));
return R.data(pages);
}
/**
* 自定义分页
*/
@GetMapping("/page")
@ApiOperationSupport(order = 3)
@Operation(summary ="分页", description ="传入wxpayAccountConfig")
public R<IPage<WxPayAccountConfigVO>> page(WxPayAccountConfigVO wxpayAccountConfig, Query query) {
IPage<WxPayAccountConfigVO> pages = wxpayAccountConfigService.selectWxpayAccountConfigPage(Condition.getPage(query.setDescs("create_time")), wxpayAccountConfig);
return R.data(pages);
}
/**
* 新增
*/
@PostMapping("/save")
@ApiOperationSupport(order = 4)
@Operation(summary ="新增", description ="传入wxpayAccountConfig")
public R save(@Valid @RequestBody WxPayAccountConfig wxpayAccountConfig) {
if (wxpayAccountConfig.getPrivateKey() != null) {
wxpayAccountConfig.setPrivateKey(null);
}
if (!StringUtil.isBlank(wxpayAccountConfig.getCertPem())) {
wxpayAccountConfig.setCertPem(null);
}
if (!StringUtil.isBlank(wxpayAccountConfig.getCertPkcs())) {
wxpayAccountConfig.setCertPkcs(null);
}
if (!StringUtil.isBlank(wxpayAccountConfig.getCertPubKey())) {
wxpayAccountConfig.setCertPubKey(null);
}
if (!StringUtil.isBlank(wxpayAccountConfig.getCertPrivateKey())) {
wxpayAccountConfig.setCertPrivateKey(null);
}
if (!StringUtil.isBlank(wxpayAccountConfig.getCertSerialNo())) {
wxpayAccountConfig.setCertSerialNo(null);
}
if (!StringUtil.isBlank(wxpayAccountConfig.getCertPlatSerialNo())) {
wxpayAccountConfig.setCertPlatSerialNo(null);
}
if (wxpayAccountConfig.getPrivateKey() != null) {
wxpayAccountConfig.setPrivateKey(null);
}
if (wxpayAccountConfig.getCertPkcsStream() != null) {
wxpayAccountConfig.setCertPkcsStream(null);
}
if (wxpayAccountConfig.getCertPubKeyStream() != null) {
wxpayAccountConfig.setCertPubKeyStream(null);
}
return R.status(wxpayAccountConfigService.save(wxpayAccountConfig));
}
/**
* 修改
*/
@PostMapping("/update")
@ApiOperationSupport(order = 5)
@Operation(summary ="修改", description ="传入wxpayAccountConfig")
public R update(@Valid @RequestBody WxPayAccountConfig wxpayAccountConfig) {
if (wxpayAccountConfig.getPrivateKey() != null) {
wxpayAccountConfig.setPrivateKey(null);
}
if (!StringUtil.isBlank(wxpayAccountConfig.getCertPem())) {
wxpayAccountConfig.setCertPem(null);
}
if (!StringUtil.isBlank(wxpayAccountConfig.getCertPkcs())) {
wxpayAccountConfig.setCertPkcs(null);
}
if (!StringUtil.isBlank(wxpayAccountConfig.getCertPubKey())) {
wxpayAccountConfig.setCertPubKey(null);
}
if (!StringUtil.isBlank(wxpayAccountConfig.getCertPrivateKey())) {
wxpayAccountConfig.setCertPrivateKey(null);
}
if (!StringUtil.isBlank(wxpayAccountConfig.getCertSerialNo())) {
wxpayAccountConfig.setCertSerialNo(null);
}
if (!StringUtil.isBlank(wxpayAccountConfig.getCertPlatSerialNo())) {
wxpayAccountConfig.setCertPlatSerialNo(null);
}
if (wxpayAccountConfig.getPrivateKey() != null) {
wxpayAccountConfig.setPrivateKey(null);
}
if (wxpayAccountConfig.getCertPkcsStream() != null) {
wxpayAccountConfig.setCertPkcsStream(null);
}
if (wxpayAccountConfig.getCertPubKeyStream() != null) {
wxpayAccountConfig.setCertPubKeyStream(null);
}
return R.status(wxpayAccountConfigService.updateById(wxpayAccountConfig));
}
/**
* 新增或修改
*/
@PostMapping("/submit")
@ApiOperationSupport(order = 6)
@Operation(summary ="新增或修改", description ="传入wxpayAccountConfig")
public R submit(@Valid @RequestBody WxPayAccountConfig wxpayAccountConfig) {
if (wxpayAccountConfig.getPrivateKey() != null) {
wxpayAccountConfig.setPrivateKey(null);
}
if (!StringUtil.isBlank(wxpayAccountConfig.getCertPem())) {
wxpayAccountConfig.setCertPem(null);
}
if (!StringUtil.isBlank(wxpayAccountConfig.getCertPkcs())) {
wxpayAccountConfig.setCertPkcs(null);
}
if (!StringUtil.isBlank(wxpayAccountConfig.getCertPubKey())) {
wxpayAccountConfig.setCertPubKey(null);
}
if (!StringUtil.isBlank(wxpayAccountConfig.getCertPrivateKey())) {
wxpayAccountConfig.setCertPrivateKey(null);
}
if (!StringUtil.isBlank(wxpayAccountConfig.getCertSerialNo())) {
wxpayAccountConfig.setCertSerialNo(null);
}
if (!StringUtil.isBlank(wxpayAccountConfig.getCertPlatSerialNo())) {
wxpayAccountConfig.setCertPlatSerialNo(null);
}
if (wxpayAccountConfig.getPrivateKey() != null) {
wxpayAccountConfig.setPrivateKey(null);
}
if (wxpayAccountConfig.getCertPkcsStream() != null) {
wxpayAccountConfig.setCertPkcsStream(null);
}
if (wxpayAccountConfig.getCertPubKeyStream() != null) {
wxpayAccountConfig.setCertPubKeyStream(null);
}
return R.status(wxpayAccountConfigService.saveOrUpdate(wxpayAccountConfig));
}
/**
* 删除
*/
@PostMapping("/remove")
@ApiOperationSupport(order = 8)
@Operation(summary ="删除", description ="传入ids")
public R remove(@Parameter(name ="主键集合", required = true) @RequestParam String ids) {
return R.status(wxpayAccountConfigService.removeByIds(Func.toLongList(ids)));
}
}

View File

@@ -0,0 +1,127 @@
package org.springblade.plugin.pay.controller;
import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R;
import org.springblade.plugin.pay.constant.PayConstant;
import org.springblade.plugin.pay.service.IWxPayService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
/**
* @author YunGouOS技术部-029
* @time 2022/1/1 17:57
*/
@RestController
@AllArgsConstructor
@RequestMapping(PayConstant.SERVICE_NAME + "/wxpay")
public class WxPayController {
private final IWxPayService wxPayService;
/**
* 微信扫码支付
*
* @param json
* @return
*/
@RequestMapping("/nativePay")
public R<Map<String, Object>> nativePay(@RequestBody JSONObject json) {
String appId = json.getString("appId");
String mchId = json.getString("mchId");
String body = json.getString("body");
String money = json.getString("money");
String notify = json.getString("notifyUrl");
String attach = json.getString("attach");
String orderPrefix = "S";
Map<String, Object> map = wxPayService.nativePay(appId, mchId, body, money, notify, attach, orderPrefix);
return R.data(map);
}
/**
* 微信jsapi支付
*
* @param json
* @return
*/
@RequestMapping("/jsPay")
public R<Map<String, String>> jsPay(@RequestBody JSONObject json) {
String appId = json.getString("appId");
String mchId = json.getString("mchId");
String openId = json.getString("openId");
String body = json.getString("body");
String money = json.getString("money");
String notify = json.getString("notifyUrl");
String attach = json.getString("attach");
String orderPrefix = "S";
Map<String, String> jsPay = wxPayService.jsPay(appId, mchId, openId, body, money, notify, attach , orderPrefix);
return R.data(jsPay);
}
/**
* 微信小程序支付
*
* @param json
* @return
*/
@RequestMapping("/wxAppPay")
public R<Map<String, String>> wxAppPay(@RequestBody JSONObject json) {
String appId = json.getString("appId");
String mchId = json.getString("mchId");
String openId = json.getString("openId");
String body = json.getString("body");
String money = json.getString("money");
String notify = json.getString("notifyUrl");
String attach = json.getString("attach");
String orderPrefix = "S";
Map<String, String> wxAppPay = wxPayService.wxApp(appId, mchId, openId, body, money, notify, attach , orderPrefix);
return R.data(wxAppPay);
}
/**
* 微信H5支付
*
* @param json
* @return
*/
@RequestMapping("/h5Pay")
public R<String> h5Pay(@RequestBody JSONObject json) {
String appId = json.getString("appId");
String mchId = json.getString("mchId");
String body = json.getString("body");
String money = json.getString("money");
String notify = json.getString("notifyUrl");
String returnUrl = json.getString("returnUrl");
String attach = json.getString("attach");
String orderPrefix = "S";
String url = wxPayService.h5Pay(appId, mchId, body, money, notify, returnUrl, attach , orderPrefix);
return R.data(url);
}
/**
* 微信APP支付
*
* @param json
* @return
*/
@RequestMapping("/appPay")
public R<Map<String, String>> appPay(@RequestBody JSONObject json) {
String appId = json.getString("appId");
String mchId = json.getString("mchId");
String body = json.getString("body");
String money = json.getString("money");
String notify = json.getString("notifyUrl");
String attach = json.getString("attach");
String orderPrefix = "S";
Long orderNo = System.currentTimeMillis();
Map<String, String> appPay = wxPayService.appPay(appId, mchId, body, money, notify, attach , orderPrefix , orderNo);
return R.data(appPay);
}
}

View File

@@ -0,0 +1,36 @@
package org.springblade.plugin.pay.dto;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springblade.modules.common.eums.BusinessModule;
import org.springblade.modules.common.eums.PaymentType;
import java.io.Serializable;
import java.math.BigDecimal;
@Data
@Accessors(chain = true)
public class APPPayDto implements Serializable {
private static final long serialVersionUID = 1L;
private PaymentType paymentType;
private BusinessModule businessModule;
private Long orderId;
private String body;
private String remark;
/**
* 现金金额
*/
private BigDecimal amount;
}

View File

@@ -0,0 +1,19 @@
package org.springblade.plugin.pay.dto;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springblade.modules.common.eums.BusinessModule;
import org.springblade.modules.common.eums.PaymentType;
import java.io.Serializable;
import java.math.BigDecimal;
@Data
@Accessors(chain = true)
public class APPQueryDto implements Serializable {
private String orderNo;
private PaymentType paymentType;
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.dto;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.plugin.pay.entity.AliPayAccountConfig;
/**
* 数据传输对象实体类
*
* @author BladeX
* @since 2021-12-31
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class AliPayAccountConfigDTO extends AliPayAccountConfig {
private static final long serialVersionUID = 1L;
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.dto;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.plugin.pay.entity.MergePayConfig;
/**
* 数据传输对象实体类
*
* @author BladeX
* @since 2022-06-27
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class MergePayConfigDTO extends MergePayConfig {
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.dto;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.plugin.pay.entity.Order;
/**
* 数据传输对象实体类
*
* @author BladeX
* @since 2021-12-31
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class OrderDTO extends Order {
private static final long serialVersionUID = 1L;
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.dto;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.plugin.pay.entity.Refund;
/**
* 订单退款表数据传输对象实体类
*
* @author BladeX
* @since 2022-01-03
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class RefundDTO extends Refund {
private static final long serialVersionUID = 1L;
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.dto;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.plugin.pay.entity.WxPayAccountConfig;
/**
* 数据传输对象实体类
*
* @author BladeX
* @since 2021-12-31
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class WxPayAccountConfigDTO extends WxPayAccountConfig {
private static final long serialVersionUID = 1L;
}

View File

@@ -0,0 +1,159 @@
package org.springblade.plugin.pay.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springblade.core.mp.base.BaseEntity;
/**
* 支付宝商户配置对象
*/
@Data
@TableName("blade_pay_alipay_account_config")
@Schema(description = "AlipayAccountConfig对象")
public class AliPayAccountConfig extends BaseEntity {
private Long id;
/**
* 商户号
*/
@Schema(description = "mch_id")
private String mchId;
/**
* 支付密钥
*/
@Schema(description = "pay_key")
private String payKey;
/**
* 支付宝应用id
*/
@Schema(description = "app_id")
private String appId;
/**
* 支付宝账户
*/
@Schema(description = "account")
private String account;
/**
* 支付宝公钥
*/
@Schema(description = "pub_key")
private String pubKey;
/**
* 支付宝私钥
*/
@Schema(description = "private_key")
private String privateKey;
/**
* 支付宝证书
*/
@Schema(description = "app_cert")
private String appCert;
/**
* 支付宝公钥证书
*/
@Schema(description = "alipay_pub_cert")
private String alipayPubCert;
/**
* 支付宝根证书
*/
@Schema(description = "root_cert")
private String rootCert;
/**
* 支付宝网关地址
*/
@Schema(description = "service_url")
private String serviceUrl;
/**
* 加密算法类型
*/
@Schema(description = "sign_type")
private String signType;
/**
* 收款名称
*/
@Schema(description = "pay_name")
private String payName;
/**
* 公司名称
*/
@Schema(description = "company_name")
private String companyName;
/**
* API类型【0:普通】
*/
@Schema(description = "API类型【0:普通】")
private Integer apiType;
/**
* 统一支付回调地址
*/
@Schema(description = "notify_url")
private String notifyUrl;
/**
* 统一退款回调地址
*/
@Schema(description = "refund_notify_url")
private String refundNotifyUrl;
/**
* 三方模式授权token
*/
@Schema(description = "app_auth_token")
private String appAuthToken;
/**
* 状态【0:关闭、1:启用】
*/
@Schema(description = "status")
private Integer status;
/**
* 备注
*/
@Schema(description = "备注")
private String remark;
/**
* 接口交互证书临时路径(privateKeyUrl)
*/
@TableField(exist = false)
private String privateKeyUrl;
/**
* 接口交互证书临时路径(支付宝根证书)
*/
@TableField(exist = false)
private String aliPayRootCertUrl;
/**
* 接口交互证书临时路径(应用公钥证书)
*/
@TableField(exist = false)
private String appCertUrl;
/**
* 接口交互证书临时路径(支付宝公钥证书)
*/
@TableField(exist = false)
private String aliPayPubCertUrl;
}

View File

@@ -0,0 +1,72 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springblade.core.mp.base.BaseEntity;
/**
* 实体类
*
* @author BladeX
* @since 2022-06-27
*/
@Data
@TableName("blade_pay_merge_pay_config")
@Schema(description = "MergePayConfig对象")
public class MergePayConfig extends BaseEntity {
private Long id;
/**
* 商户号
*/
@Schema(description = "商户号")
private String mchId;
/**
* 支付密钥
*/
@Schema(description = "支付密钥")
private String payKey;
/**
* 统一支付回调地址
*/
@Schema(description = "统一支付回调地址")
private String notifyUrl;
/**
* 退款回调地址
*/
@Schema(description = "退款回调地址")
private String refundNotifyUrl;
/**
* 状态【0:关闭、1:启用】
*/
@Schema(description = "状态【0:关闭、1:启用】")
private Integer status;
/**
* 备注
*/
@Schema(description = "备注")
private String remark;
}

View File

@@ -0,0 +1,123 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springblade.core.mp.base.BaseEntity;
/**
* 实体类
*
* @author BladeX
* @since 2021-12-31
*/
@Data
@TableName("blade_pay_order")
@Schema(description = "Order对象")
public class Order extends BaseEntity{
private static final long serialVersionUID = 1L;
private Long id;
/**
* 系统单号
*/
@Schema(description = "系统单号")
private String orderNo;
/**
* 商品名称
*/
@Schema(description = "商品名称")
private String body;
/**
* 支付金额
*/
@Schema(description = "支付金额")
private String money;
/**
* 应用ID
*/
@Schema(description = "应用ID")
private String appId;
/**
* 商户号
*/
@Schema(description = "商户号")
private String mchId;
/**
* 收款名称
*/
@Schema(description = "收款名称")
private String payName;
/**
* 支付方式【code、native、jsapi、wxapp、h5、app】
*/
@Schema(description = "支付方式【code、native、jsapi、wxapp、h5、app】")
private String payType;
/**
* 支付渠道【wxpay、alipay】
*/
@Schema(description = "支付渠道【wxpay、alipay】")
private String channel;
/**
* 买家ID
*/
@Schema(description = "买家ID")
private String buyerId;
/**
* 0:未支付、1:已支付
*/
@Schema(description = "0:未支付、1:已支付")
private Integer status;
/**
* 第三方支付单号
*/
@Schema(description = "第三方支付单号")
private String payNo;
/**
* 支付时间
*/
@Schema(description = "支付时间")
private String payTime;
/**
* 是否退款【0:否、1:是】
*/
@Schema(description = "是否退款【0:否、1:是】")
private Integer isRefund;
/**
* 已退款金额
*/
@Schema(description = "已退款金额")
private String refundMoney;
/**
* 异步回调地址
*/
@Schema(description = "异步回调地址")
private String notifyUrl;
/**
* 备注
*/
@Schema(description = "备注")
private String remark;
}

View File

@@ -0,0 +1,83 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springblade.core.mp.base.BaseEntity;
/**
* 订单退款表实体类
*
* @author BladeX
* @since 2022-01-03
*/
@Data
@TableName("blade_pay_order_refund")
@Schema(description = "订单退款表")
public class Refund extends BaseEntity {
private Long id;
/**
* 退款单号
*/
@Schema(description = "退款单号")
private String refundNo;
/**
* 业务订单
*/
@Schema(description = "业务订单")
private String orderNo;
/**
* 支付单号
*/
@Schema(description = "支付单号")
private String payNo;
/**
* 退款商户
*/
@Schema(description = "退款商户")
private String refundMchId;
/**
* 退款金额
*/
@Schema(description = "退款金额")
private String refundMoney;
/**
* 退款原因
*/
@Schema(description = "退款原因")
private String refundDesc;
/**
* 退款状态 -1:退款失败 0:已发起 1:退款成功
*/
@Schema(description = "退款状态 -1:退款失败 0:已发起 1:退款成功")
private Integer status;
/**
* 退款回调地址
*/
@Schema(description = "退款回调地址 ")
private String notifyUrl;
/**
* 备注
*/
@Schema(description = "备注")
private String remark;
}

View File

@@ -0,0 +1,231 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.entity;
import cn.hutool.core.codec.Base64;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.ijpay.core.kit.RsaKit;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.apache.commons.lang.StringUtils;
import org.springblade.core.mp.base.BaseEntity;
import java.io.ByteArrayInputStream;
import java.security.PrivateKey;
/**
* 实体类
*
* @author BladeX
* @since 2021-12-31
*/
@Data
@TableName("blade_pay_wxpay_account_config")
@Schema(description = "WxPayAccountConfig对象")
public class WxPayAccountConfig extends BaseEntity {
private Long id;
/**
* 商户号
*/
@Schema(description = "商户号")
private String mchId;
/**
* 支付密钥
*/
@Schema(description = "支付密钥")
private String payKey;
/**
* 收款名称
*/
@Schema(description = "收款名称")
private String payName;
/**
* V3密钥
*/
@Schema(description = "V3密钥")
private String v3Key;
/**
* API类型【0:普通】
*/
@Schema(description = "API类型【0:普通】")
private Integer apiType;
/**
* 统一支付回调地址
*/
@Schema(description = "统一支付回调地址")
private String notifyUrl;
/**
* 统一退款回调
*/
@Schema(description = "统一退款回调")
private String refundNotifyUrl;
/**
* 聚合收银台URL
*/
@Schema(description = "聚合收银台URL")
private String cashierUrl;
/**
* 微信证书pem文件
*/
@Schema(description = "微信证书pem文件")
private String certPem;
/**
* 微信正式p12文件
*/
@Schema(description = "微信正式p12文件")
private String certPkcs;
/**
* 微信证书公钥
*/
@Schema(description = "微信证书公钥")
private String certPubKey;
/**
* 微信证书私钥
*/
@Schema(description = "微信证书私钥")
private String certPrivateKey;
/**
* 商户 API 证书序列号
*/
@Schema(description = "商户 API 证书序列号")
private String certSerialNo;
/**
* 平台序列号
*/
@Schema(description = "平台序列号")
private String certPlatSerialNo;
/**
* 微信支付公钥
*/
@Schema(description = "微信支付公钥")
private String wxPubKey;
/**
* 微信支付公钥ID
*/
@Schema(description = "微信支付公钥ID")
private String wxPubKeyId;
/**
* 状态【0:关闭、1:启用】
*/
@Schema(description = "状态【0:关闭、1:启用】")
private Integer status;
/**
* 备注
*/
@Schema(description = "备注")
private String remark;
/**
* 微信私钥
*/
@JsonIgnore
@TableField(exist = false)
private PrivateKey privateKey;
/**
* P12 流
*/
@JsonIgnore
@TableField(exist = false)
private ByteArrayInputStream certPkcsStream;
/**
* 公钥流
*/
@JsonIgnore
@TableField(exist = false)
private ByteArrayInputStream certPubKeyStream;
/**
* 接口交互证书临时路径
*/
@TableField(exist = false)
private String wxPayCertFile;
/**
* 接口交互证书临时路径
*/
@TableField(exist = false)
private String wxPayPkCsFile;
/**
* 接口交互证书临时路径
*/
@TableField(exist = false)
private String wxPayPrivateKeyFile;
/**
* 接口交互微信公钥证书临时路径
*/
@TableField(exist = false)
private String wxPubKeyFile;
public PrivateKey getPrivateKey() {
if (!StringUtils.isBlank(certPrivateKey)) {
try {
String privateKeyStr = certPrivateKey.replace("-----BEGIN PRIVATE KEY-----", "").replace("-----END PRIVATE KEY-----", "").replaceAll("\\s+", "");
privateKey = RsaKit.loadPrivateKey(privateKeyStr);
} catch (Exception e) {
e.printStackTrace();
System.err.println("微信私钥证书格式错误");
}
}
return privateKey;
}
public ByteArrayInputStream getCertPkcsStream() {
if (!StringUtils.isBlank(certPkcs)) {
try {
byte[] decode = Base64.decode(certPkcs);
ByteArrayInputStream stream = new ByteArrayInputStream(decode);
certPkcsStream = stream;
} catch (Exception e) {
e.printStackTrace();
System.err.println("微信p12证书格式错误");
}
}
return certPkcsStream;
}
public ByteArrayInputStream getCertPubKeyStream() {
if (!StringUtils.isBlank(certPubKey)) {
try {
ByteArrayInputStream stream = new ByteArrayInputStream(certPubKey.getBytes());
certPubKeyStream = stream;
} catch (Exception e) {
e.printStackTrace();
System.err.println("微信公钥证书格式错误");
}
}
return certPubKeyStream;
}
}

View File

@@ -0,0 +1,27 @@
package org.springblade.plugin.pay.entityBiz;
import lombok.Data;
import java.io.Serializable;
/**
* 支付宝支付对象
*
* @author YunGouOS技术部-029
* @time 2022/4/28 15:19
*/
@Data
public class AliPayBiz implements Serializable {
//本系统内订单号
private String orderNo;
//支付宝系统订单号
private String payNo;
//支付金额
private String money;
//支付时间
private String payTime;
}

View File

@@ -0,0 +1,21 @@
package org.springblade.plugin.pay.entityBiz;
import lombok.Data;
import org.springblade.plugin.pay.entity.AliPayAccountConfig;
import org.springblade.plugin.pay.entity.Order;
import java.io.Serializable;
/**
* 支付宝API前置对象
*/
@Data
public class AliPayCheckBiz implements Serializable {
//订单对象
private Order order;
//支付宝商户配置对象
private AliPayAccountConfig aliPayAccountConfig;
}

View File

@@ -0,0 +1,33 @@
package org.springblade.plugin.pay.entityBiz;
import lombok.Data;
import java.io.Serializable;
@Data
public class AliPayPageApiBiz implements Serializable{
private static final long serialVersionUID = 6665081013047347001L;
private String form;
private String url;
public String getForm() {
return form;
}
public void setForm(String form) {
this.form = form;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}

View File

@@ -0,0 +1,24 @@
package org.springblade.plugin.pay.entityBiz;
import lombok.Data;
import org.springblade.plugin.pay.entity.MergePayConfig;
import org.springblade.plugin.pay.entity.Order;
import java.io.Serializable;
/**
* 聚合支付验证对象
*
* @author YunGouOS技术部-029
* @time 2022/6/28 18:04
*/
@Data
public class MergePayCheckBiz implements Serializable {
//订单对象
private Order order;
//支付宝商户配置对象
private MergePayConfig mergePayConfig;
}

View File

@@ -0,0 +1,24 @@
package org.springblade.plugin.pay.entityBiz;
import lombok.Data;
import org.springblade.plugin.pay.entity.Order;
import org.springblade.plugin.pay.entity.WxPayAccountConfig;
import java.io.Serializable;
/**
* 微信支付API前置对象
*
* @author YunGouOS技术部-029
* @time 2022/1/3 12:13
*/
@Data
public class WxPayCheckBiz implements Serializable {
//订单对象
private Order order;
//微信商户配置对象
private WxPayAccountConfig wxPayAccountConfig;
}

View File

@@ -0,0 +1,26 @@
package org.springblade.plugin.pay.entityBiz;
import lombok.Data;
import java.io.Serializable;
/**
* 微信支付退款对象
* 文档:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_9.shtml
*
* @author YunGouOS技术部-029
* @time 2022/1/3 14:10
*/
@Data
public class WxPayRefundBiz implements Serializable {
private String refund_id;
private String out_refund_no;
private String transaction_id;
private String out_trade_no;
private String channel;
private String user_received_account;
private String success_time;
private String create_time;
private String status;
private String funds_account;
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.plugin.pay.entity.AliPayAccountConfig;
import org.springblade.plugin.pay.vo.AliPayAccountConfigVO;
import java.util.List;
/**
* Mapper 接口
*
* @author BladeX
* @since 2021-12-31
*/
public interface AliPayAccountConfigMapper extends BaseMapper<AliPayAccountConfig> {
/**
* 自定义分页
*
* @param page
* @param aliPayAccountConfig
* @return
*/
List<AliPayAccountConfigVO> selectAliPayAccountConfigPage(IPage page, AliPayAccountConfigVO aliPayAccountConfig);
}

View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.springblade.plugin.pay.mapper.AliPayAccountConfigMapper">
<!-- 通用查询映射结果 -->
<resultMap id="aliPayAccountConfigResultMap" type="org.springblade.plugin.pay.entity.AliPayAccountConfig">
<result column="id" property="id"/>
<result column="mch_id" property="mchId"/>
<result column="app_id" property="appId"/>
<result column="account" property="account"/>
<result column="pub_key" property="pubKey"/>
<result column="private_key" property="privateKey"/>
<result column="app_cert" property="appCert"/>
<result column="alipay_pub_cert" property="alipayPubCert"/>
<result column="root_cert" property="rootCert"/>
<result column="app_auth_token" property="appAuthToken"/>
<result column="service_url" property="serviceUrl"/>
<result column="sign_type" property="signType"/>
<result column="pay_name" property="payName"/>
<result column="company_name" property="companyName"/>
<result column="api_type" property="apiType"/>
<result column="notify_url" property="notifyUrl"/>
<result column="refund_notify_url" property="refundNotifyUrl"/>
<result column="status" property="status"/>
<result column="create_user" property="createUser"/>
<result column="create_dept" property="createDept"/>
<result column="create_time" property="createTime"/>
<result column="update_user" property="updateUser"/>
<result column="update_time" property="updateTime"/>
<result column="is_deleted" property="isDeleted"/>
<result column="remark" property="remark"/>
</resultMap>
<select id="selectAliPayAccountConfigPage" resultMap="aliPayAccountConfigResultMap">
select *
from blade_pay_alipay_account_config
where is_deleted = 0
</select>
</mapper>

View File

@@ -0,0 +1,43 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.plugin.pay.entity.MergePayConfig;
import org.springblade.plugin.pay.vo.MergePayConfigVO;
import java.util.List;
/**
* Mapper 接口
*
* @author BladeX
* @since 2022-06-27
*/
public interface MergePayConfigMapper extends BaseMapper<MergePayConfig> {
/**
* 自定义分页
*
* @param page
* @param mergePayConfig
* @return
*/
List<MergePayConfigVO> selectMergePayConfigPage(IPage page, MergePayConfigVO mergePayConfig);
}

View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.springblade.plugin.pay.mapper.MergePayConfigMapper">
<!-- 通用查询映射结果 -->
<resultMap id="mergePayConfigResultMap" type="org.springblade.plugin.pay.entity.MergePayConfig">
<id column="id" property="id"/>
<result column="mch_id" property="mchId"/>
<result column="pay_key" property="payKey"/>
<result column="type" property="type"/>
<result column="extend_config" property="extendConfig"/>
<result column="notify_url" property="notifyUrl"/>
<result column="refund_notify_url" property="refundNotifyUrl"/>
<result column="status" property="status"/>
<result column="create_user" property="createUser"/>
<result column="create_dept" property="createDept"/>
<result column="create_time" property="createTime"/>
<result column="update_user" property="updateUser"/>
<result column="update_time" property="updateTime"/>
<result column="is_deleted" property="isDeleted"/>
<result column="remark" property="remark"/>
</resultMap>
<select id="selectMergePayConfigPage" resultMap="mergePayConfigResultMap">
select * from blade_pay_merge_pay_config where is_deleted = 0
</select>
</mapper>

View File

@@ -0,0 +1,43 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.plugin.pay.entity.Order;
import org.springblade.plugin.pay.vo.OrderVO;
import java.util.List;
/**
* Mapper 接口
*
* @author BladeX
* @since 2021-12-31
*/
public interface OrderMapper extends BaseMapper<Order> {
/**
* 自定义分页
*
* @param page
* @param order
* @return
*/
List<OrderVO> selectOrderPage(IPage page, OrderVO order);
}

View File

@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.springblade.plugin.pay.mapper.OrderMapper">
<!-- 通用查询映射结果 -->
<resultMap id="orderResultMap" type="org.springblade.plugin.pay.entity.Order">
<result column="id" property="id"/>
<result column="order_no" property="orderNo"/>
<result column="body" property="body"/>
<result column="money" property="money"/>
<result column="app_id" property="appId"/>
<result column="mch_id" property="mchId"/>
<result column="pay_name" property="payName"/>
<result column="pay_type" property="payType"/>
<result column="channel" property="channel"/>
<result column="buyer_id" property="buyerId"/>
<result column="status" property="status"/>
<result column="pay_no" property="payNo"/>
<result column="pay_time" property="payTime"/>
<result column="is_refund" property="isRefund"/>
<result column="refund_money" property="refundMoney"/>
<result column="notify_url" property="notifyUrl"/>
<result column="create_user" property="createUser"/>
<result column="create_dept" property="createDept"/>
<result column="create_time" property="createTime"/>
<result column="update_user" property="updateUser"/>
<result column="update_time" property="updateTime"/>
<result column="is_deleted" property="isDeleted"/>
<result column="remark" property="remark"/>
</resultMap>
<select id="selectOrderPage" resultMap="orderResultMap">
select * from blade_pay_order where is_deleted = 0
</select>
</mapper>

View File

@@ -0,0 +1,43 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.plugin.pay.entity.Refund;
import org.springblade.plugin.pay.vo.RefundVO;
import java.util.List;
/**
* 订单退款表 Mapper 接口
*
* @author BladeX
* @since 2022-01-03
*/
public interface RefundMapper extends BaseMapper<Refund> {
/**
* 自定义分页
*
* @param page
* @param refund
* @return
*/
List<RefundVO> selectRefundPage(IPage page, RefundVO refund);
}

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.springblade.plugin.pay.mapper.RefundMapper">
<!-- 通用查询映射结果 -->
<resultMap id="refundResultMap" type="org.springblade.plugin.pay.entity.Refund">
<result column="id" property="id"/>
<result column="refund_no" property="refundNo"/>
<result column="order_no" property="orderNo"/>
<result column="pay_no" property="payNo"/>
<result column="refund_mch_id" property="refundMchId"/>
<result column="refund_money" property="refundMoney"/>
<result column="refund_desc" property="refundDesc"/>
<result column="refund_status" property="status"/>
<result column="notify_url" property="notifyUrl"/>
<result column="create_user" property="createUser"/>
<result column="create_dept" property="createDept"/>
<result column="create_time" property="createTime"/>
<result column="update_user" property="updateUser"/>
<result column="update_time" property="updateTime"/>
<result column="is_deleted" property="isDeleted"/>
<result column="remark" property="remark"/>
</resultMap>
<select id="selectRefundPage" resultMap="refundResultMap">
select * from blade_pay_order_refund where is_deleted = 0
</select>
</mapper>

View File

@@ -0,0 +1,43 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.plugin.pay.entity.WxPayAccountConfig;
import org.springblade.plugin.pay.vo.WxPayAccountConfigVO;
import java.util.List;
/**
* Mapper 接口
*
* @author BladeX
* @since 2021-12-31
*/
public interface WxPayAccountConfigMapper extends BaseMapper<WxPayAccountConfig> {
/**
* 自定义分页
*
* @param page
* @param wxpayAccountConfig
* @return
*/
List<WxPayAccountConfigVO> selectWxpayAccountConfigPage(IPage page, WxPayAccountConfigVO wxpayAccountConfig);
}

View File

@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.springblade.plugin.pay.mapper.WxPayAccountConfigMapper">
<!-- 通用查询映射结果 -->
<resultMap id="wxpayAccountConfigResultMap" type="org.springblade.plugin.pay.entity.WxPayAccountConfig">
<result column="id" property="id"/>
<result column="mch_id" property="mchId"/>
<result column="pay_key" property="payKey"/>
<result column="pay_name" property="payName"/>
<result column="v3_key" property="v3Key"/>
<result column="api_type" property="apiType"/>
<result column="notify_url" property="notifyUrl"/>
<result column="refund_notify_url" property="refundNotifyUrl"/>
<result column="cashier_url" property="cashierUrl"/>
<result column="cert_pem" property="certPem"/>
<result column="cert_pkcs" property="certPkcs"/>
<result column="cert_pub_key" property="certPubKey"/>
<result column="cert_private_key" property="certPrivateKey"/>
<result column="cert_serial_no" property="certSerialNo"/>
<result column="cert_plat_serial_no" property="certPlatSerialNo"/>
<result column="status" property="status"/>
<result column="create_user" property="createUser"/>
<result column="create_dept" property="createDept"/>
<result column="create_time" property="createTime"/>
<result column="update_user" property="updateUser"/>
<result column="update_time" property="updateTime"/>
<result column="is_deleted" property="isDeleted"/>
<result column="remark" property="remark"/>
</resultMap>
<select id="selectWxpayAccountConfigPage" resultMap="wxpayAccountConfigResultMap">
select * from blade_pay_wxpay_account_config where is_deleted = 0
</select>
</mapper>

View File

@@ -0,0 +1,21 @@
package org.springblade.plugin.pay.response;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springblade.core.tool.utils.StringPool;
import org.springblade.modules.common.eums.PaymentType;
import java.io.Serializable;
@Data
@Accessors(chain = true)
public class APPPayResult implements Serializable {
private Boolean success = false;
private String content = StringPool.EMPTY;
PaymentType paymentTypeEnum;
}

View File

@@ -0,0 +1,67 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseService;
import org.springblade.plugin.pay.entity.AliPayAccountConfig;
import org.springblade.plugin.pay.vo.AliPayAccountConfigVO;
/**
* 支付宝商户管理服务类
*/
public interface IAliPayAccountConfigService extends BaseService<AliPayAccountConfig> {
/**
* 自定义分页
*
* @param page
* @param aliPayAccountConfig
* @return
*/
IPage<AliPayAccountConfigVO> selectAliPayAccountConfigPage(IPage<AliPayAccountConfigVO> page, AliPayAccountConfigVO aliPayAccountConfig);
/**
* 支付宝商戶接入
*
* @param aliPayAccountConfig
* @return
*/
public boolean save(AliPayAccountConfig aliPayAccountConfig);
/**
* 修改接入信息
*
* @param aliPayAccountConfig
* @return
*/
public boolean updateById(AliPayAccountConfig aliPayAccountConfig);
public boolean saveOrUpdate(AliPayAccountConfig aliPayAccountConfig);
/**
* 根据商户和、appid 查询支付宝配置
*
* @param mchId
* @param appId
* @return
*/
public AliPayAccountConfig getInfoByMchIdAndAppId(String mchId, String appId);
}

View File

@@ -0,0 +1,118 @@
package org.springblade.plugin.pay.service;
import com.alipay.api.response.AlipayTradeRefundResponse;
import org.springblade.plugin.pay.entityBiz.AliPayBiz;
import org.springblade.plugin.pay.entityBiz.AliPayPageApiBiz;
import java.util.Map;
/**
* @author YunGouOS技术部-029
* @time 2022/4/28 16:02
*/
public interface IAliPayService {
/**
* 付款码支付
*
* @param appId
* @param mchId
* @param body
* @param money
* @param notifyUrl
* @param authCode
* @param attach
* @return
*/
public boolean codePay(String appId, String mchId, String body, String money, String notifyUrl, String authCode, String attach , String orderPrefix);
/**
* 支付宝扫码支付
*
* @param appId
* @param mchId
* @param body
* @param money
* @param notifyUrl
* @param attach
* @return
*/
public Map<String, Object> nativePay(String appId, String mchId, String body, String money, String notifyUrl, String attach , String orderPrefix);
/**
* 支付宝js支付,适合支付宝小程序使用
*
* @param appId
* @param mchId
* @param buyerId
* @param body
* @param money
* @param notifyUrl
* @param attach
* @return
*/
public AliPayBiz jsPay(String appId, String mchId, String buyerId, String body, String money, String notifyUrl, String attach , String orderPrefix);
/**
* 支付宝H5支付
*
* @param appId
* @param mchId
* @param body
* @param money
* @param notifyUrl
* @param returnUrl
* @param attach
* @return
*/
public AliPayPageApiBiz h5Pay(String appId, String mchId, String body, String money, String notifyUrl, String returnUrl, String attach , String orderPrefix);
/**
* 支付宝PC网站支付
*
* @param appId
* @param mchId
* @param body
* @param money
* @param notifyUrl
* @param returnUrl
* @param attach
* @return
*/
public AliPayPageApiBiz pcPay(String appId, String mchId, String body, String money, String notifyUrl, String returnUrl, String attach , String orderPrefix);
/**
* 支付宝APP支付
*
* @param appId
* @param mchId
* @param body
* @param money
* @param notifyUrl
* @param attach
* @return
*/
public String appPay(String appId, String mchId, String body, String money, String notifyUrl, String attach ,String orderPrefix, Long orderId);
/**
* 订单退款
* @param appId
* @param orderNo
* @param mchId
* @param refundMoney
* @param reason
* @param notifyUrl
* @return
*/
public AlipayTradeRefundResponse refund(String appId,String orderNo, String mchId, String refundMoney, String reason, String notifyUrl);
Boolean query(String orderNo , String appId, String mchId);
Boolean closeOrder(String orderNo , String appId, String mchId);
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import org.springblade.plugin.pay.entity.MergePayConfig;
import org.springblade.plugin.pay.vo.MergePayConfigVO;
/**
* 服务类
*
* @author BladeX
* @since 2022-06-27
*/
public interface IMergePayConfigService extends IService<MergePayConfig> {
/**
* 自定义分页
*
* @param page
* @param mergePayConfig
* @return
*/
IPage<MergePayConfigVO> selectMergePayConfigPage(IPage<MergePayConfigVO> page, MergePayConfigVO mergePayConfig);
/**
* 根据商户号查询聚合支付配置
*
* @param mchId
* @return
*/
public MergePayConfig getInfoByMchId(String mchId);
}

View File

@@ -0,0 +1,39 @@
package org.springblade.plugin.pay.service;
import java.util.Map;
/**
* 聚合支付接口
*
* @author YunGouOS技术部-029
* @time 2022/6/28 15:26
*/
public interface IMergePayService {
/**
* 聚合一码付
*
* @param mchId
* @param body
* @param money
* @param notifyUrl
* @param returnUrl
* @param attach
* @return
*/
public Map<String, Object> nativePay(String mchId, String body, String money, String notifyUrl, String returnUrl, String attach, String configNo, String auto, String autoNode,String orderPrefix);
/**
* 聚合手机支付
*
* @param mchId
* @param body
* @param money
* @param notifyUrl
* @param returnUrl
* @param attach
* @return
*/
public Map<String, Object> mobilePay(String mchId, String body, String money, String notifyUrl, String returnUrl, String attach, String configNo, String auto, String autoNode,String orderPrefix);
}

View File

@@ -0,0 +1,100 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseService;
import org.springblade.plugin.pay.entity.Order;
import org.springblade.plugin.pay.vo.OrderVO;
/**
* 服务类
*
* @author BladeX
* @since 2021-12-31
*/
public interface IOrderService extends BaseService<Order> {
/**
* 自定义分页
*
* @param page
* @param order
* @return
*/
IPage<OrderVO> selectOrderPage(IPage<OrderVO> page, OrderVO order);
/**
* 保存订单
*
* @param mchId
* @param body
* @param money
* @param chanel
* @param payType
* @param notifyUrl
* @return
*/
public Order save(String appId, String mchId, String payName, String body, String money, String chanel, String payType, String notifyUrl , String orderPrefix);
/**
* 根据订单号、商户号查询支付订单
*
* @author YunGouOS
*/
public Order getOrderInfoByOrderNoAndMchId(String orderNo, String mchId);
/**
* 根据订单号、APPID查询支付订单
*
* @param orderNo
* @param appId
* @return
*/
public Order getOrderInfoByOrderNoAndAppId(String orderNo, String appId);
/**
* 订单支付成功
*
* @param orderNo
* @return
*/
public boolean paySuccess(String orderNo, String mchId, String payNo, String payTime, String buyerId);
/**
* 订单支付成功,聚合支付
*
* @param orderNo
* @param mchId
* @param payNo
* @param payTime
* @param buyerId
* @return
*/
public boolean paySuccessMerge(String orderNo, String appId, String mchId, String payNo, String payTime, String buyerId);
/**
* 订单退款成功
*
* @param orderNo
* @param mchId
* @param refundMoney
* @return
*/
public boolean refundSuccess(String orderNo, String mchId, String refundMoney);
}

View File

@@ -0,0 +1,57 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseService;
import org.springblade.plugin.pay.entity.Refund;
import org.springblade.plugin.pay.vo.RefundVO;
/**
* 订单退款表 服务类
*
* @author BladeX
* @since 2022-01-03
*/
public interface IRefundService extends BaseService<Refund> {
/**
* 自定义分页
*
* @param page
* @param refund
* @return
*/
IPage<RefundVO> selectRefundPage(IPage<RefundVO> page, RefundVO refund);
/**
* 退款完成
* @param refundNo
* @param mchId
* @return
*/
public boolean refundSuccess(String refundNo,String mchId);
/**
* 根据退款编号、商户号查询退款详情
* @param refundNo
* @param mchId
* @return
*/
public Refund getInfoByRefundNoAndMchId(String refundNo,String mchId);
}

View File

@@ -0,0 +1,68 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseService;
import org.springblade.plugin.pay.entity.WxPayAccountConfig;
import org.springblade.plugin.pay.vo.WxPayAccountConfigVO;
/**
* 服务类
*
* @author BladeX
* @since 2021-12-31
*/
public interface IWxPayAccountConfigService extends BaseService<WxPayAccountConfig> {
/**
* 自定义分页
*
* @param page
* @param wxpayAccountConfig
* @return
*/
IPage<WxPayAccountConfigVO> selectWxpayAccountConfigPage(IPage<WxPayAccountConfigVO> page, WxPayAccountConfigVO wxpayAccountConfig);
/**
* 微信商戶接入
*
* @param wxPayAccountConfig
* @return
*/
public boolean save(WxPayAccountConfig wxPayAccountConfig);
/**
* 修改接入信息
* @param wxPayAccountConfig
* @return
*/
public boolean updateById(WxPayAccountConfig wxPayAccountConfig);
public boolean saveOrUpdate(WxPayAccountConfig wxPayAccountConfig);
/**
* 根据商户号查询配置
*
* @param mchId
* @return
*/
public WxPayAccountConfig getInfoByMchId(String mchId);
}

View File

@@ -0,0 +1,107 @@
package org.springblade.plugin.pay.service;
import com.alibaba.fastjson.JSONObject;
import org.springblade.plugin.pay.entityBiz.WxPayRefundBiz;
import java.util.Map;
/**
* 微信支付业务接口
*
* @author YunGouOS技术部-029
* @time 2022/1/1 16:56
*/
public interface IWxPayService {
/**
* 微信扫码支付
*
* @param appId 公众号/小程序的APPID
* @param mchId 微信支付商户号
* @param body 商品名称
* @param money 支付金额 单位:元
* @param notifyUrl 异步通知地址
* @return
*/
public Map<String, Object> nativePay(String appId, String mchId, String body, String money, String notifyUrl, String attach, String orderPrefix);
/**
* 微信jsapi支付,适合微信内的H5网页发起,返回微信jssdk支付api所需的参数
*
* @param appId
* @param mchId
* @param openId
* @param body
* @param money
* @param notifyUrl
* @param attach
*/
public Map<String, String> jsPay(String appId, String mchId, String openId, String body, String money, String notifyUrl, String attach, String orderPrefix);
/**
* 微信小程序支付,返回小程序支付API所需的参数
*
* @param appId
* @param mchId
* @param openId
* @param body
* @param money
* @param notifyUrl
* @param attach
* @return
*/
public Map<String, String> wxApp(String appId, String mchId, String openId, String body, String money, String notifyUrl, String attach, String orderPrefix);
/**
* 微信H5支付 返回H5支付链接,前端重定向到该地址即可
*
* @param appId
* @param mchId
* @param body
* @param money
* @param notifyUrl
* @param returnUrl
* @param attach
* @return
*/
public String h5Pay(String appId, String mchId,String body, String money, String notifyUrl, String returnUrl, String attach, String orderPrefix);
/**
* 微信APP支付,返回APP支付所需的参数
*
* @param appId
* @param mchId
* @param body
* @param money
* @param notifyUrl
* @param attach
* @return
*/
public Map<String, String> appPay(String appId, String mchId,String body, String money, String notifyUrl, String attach, String orderPrefix , Long orderId);
/**
* 订单退款
*
* @param orderNo
* @param refundMoney
* @param reason
* @param notifyUrl
* @return
*/
public WxPayRefundBiz refund(String orderNo, String mchId ,String refundMoney, String reason, String notifyUrl);
/**
* 查询微信订单详情
*
* @param orderNo
* @param payNo
* @param mchId
*/
public JSONObject getOrderInfo(String orderNo, String payNo, String mchId);
}

View File

@@ -0,0 +1,161 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.service.impl;
import com.alipay.api.internal.util.AntCertificationUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.plugin.pay.api.wxpay.IWxPayApiService;
import org.springblade.plugin.pay.entity.AliPayAccountConfig;
import org.springblade.plugin.pay.mapper.AliPayAccountConfigMapper;
import org.springblade.plugin.pay.service.IAliPayAccountConfigService;
import org.springblade.plugin.pay.util.FileUtil;
import org.springblade.plugin.pay.vo.AliPayAccountConfigVO;
import org.springframework.stereotype.Service;
/**
* 服务实现类
*
* @author BladeX
* @since 2021-12-31
*/
@Service
@AllArgsConstructor
public class AliPayAccountConfigServiceImpl extends BaseServiceImpl<AliPayAccountConfigMapper, AliPayAccountConfig> implements IAliPayAccountConfigService {
private final IWxPayApiService wxPayApiService;
@Override
public IPage<AliPayAccountConfigVO> selectAliPayAccountConfigPage(IPage<AliPayAccountConfigVO> page, AliPayAccountConfigVO AliPayAccountConfig) {
return page.setRecords(baseMapper.selectAliPayAccountConfigPage(page, AliPayAccountConfig));
}
@Override
public boolean save(AliPayAccountConfig aliPayAccountConfig) {
try {
//处理一些默认值
if (aliPayAccountConfig.getApiType() == null) {
aliPayAccountConfig.setApiType(0);
}
if (aliPayAccountConfig.getStatus() == null) {
aliPayAccountConfig.setStatus(1);
}
aliPayAccountConfig.setSignType("RSA2");
aliPayAccountConfig = doCertParams(aliPayAccountConfig);
return super.save(aliPayAccountConfig);
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
}
@Override
public boolean updateById(AliPayAccountConfig aliPayAccountConfig) {
try {
aliPayAccountConfig = doCertParams(aliPayAccountConfig);
return super.updateById(aliPayAccountConfig);
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
}
@Override
public boolean saveOrUpdate(AliPayAccountConfig aliPayAccountConfig) {
try {
aliPayAccountConfig = doCertParams(aliPayAccountConfig);
return super.saveOrUpdate(aliPayAccountConfig);
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
}
/**
* 处理支付宝证书参数
*
* @return
*/
private AliPayAccountConfig doCertParams(AliPayAccountConfig aliPayAccountConfig) {
try {
aliPayAccountConfig.setServiceUrl("https://openapi.alipay.com/gateway.do");
aliPayAccountConfig.setSignType("RSA2");
String aliPayPubCertUrl = aliPayAccountConfig.getAliPayPubCertUrl();
if (!StringUtil.isBlank(aliPayPubCertUrl)) {
String aliPayPubCertPath = FileUtil.downloadFile(aliPayPubCertUrl);
String publicKey = AntCertificationUtil.getAlipayPublicKey(aliPayPubCertPath);
//支付宝公钥
aliPayAccountConfig.setPubKey(publicKey);
String aliPayPubCertStr = cn.hutool.core.io.FileUtil.readString(aliPayPubCertPath, "utf-8");
//支付宝公钥证书
aliPayAccountConfig.setAlipayPubCert(aliPayPubCertStr);
cn.hutool.core.io.FileUtil.del(aliPayPubCertPath);
}
String privateKeyUrl = aliPayAccountConfig.getPrivateKeyUrl();
if (!StringUtil.isBlank(privateKeyUrl)) {
String privateKeyPath = FileUtil.downloadFile(privateKeyUrl);
String privateKeyStr = cn.hutool.core.io.FileUtil.readString(privateKeyPath, "utf-8");
aliPayAccountConfig.setPrivateKey(privateKeyStr);
cn.hutool.core.io.FileUtil.del(privateKeyPath);
}
//支付宝根证书
String aliPayRootCertUrl = aliPayAccountConfig.getAliPayRootCertUrl();
if (!StringUtil.isBlank(aliPayRootCertUrl)) {
String aliPayRootCertPath = FileUtil.downloadFile(aliPayRootCertUrl);
String aliPayRootCertStr = cn.hutool.core.io.FileUtil.readString(aliPayRootCertPath, "utf-8");
aliPayAccountConfig.setRootCert(aliPayRootCertStr);
cn.hutool.core.io.FileUtil.del(aliPayRootCertPath);
}
//应用证书
String appCertUrl = aliPayAccountConfig.getAppCertUrl();
if (!StringUtil.isBlank(appCertUrl)) {
String appCertPath = FileUtil.downloadFile(appCertUrl);
String appCertStr = cn.hutool.core.io.FileUtil.readString(appCertPath, "utf-8");
aliPayAccountConfig.setAppCert(appCertStr);
cn.hutool.core.io.FileUtil.del(appCertPath);
}
return aliPayAccountConfig;
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
}
@Override
public AliPayAccountConfig getInfoByMchIdAndAppId(String mchId, String appId) {
AliPayAccountConfig aliPayAccountConfig = null;
try {
AliPayAccountConfig aliPayAccountConfigWhere = new AliPayAccountConfig();
aliPayAccountConfigWhere.setMchId(mchId);
if (!StringUtil.isBlank(appId)) {
aliPayAccountConfigWhere.setAppId(appId);
}
aliPayAccountConfig = super.getOne(Condition.getQueryWrapper(aliPayAccountConfigWhere));
} catch (Exception e) {
e.printStackTrace();
}
return aliPayAccountConfig;
}
}

View File

@@ -0,0 +1,474 @@
package org.springblade.plugin.pay.service.impl;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.extra.qrcode.QrCodeUtil;
import com.alipay.api.response.AlipayTradeCloseResponse;
import com.alipay.api.response.AlipayTradeQueryResponse;
import com.alipay.api.response.AlipayTradeRefundResponse;
import com.yungouos.pay.alipay.AliPay;
import com.yungouos.pay.common.PayException;
import com.yungouos.pay.entity.AliPayH5Biz;
import com.yungouos.pay.entity.AliPayJsPayBiz;
import com.yungouos.pay.entity.RefundOrder;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.oss.model.BladeFile;
import org.springblade.core.tool.utils.PathUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.modules.common.eums.OrderStatus;
import org.springblade.modules.common.eums.PaymentStatus;
import org.springblade.modules.common.eums.PaymentType;
import org.springblade.modules.common.pojo.entity.CommonPayOrderEntity;
import org.springblade.modules.common.service.ICommonPayOrderService;
import org.springblade.modules.resource.builder.OssBuilder;
import org.springblade.plugin.pay.api.alipay.IAliPayApiService;
import org.springblade.plugin.pay.common.AliPayException;
import org.springblade.plugin.pay.constant.PayConstant;
import org.springblade.plugin.pay.entity.AliPayAccountConfig;
import org.springblade.plugin.pay.entity.Order;
import org.springblade.plugin.pay.entity.Refund;
import org.springblade.plugin.pay.entityBiz.AliPayBiz;
import org.springblade.plugin.pay.entityBiz.AliPayCheckBiz;
import org.springblade.plugin.pay.entityBiz.AliPayPageApiBiz;
import org.springblade.plugin.pay.service.IAliPayAccountConfigService;
import org.springblade.plugin.pay.service.IAliPayService;
import org.springblade.plugin.pay.service.IOrderService;
import org.springblade.plugin.pay.service.IRefundService;
import org.springblade.plugin.pay.util.OrderUtil;
import org.springframework.stereotype.Service;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
/**
* 支付宝支付业务接口实现
*
* @author YunGouOS技术部-029
* @time 2022/4/28 16:02
*/
@Slf4j
@Service
@AllArgsConstructor
public class AliPayServiceImpl implements IAliPayService {
private final IOrderService orderService;
private final IAliPayApiService aliPayApiService;
private final IAliPayAccountConfigService aliPayAccountConfigService;
private final OssBuilder ossBuilder;
private final IRefundService refundService;
private final ICommonPayOrderService commonPayOrderService;
/**
* 订单前置验证
*
* @return
*/
private AliPayCheckBiz beforeCheck(String appId, String mchId, String body, String money, String notifyUrl, String payType , String orderPrefix) {
AliPayAccountConfig aliPayAccountConfig = aliPayAccountConfigService.getInfoByMchIdAndAppId(mchId, appId);
if (aliPayAccountConfig == null) {
throw new ServiceException("该商户号尚未接入");
}
if (aliPayAccountConfig.getStatus().intValue() != 1) {
throw new ServiceException("该商户号已暂停交易");
}
if (StringUtil.isBlank(notifyUrl)) {
notifyUrl = aliPayAccountConfig.getNotifyUrl();
}
Order order = orderService.save(appId, mchId, aliPayAccountConfig.getPayName(), body, money, PayConstant.ALIPAY, payType, notifyUrl , orderPrefix);
if (order == null) {
throw new ServiceException("下单失败,请稍候再试");
}
AliPayCheckBiz aliPayCheckBiz = new AliPayCheckBiz();
aliPayCheckBiz.setOrder(order);
aliPayCheckBiz.setAliPayAccountConfig(aliPayAccountConfig);
return aliPayCheckBiz;
}
@Override
public boolean codePay(String appId, String mchId, String body, String money, String notifyUrl, String authCode, String attach, String orderPrefix) {
Map<String, Object> map = new HashMap<String, Object>();
try {
AliPayCheckBiz aliPayCheckBiz = beforeCheck(appId, mchId, body, money, notifyUrl,PayConstant.CODEPAY , orderPrefix);
Order order = aliPayCheckBiz.getOrder();
AliPayAccountConfig aliPayAccountConfig = aliPayCheckBiz.getAliPayAccountConfig();
AliPayBiz aliPayBiz = null;
Integer apiType = aliPayAccountConfig.getApiType();
switch (apiType) {
case 0:
//支付宝官方接口
aliPayBiz = aliPayApiService.codePay(order, aliPayAccountConfig, authCode, attach);
break;
default:
throw new ServiceException("该渠道暂不支持");
}
if (!StringUtil.isBlank(aliPayBiz.getPayNo())) {
return true;
}
} catch (AliPayException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
return false;
}
@Override
public Map<String, Object> nativePay(String appId, String mchId, String body, String money, String notifyUrl, String attach , String orderPrefix) {
Map<String, Object> map = new HashMap<String, Object>();
try {
AliPayCheckBiz aliPayCheckBiz = beforeCheck(appId, mchId, body, money, notifyUrl,PayConstant.NATIVEPAY , orderPrefix);
Order order = aliPayCheckBiz.getOrder();
AliPayAccountConfig aliPayAccountConfig = aliPayCheckBiz.getAliPayAccountConfig();
String codeUrl = null;
Integer apiType = aliPayAccountConfig.getApiType();
switch (apiType) {
case 0:
//支付宝官方接口
codeUrl = aliPayApiService.nativePay(order, aliPayAccountConfig, attach);
break;
case 1:
//YunGouOS服务商平台接口,文档:https://open.pay.yungouos.com/#/api/api/pay/alipay/nativePay
codeUrl = AliPay.nativePay(order.getOrderNo(), order.getMoney(), order.getMchId(), body, "1", attach, order.getNotifyUrl(), null, null, null, null,null,null, aliPayAccountConfig.getPayKey());
break;
default:
throw new ServiceException("该渠道暂不支持");
}
String path = PathUtil.getJarPath() + File.separator + order.getOrderNo() + ".png";
File file = QrCodeUtil.generate(codeUrl, 240, 240, FileUtil.file(path));
file = new File(path);
BufferedInputStream inputStream = FileUtil.getInputStream(file);
BladeFile bladeFile = ossBuilder.template().putFile(order.getOrderNo() + ".png", inputStream);
map.put("url", bladeFile.getLink());
map.put("order", order);
inputStream.close();
FileUtil.del(path);
} catch (PayException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (AliPayException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
return map;
}
@Override
public AliPayBiz jsPay(String appId, String mchId, String buyerId, String body, String money, String notifyUrl, String attach , String orderPrefix) {
AliPayBiz aliPayBiz = null;
try {
AliPayCheckBiz aliPayCheckBiz = beforeCheck(appId, mchId, body, money, notifyUrl,PayConstant.JSPAY , orderPrefix);
Order order = aliPayCheckBiz.getOrder();
order.setBuyerId(buyerId);
AliPayAccountConfig aliPayAccountConfig = aliPayCheckBiz.getAliPayAccountConfig();
Integer apiType = aliPayAccountConfig.getApiType();
switch (apiType) {
case 0:
//支付宝官方接口
aliPayBiz = aliPayApiService.jsPay(order, aliPayAccountConfig, attach);
break;
case 1:
//YunGouOS服务商平台接口,文档:https://open.pay.yungouos.com/#/api/api/pay/alipay/jsPay
AliPayJsPayBiz aliPayJsPayBiz = AliPay.jsPay(order.getOrderNo(), order.getMoney(), order.getMchId(), buyerId, body, attach, order.getNotifyUrl(), null, null, null, null,null,null, aliPayAccountConfig.getPayKey());
//转换成支付宝同一对象
aliPayBiz = new AliPayBiz();
aliPayBiz.setOrderNo(aliPayJsPayBiz.getOrderNo());
aliPayBiz.setPayNo(aliPayJsPayBiz.getPayNo());
aliPayBiz.setMoney(order.getMoney());
aliPayBiz.setPayTime(null);
break;
default:
throw new ServiceException("该渠道暂不支持");
}
} catch (PayException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (AliPayException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
return aliPayBiz;
}
@Override
public AliPayPageApiBiz h5Pay(String appId, String mchId, String body, String money, String notifyUrl, String returnUrl, String attach , String orderPrefix) {
AliPayPageApiBiz aliPayPageApiBiz = null;
try {
AliPayCheckBiz aliPayCheckBiz = beforeCheck(appId, mchId,body, money, notifyUrl,PayConstant.H5PAY , orderPrefix);
Order order = aliPayCheckBiz.getOrder();
AliPayAccountConfig aliPayAccountConfig = aliPayCheckBiz.getAliPayAccountConfig();
Integer apiType = aliPayAccountConfig.getApiType();
String wapPayStr = null;
switch (apiType) {
case 0:
//支付宝官方接口
wapPayStr = aliPayApiService.mobilePay(order, aliPayAccountConfig, attach, returnUrl);
break;
case 1:
//YunGouOS服务商平台接口,文档:https://open.pay.yungouos.com/#/api/api/pay/alipay/mobilePay
AliPayH5Biz aliPayH5Biz = AliPay.h5Pay(order.getOrderNo(), order.getMoney(), order.getMchId(), body, attach, order.getNotifyUrl(), returnUrl, null, null, null, null,null,null, aliPayAccountConfig.getPayKey());
wapPayStr = aliPayH5Biz.getForm();
break;
default:
throw new ServiceException("该渠道暂不支持");
}
aliPayPageApiBiz = new AliPayPageApiBiz();
aliPayPageApiBiz.setForm(wapPayStr);
// 以下代码是将支付宝返回的form字符串生成html文件并上传到oss上,这样前端可以直接通过oss的地址实现直接url跳转支付。
//如果你系统没有开启oss,可以注释掉以下代码,获取wapPayStr字段后,自己前端做跳转处理。
StringBuffer sb = new StringBuffer();
sb.append("<!DOCTYPE html>");
sb.append("\n");
sb.append("<html>");
sb.append("\n");
sb.append("<head>");
sb.append("\n");
sb.append("<meta charset=\"utf-8\">");
sb.append("\n");
sb.append("<title>支付宝</title>");
sb.append("\n");
sb.append("</head>");
sb.append("\n");
sb.append("<body>");
sb.append("\n");
sb.append(wapPayStr);
sb.append("\n");
sb.append("</body>");
sb.append("\n");
sb.append("</html>");
InputStream inputStream = new ByteArrayInputStream(sb.toString().getBytes());
BladeFile bladeFile = ossBuilder.template().putFile(order.getOrderNo() + ".html", inputStream);
aliPayPageApiBiz.setUrl(bladeFile.getLink());
} catch (PayException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (AliPayException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
return aliPayPageApiBiz;
}
@Override
public AliPayPageApiBiz pcPay(String appId, String mchId, String body, String money, String notifyUrl, String returnUrl, String attach , String orderPrefix) {
AliPayPageApiBiz aliPayPageApiBiz = null;
try {
AliPayCheckBiz aliPayCheckBiz = beforeCheck(appId, mchId , body, money, notifyUrl,PayConstant.PCPAY , orderPrefix);
Order order = aliPayCheckBiz.getOrder();
AliPayAccountConfig aliPayAccountConfig = aliPayCheckBiz.getAliPayAccountConfig();
Integer apiType = aliPayAccountConfig.getApiType();
String webPayStr = null;
switch (apiType) {
case 0:
//支付宝官方接口
webPayStr = aliPayApiService.webPay(order, aliPayAccountConfig, attach, returnUrl);
break;
default:
throw new ServiceException("该渠道暂不支持");
}
aliPayPageApiBiz = new AliPayPageApiBiz();
aliPayPageApiBiz.setForm(webPayStr);
// 以下代码是将支付宝返回的form字符串生成html文件并上传到oss上,这样前端可以直接通过oss的地址实现直接url跳转支付。
//如果你系统没有开启oss,可以注释掉以下代码,获取wapPayStr字段后,自己前端做跳转处理。
StringBuffer sb = new StringBuffer();
sb.append("<!DOCTYPE html>");
sb.append("\n");
sb.append("<html>");
sb.append("\n");
sb.append("<head>");
sb.append("\n");
sb.append("<meta charset=\"utf-8\">");
sb.append("\n");
sb.append("<title>支付宝</title>");
sb.append("\n");
sb.append("</head>");
sb.append("\n");
sb.append("<body>");
sb.append("\n");
sb.append(webPayStr);
sb.append("\n");
sb.append("</body>");
sb.append("\n");
sb.append("</html>");
InputStream inputStream = new ByteArrayInputStream(sb.toString().getBytes());
BladeFile bladeFile = ossBuilder.template().putFile(order.getOrderNo() + ".html", inputStream);
aliPayPageApiBiz.setUrl(bladeFile.getLink());
} catch (AliPayException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
return aliPayPageApiBiz;
}
@Override
public String appPay(String appId, String mchId, String body, String money, String notifyUrl, String attach ,String orderPrefix , Long orderId) {
String appPayStr = null;
try {
AliPayCheckBiz aliPayCheckBiz = beforeCheck(appId, mchId, body, money, notifyUrl,PayConstant.APPPAY , orderPrefix);
Order order = aliPayCheckBiz.getOrder();
CommonPayOrderEntity commonPayOrderEntity = new CommonPayOrderEntity();
commonPayOrderEntity.setId(order.getId());
commonPayOrderEntity.setOrderId(orderId);
commonPayOrderEntity.setStatus(OrderStatus.PENDING_PAYMENT.getCode());
commonPayOrderEntity.setPaymentStatus(PaymentStatus.UNPAID.getCode());
commonPayOrderEntity.setOrderNo(order.getOrderNo());
commonPayOrderEntity.setPaymentType(PaymentType.ALI.getCode());
commonPayOrderService.save(commonPayOrderEntity);
AliPayAccountConfig aliPayAccountConfig = aliPayCheckBiz.getAliPayAccountConfig();
Integer apiType = aliPayAccountConfig.getApiType();
switch (apiType) {
case 0:
//支付宝官方接口
appPayStr = aliPayApiService.appPay(order, aliPayAccountConfig, attach);
break;
case 1:
//YunGouOS服务商平台接口,文档:https://open.pay.yungouos.com/#/api/api/pay/alipay/appPay
appPayStr = AliPay.appPay(order.getOrderNo(), order.getMoney(), order.getMchId(), body, attach, order.getNotifyUrl(), null, null, null, null,null,null, aliPayAccountConfig.getPayKey());
break;
default:
throw new ServiceException("该渠道暂不支持");
}
} catch (PayException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (AliPayException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
return appPayStr;
}
@Override
public AlipayTradeRefundResponse refund(String appId, String orderNo, String mchId, String refundMoney, String reason, String notifyUrl) {
AlipayTradeRefundResponse refundResponse = null;
try {
Order order = orderService.getOrderInfoByOrderNoAndMchId(orderNo, mchId);
if (order == null) {
throw new ServiceException("订单不存在");
}
if (order.getStatus().intValue() != 1) {
throw new ServiceException("订单尚未支付");
}
if (order.getIsRefund().intValue() == 1 && NumberUtil.isGreaterOrEqual(new BigDecimal(order.getRefundMoney()), new BigDecimal(order.getMoney()))) {
throw new ServiceException("订单已全额退款");
}
AliPayAccountConfig aliPayAccountConfig = aliPayAccountConfigService.getInfoByMchIdAndAppId(mchId, appId);
if (aliPayAccountConfig == null) {
throw new ServiceException("商户未接入");
}
Refund refund = new Refund();
refund.setRefundNo(OrderUtil.createOrderNo("R"));
refund.setOrderNo(order.getOrderNo());
refund.setPayNo(order.getPayNo());
refund.setRefundMchId(order.getMchId());
refund.setRefundDesc(reason);
refund.setRefundMoney(refundMoney);
refund.setStatus(0);
if (StringUtil.isBlank(notifyUrl)) {
notifyUrl = aliPayAccountConfig.getRefundNotifyUrl();
}
refund.setNotifyUrl(notifyUrl);
boolean save = refundService.save(refund);
if (!save) {
throw new ServiceException("退款发起失败");
}
Integer apiType = aliPayAccountConfig.getApiType();
switch (apiType) {
case 0:
//支付宝官方接口
refundResponse = aliPayApiService.refund(refund, aliPayAccountConfig);
break;
case 1:
//YunGouOS服务商平台接口,文档:https://open.pay.yungouos.com/#/api/api/pay/alipay/refundOrder
RefundOrder refundOrder = AliPay.orderRefund(refund.getOrderNo(), refund.getRefundMchId(), refund.getRefundMoney(), refund.getRefundNo(), refund.getRefundDesc(), refund.getNotifyUrl(), aliPayAccountConfig.getPayKey());
//转换为支付宝退款对象
refundResponse = new AlipayTradeRefundResponse();
refundResponse.setTradeNo(refundOrder.getPayNo());
refundResponse.setOutTradeNo(refundOrder.getOrderNo());
//本次退款金额
refundResponse.setRefundFee(refundOrder.getRefundMoney());
refundResponse.setStoreName(refundOrder.getRefundPayName());
break;
default:
throw new ServiceException("该渠道暂不支持");
}
} catch (PayException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (AliPayException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
return refundResponse;
}
@Override
public Boolean query(String orderNo , String appId, String mchId) {
AliPayAccountConfig aliPayAccountConfig = aliPayAccountConfigService.getInfoByMchIdAndAppId(mchId, appId);
if (aliPayAccountConfig == null) {
throw new ServiceException("商户未接入");
}
AlipayTradeQueryResponse response = null;
try {
response = aliPayApiService.query(orderNo, aliPayAccountConfig);
log.info("支付宝账单:[{}]的支付结果为:{}", orderNo, response.getBody());
return response.getTradeStatus().equalsIgnoreCase("TRADE_SUCCESS")
|| response.getTradeStatus().equalsIgnoreCase("TRADE_FINISHED");
} catch (Exception e) {
log.error("查询订单异常:{}", e.getMessage());
return false;
}
}
@Override
public Boolean closeOrder(String orderNo, String appId, String mchId) {
AliPayAccountConfig aliPayAccountConfig = aliPayAccountConfigService.getInfoByMchIdAndAppId(mchId, appId);
if (aliPayAccountConfig == null) {
throw new ServiceException("商户未接入");
}
AlipayTradeCloseResponse response = null;
try {
response = aliPayApiService.closeOrder(orderNo, aliPayAccountConfig);
log.info("支付宝账单:[{}]的支付结果为:{}", orderNo, response.getBody());
return response.getMsg().equalsIgnoreCase("SUCCESS")
|| response.getCode().equalsIgnoreCase("10000");
} catch (Exception e) {
log.error("查询订单异常:{}", e.getMessage());
return false;
}
}
}

View File

@@ -0,0 +1,55 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.core.mp.support.Condition;
import org.springblade.plugin.pay.entity.MergePayConfig;
import org.springblade.plugin.pay.mapper.MergePayConfigMapper;
import org.springblade.plugin.pay.service.IMergePayConfigService;
import org.springblade.plugin.pay.vo.MergePayConfigVO;
import org.springframework.stereotype.Service;
/**
* 服务实现类
*
* @author BladeX
* @since 2022-06-27
*/
@Service
public class MergePayConfigServiceImpl extends ServiceImpl<MergePayConfigMapper, MergePayConfig> implements IMergePayConfigService {
@Override
public IPage<MergePayConfigVO> selectMergePayConfigPage(IPage<MergePayConfigVO> page, MergePayConfigVO mergePayConfig) {
return page.setRecords(baseMapper.selectMergePayConfigPage(page, mergePayConfig));
}
@Override
public MergePayConfig getInfoByMchId(String mchId) {
MergePayConfig mergePayConfig = null;
try {
MergePayConfig mergePayConfigWhere = new MergePayConfig();
mergePayConfigWhere.setMchId(mchId);
mergePayConfig = super.getOne(Condition.getQueryWrapper(mergePayConfigWhere));
} catch (Exception e) {
e.printStackTrace();
}
return mergePayConfig;
}
}

View File

@@ -0,0 +1,113 @@
package org.springblade.plugin.pay.service.impl;
import cn.hutool.core.io.FileUtil;
import cn.hutool.extra.qrcode.QrCodeUtil;
import com.yungouos.pay.common.PayException;
import lombok.AllArgsConstructor;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.oss.model.BladeFile;
import org.springblade.core.tool.utils.PathUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.modules.resource.builder.OssBuilder;
import org.springblade.plugin.pay.api.yungouos.IMergePayApiService;
import org.springblade.plugin.pay.constant.PayConstant;
import org.springblade.plugin.pay.entity.MergePayConfig;
import org.springblade.plugin.pay.entity.Order;
import org.springblade.plugin.pay.entityBiz.MergePayCheckBiz;
import org.springblade.plugin.pay.service.IMergePayConfigService;
import org.springblade.plugin.pay.service.IMergePayService;
import org.springblade.plugin.pay.service.IOrderService;
import org.springblade.plugin.pay.service.IRefundService;
import org.springframework.stereotype.Service;
import java.io.BufferedInputStream;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
/**
* @author YunGouOS技术部-029
* @time 2022/6/28 15:27
*/
@Service
@AllArgsConstructor
public class MergePayServiceImpl implements IMergePayService {
private final IOrderService orderService;
private final IMergePayApiService mergePayApiService;
private final IMergePayConfigService mergePayConfigService;
private final OssBuilder ossBuilder;
private final IRefundService refundService;
/**
* 订单前置验证
*
* @return
*/
private MergePayCheckBiz beforeCheck(String mchId, String body, String money, String notifyUrl ,String orderPrefix) {
MergePayConfig mergePayConfig = mergePayConfigService.getInfoByMchId(mchId);
if (mergePayConfig == null) {
throw new ServiceException("该商户号尚未接入");
}
if (StringUtil.isBlank(notifyUrl)) {
notifyUrl = mergePayConfig.getNotifyUrl();
}
Order order = orderService.save(mchId, mchId, "聚合商户号:" + mchId ,body, money, PayConstant.MERGE, PayConstant.NATIVEPAY, notifyUrl , orderPrefix);
if (order == null) {
throw new ServiceException("下单失败,请稍候再试");
}
MergePayCheckBiz mergePayCheckBiz = new MergePayCheckBiz();
mergePayCheckBiz.setOrder(order);
mergePayCheckBiz.setMergePayConfig(mergePayConfig);
return mergePayCheckBiz;
}
@Override
public Map<String, Object> nativePay(String mchId, String body, String money, String notifyUrl, String returnUrl, String attach, String configNo, String auto, String autoNode,String orderPrefix) {
Map<String, Object> map = new HashMap<String, Object>();
try {
MergePayCheckBiz mergePayCheckBiz = beforeCheck(mchId, body, money, notifyUrl , orderPrefix);
Order order = mergePayCheckBiz.getOrder();
MergePayConfig mergePayConfig = mergePayCheckBiz.getMergePayConfig();
String codeUrl = mergePayApiService.nativePay(order, mergePayConfig, "1", attach, returnUrl, configNo, auto, autoNode);
String path = PathUtil.getJarPath() + File.separator + order.getOrderNo() + ".png";
File file = QrCodeUtil.generate(codeUrl, 240, 240, FileUtil.file(path));
file = new File(path);
BufferedInputStream inputStream = FileUtil.getInputStream(file);
BladeFile bladeFile = ossBuilder.template().putFile(order.getOrderNo() + ".png", inputStream);
map.put("url", bladeFile.getLink());
map.put("order", order);
inputStream.close();
FileUtil.del(path);
} catch (PayException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
return map;
}
@Override
public Map<String, Object> mobilePay(String mchId, String body, String money, String notifyUrl, String returnUrl, String attach, String configNo, String auto, String autoNode,String orderPrefix) {
Map<String, Object> map = new HashMap<String, Object>();
try {
MergePayCheckBiz mergePayCheckBiz = beforeCheck(mchId, body, money, notifyUrl,orderPrefix);
Order order = mergePayCheckBiz.getOrder();
MergePayConfig mergePayConfig = mergePayCheckBiz.getMergePayConfig();
String codeUrl = mergePayApiService.nativePay(order, mergePayConfig, "1", attach, returnUrl, configNo, auto, autoNode);
map.put("url", codeUrl);
map.put("order", order);
} catch (PayException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
return map;
}
}

View File

@@ -0,0 +1,175 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.service.impl;
import cn.hutool.core.util.NumberUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.AllArgsConstructor;
import org.springblade.common.utils.date.DateUtil;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.modules.common.event.PaymentCallbackEvent;
import org.springblade.plugin.pay.constant.PayConstant;
import org.springblade.plugin.pay.entity.Order;
import org.springblade.plugin.pay.mapper.OrderMapper;
import org.springblade.plugin.pay.service.IOrderService;
import org.springblade.plugin.pay.util.OrderUtil;
import org.springblade.plugin.pay.vo.OrderVO;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
/**
* 服务实现类
*
* @author BladeX
* @since 2021-12-31
*/
@Service
@AllArgsConstructor
public class OrderServiceImpl extends BaseServiceImpl<OrderMapper, Order> implements IOrderService {
private final ApplicationEventPublisher publisher;
@Override
public IPage<OrderVO> selectOrderPage(IPage<OrderVO> page, OrderVO order) {
return page.setRecords(baseMapper.selectOrderPage(page, order));
}
@Override
public Order save(String appId, String mchId, String payName, String body, String money, String chanel, String payType, String notifyUrl ,String orderPrefix) {
Order order = null;
try {
order = new Order();
order.setOrderNo(OrderUtil.createOrderNo(orderPrefix));
order.setBody(body);
order.setMoney(money);
order.setMchId(mchId);
order.setAppId(appId);
order.setPayName(payName);
order.setPayType(payType);
order.setChannel(chanel);
order.setNotifyUrl(notifyUrl);
order.setStatus(0);
order.setIsRefund(0);
order.setRefundMoney("0");
boolean save = super.save(order);
if (!save) {
throw new ServiceException("订单保存失败");
}
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
return order;
}
@Override
public Order getOrderInfoByOrderNoAndMchId(String orderNo, String mchId) {
Order order = null;
try {
Order orderWhere = new Order();
orderWhere.setOrderNo(orderNo);
if (!StringUtil.isBlank(mchId)) {
orderWhere.setMchId(mchId);
}
order = super.getOne(Condition.getQueryWrapper(orderWhere));
} catch (Exception e) {
e.printStackTrace();
}
return order;
}
@Override
public Order getOrderInfoByOrderNoAndAppId(String orderNo, String appId) {
Order order = null;
try {
Order orderWhere = new Order();
orderWhere.setOrderNo(orderNo);
if (!StringUtil.isBlank(appId)) {
orderWhere.setAppId(appId);
}
order = super.getOne(Condition.getQueryWrapper(orderWhere));
} catch (Exception e) {
e.printStackTrace();
}
return order;
}
@Override
public boolean paySuccess(String orderNo, String mchId, String payNo, String payTime, String buyerId) {
Order order = getOrderInfoByOrderNoAndMchId(orderNo, mchId);
if (order == null) {
throw new ServiceException("订单不存在");
}
if (order.getStatus() == 1) {
return true;
}
boolean update = super.update(
Wrappers.<Order>update().lambda()
.set(Order::getStatus, 1)
.set(Order::getPayTime, payTime)
.set(Order::getPayNo, payNo)
.set(Order::getBuyerId, buyerId)
.eq(Order::getOrderNo, orderNo)
.eq(Order::getMchId, mchId));
if (update){
publisher.publishEvent(new PaymentCallbackEvent().setId(order.getId()).setPayTime(DateUtil.convertFromString(payTime , "yyyy-MM-dd hh:mm:ss")));
}
return update;
}
@Override
public boolean paySuccessMerge(String orderNo, String appId, String mchId, String payNo, String payTime, String buyerId) {
Order order = getOrderInfoByOrderNoAndAppId(orderNo, appId);
if (order == null) {
throw new ServiceException("订单不存在");
}
if (order.getStatus() == 1) {
return true;
}
boolean update = super.update(
Wrappers.<Order>update().lambda()
.set(Order::getStatus, 1)
.set(Order::getPayTime, payTime)
.set(Order::getPayNo, payNo)
.set(Order::getBuyerId, buyerId)
.set(Order::getMchId, mchId)
.eq(Order::getOrderNo, orderNo)
.eq(Order::getAppId, appId));
return update;
}
@Override
public boolean refundSuccess(String orderNo, String mchId, String refundMoney) {
Order order = getOrderInfoByOrderNoAndMchId(orderNo, mchId);
if (order == null) {
throw new ServiceException("订单不存在");
}
boolean update = super.update(
Wrappers.<Order>update().lambda()
.set(Order::getIsRefund, 1)
.set(Order::getRefundMoney, NumberUtil.add(order.getRefundMoney(), refundMoney))
.eq(Order::getOrderNo, orderNo)
.eq(Order::getMchId, mchId));
return update;
}
}

View File

@@ -0,0 +1,84 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.AllArgsConstructor;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.mp.support.Condition;
import org.springblade.plugin.pay.entity.Refund;
import org.springblade.plugin.pay.mapper.RefundMapper;
import org.springblade.plugin.pay.service.IOrderService;
import org.springblade.plugin.pay.service.IRefundService;
import org.springblade.plugin.pay.vo.RefundVO;
import org.springframework.stereotype.Service;
/**
* 订单退款表 服务实现类
*
* @author BladeX
* @since 2022-01-03
*/
@Service
@AllArgsConstructor
public class RefundServiceImpl extends BaseServiceImpl<RefundMapper, Refund> implements IRefundService {
private final IOrderService orderService;
@Override
public IPage<RefundVO> selectRefundPage(IPage<RefundVO> page, RefundVO refund) {
return page.setRecords(baseMapper.selectRefundPage(page, refund));
}
@Override
public boolean refundSuccess(String refundNo, String mchId) {
Refund refund = getInfoByRefundNoAndMchId(refundNo, mchId);
if (refund == null) {
throw new ServiceException("退款记录不存在");
}
if (refund.getStatus() == 1) {
return true;
}
boolean update = super.update(
Wrappers.<Refund>update().lambda()
.set(Refund::getStatus, 1)
.eq(Refund::getRefundNo, refundNo)
.eq(Refund::getRefundMchId, mchId));
if (update) {
orderService.refundSuccess(refund.getOrderNo(), refund.getRefundMchId(), refund.getRefundMoney());
}
return update;
}
@Override
public Refund getInfoByRefundNoAndMchId(String refundNo, String mchId) {
Refund refund = null;
try {
Refund refundWhere = new Refund();
refundWhere.setRefundNo(refundNo);
refundWhere.setRefundMchId(mchId);
refund = super.getOne(Condition.getQueryWrapper(refundWhere));
} catch (Exception e) {
e.printStackTrace();
}
return refund;
}
}

View File

@@ -0,0 +1,177 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ijpay.core.kit.PayKit;
import lombok.AllArgsConstructor;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.plugin.pay.api.wxpay.IWxPayApiService;
import org.springblade.plugin.pay.entity.WxPayAccountConfig;
import org.springblade.plugin.pay.mapper.WxPayAccountConfigMapper;
import org.springblade.plugin.pay.service.IWxPayAccountConfigService;
import org.springblade.plugin.pay.util.FileUtil;
import org.springblade.plugin.pay.util.WxPayInitUtil;
import org.springblade.plugin.pay.vo.WxPayAccountConfigVO;
import org.springframework.stereotype.Service;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.security.cert.X509Certificate;
/**
* 服务实现类
*
* @author BladeX
* @since 2021-12-31
*/
@Service
@AllArgsConstructor
public class WxPayAccountConfigServiceImpl extends BaseServiceImpl<WxPayAccountConfigMapper, WxPayAccountConfig> implements IWxPayAccountConfigService {
private final IWxPayApiService wxPayApiService;
@Override
public IPage<WxPayAccountConfigVO> selectWxpayAccountConfigPage(IPage<WxPayAccountConfigVO> page, WxPayAccountConfigVO wxpayAccountConfig) {
return page.setRecords(baseMapper.selectWxpayAccountConfigPage(page, wxpayAccountConfig));
}
@Override
public boolean save(WxPayAccountConfig wxPayAccountConfig) {
try {
//处理一些默认值
if (wxPayAccountConfig.getApiType() == null) {
wxPayAccountConfig.setApiType(0);
}
if (wxPayAccountConfig.getStatus() == null) {
wxPayAccountConfig.setStatus(1);
}
wxPayAccountConfig = doCertParams(wxPayAccountConfig);
return super.save(wxPayAccountConfig);
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
}
@Override
public boolean updateById(WxPayAccountConfig wxPayAccountConfig) {
try {
wxPayAccountConfig = doCertParams(wxPayAccountConfig);
return super.updateById(wxPayAccountConfig);
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
}
@Override
public boolean saveOrUpdate(WxPayAccountConfig wxPayAccountConfig) {
try {
wxPayAccountConfig = doCertParams(wxPayAccountConfig);
return super.saveOrUpdate(wxPayAccountConfig);
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
}
/**
* 处理微信证书参数
*
* @return
*/
private WxPayAccountConfig doCertParams(WxPayAccountConfig wxPayAccountConfig) {
try {
String certPemUrl = wxPayAccountConfig.getWxPayCertFile();
if (!StringUtil.isBlank(certPemUrl)) {
String path = FileUtil.downloadFile(certPemUrl);
String certPemStr = cn.hutool.core.io.FileUtil.readUtf8String(path);
BufferedInputStream inputStream = cn.hutool.core.io.FileUtil.getInputStream(path);
// 证书编号
X509Certificate certificate = PayKit.getCertificate(inputStream);
String certficatesNo = certificate.getSerialNumber().toString(16).toUpperCase();
wxPayAccountConfig.setCertPem(certPemStr);
wxPayAccountConfig.setCertSerialNo(certficatesNo);
inputStream.close();
cn.hutool.core.io.FileUtil.del(path);
}
String certPkcs = wxPayAccountConfig.getWxPayPkCsFile();
if (!StringUtil.isBlank(certPkcs)) {
String certpath = FileUtil.downloadFile(certPkcs);
String certPkcsStr = WxPayInitUtil.initPks(certpath);
wxPayAccountConfig.setCertPkcs(certPkcsStr);
cn.hutool.core.io.FileUtil.del(certpath);
}
String certPrivateKey = wxPayAccountConfig.getWxPayPrivateKeyFile();
if (!StringUtil.isBlank(certPrivateKey)) {
String path = FileUtil.downloadFile(certPrivateKey);
String certPrivateKeyStr = cn.hutool.core.io.FileUtil.readUtf8String(path);
wxPayAccountConfig.setCertPrivateKey(certPrivateKeyStr);
//处理【验证微信支付身份】证书
if (StringUtil.isBlank(wxPayAccountConfig.getWxPubKeyFile())) {
//未上传微信支付公钥,自动去获取微信支付平台证书
if (StringUtil.isBlank(wxPayAccountConfig.getCertSerialNo())) {
throw new ServiceException("未读取到平台证书编号,请检查CERT证书文件是否有误!");
}
String publicKey = wxPayApiService.getPublicKey(path, wxPayAccountConfig.getMchId(), wxPayAccountConfig.getV3Key(), wxPayAccountConfig.getCertSerialNo());
if (StringUtil.isBlank(publicKey)) {
throw new ServiceException("自动获取微信平台证书失败,请登录微信商户平台->账户中心->API安全检查【验证微信支付身份】方式是否支持平台证书模式!");
}
wxPayAccountConfig.setCertPubKey(publicKey);
// 证书平台编号
X509Certificate certificate = PayKit.getCertificate(new ByteArrayInputStream(publicKey.getBytes()));
String platSerialNo = certificate.getSerialNumber().toString(16).toUpperCase();
wxPayAccountConfig.setCertPlatSerialNo(platSerialNo);
cn.hutool.core.io.FileUtil.del(path);
} else {
if (StringUtil.isBlank(wxPayAccountConfig.getWxPubKeyId())) {
throw new ServiceException("请填写微信支付公钥ID!");
}
String wxPubKeyFileUrl = wxPayAccountConfig.getWxPubKeyFile();
String wxPubKeyFilePath = FileUtil.downloadFile(wxPubKeyFileUrl);
String wxPubKeyStr = cn.hutool.core.io.FileUtil.readUtf8String(wxPubKeyFilePath);
wxPayAccountConfig.setWxPubKey(wxPubKeyStr);
cn.hutool.core.io.FileUtil.del(wxPubKeyFilePath);
}
}
return wxPayAccountConfig;
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
}
@Override
public WxPayAccountConfig getInfoByMchId(String mchId) {
WxPayAccountConfig wxPayAccountConfig = null;
try {
WxPayAccountConfig wxPayAccountConfigWhere = new WxPayAccountConfig();
wxPayAccountConfigWhere.setMchId(mchId);
wxPayAccountConfigWhere.setIsDeleted(0);
wxPayAccountConfig = super.getOne(Condition.getQueryWrapper(wxPayAccountConfigWhere));
} catch (Exception e) {
e.printStackTrace();
}
return wxPayAccountConfig;
}
}

View File

@@ -0,0 +1,368 @@
package org.springblade.plugin.pay.service.impl;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.extra.qrcode.QrCodeUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yungouos.pay.common.PayException;
import com.yungouos.pay.entity.PayOrder;
import com.yungouos.pay.entity.RefundOrder;
import com.yungouos.pay.order.SystemOrder;
import com.yungouos.pay.wxpay.WxPay;
import lombok.AllArgsConstructor;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.oss.model.BladeFile;
import org.springblade.core.tool.utils.PathUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.modules.common.eums.OrderStatus;
import org.springblade.modules.common.eums.PaymentStatus;
import org.springblade.modules.common.eums.PaymentType;
import org.springblade.modules.common.pojo.entity.CommonPayOrderEntity;
import org.springblade.modules.common.service.ICommonPayOrderService;
import org.springblade.modules.resource.builder.OssBuilder;
import org.springblade.plugin.pay.api.wxpay.IWxPayApiService;
import org.springblade.plugin.pay.common.WxPayException;
import org.springblade.plugin.pay.constant.PayConstant;
import org.springblade.plugin.pay.entity.Order;
import org.springblade.plugin.pay.entity.Refund;
import org.springblade.plugin.pay.entity.WxPayAccountConfig;
import org.springblade.plugin.pay.entityBiz.WxPayCheckBiz;
import org.springblade.plugin.pay.entityBiz.WxPayRefundBiz;
import org.springblade.plugin.pay.service.IOrderService;
import org.springblade.plugin.pay.service.IRefundService;
import org.springblade.plugin.pay.service.IWxPayAccountConfigService;
import org.springblade.plugin.pay.service.IWxPayService;
import org.springblade.plugin.pay.util.OrderUtil;
import org.springblade.plugin.pay.util.WxPayV3ParamsUtil;
import org.springframework.stereotype.Service;
import java.io.BufferedInputStream;
import java.io.File;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
/**
* 微信支付业务接口实现
*
* @author YunGouOS技术部-029
* @time 2022/1/1 16:56
*/
@Service
@AllArgsConstructor
public class WxPayServiceImpl implements IWxPayService {
private final IOrderService orderService;
private final IWxPayApiService wxPayApiService;
private final IWxPayAccountConfigService wxPayAccountConfigService;
private final OssBuilder ossBuilder;
private final WxPayV3ParamsUtil wxPayV3ParamsUtil;
private final IRefundService refundService;
private final ICommonPayOrderService commonPayOrderService;
/**
* 订单前置验证
*
* @return
*/
private WxPayCheckBiz beforeCheck(String appId, String mchId, String body, String money, String notifyUrl, String payType,String orderPrefix) {
WxPayAccountConfig wxPayAccountConfig = wxPayAccountConfigService.getInfoByMchId(mchId);
if (wxPayAccountConfig == null) {
throw new ServiceException("该商户号尚未接入");
}
if (wxPayAccountConfig.getStatus().intValue() != 1) {
throw new ServiceException("该商户号已暂停交易");
}
if (StringUtil.isBlank(notifyUrl)) {
notifyUrl = wxPayAccountConfig.getNotifyUrl();
}
Order order = orderService.save(appId, mchId, wxPayAccountConfig.getPayName(), body, money, PayConstant.WXPAY, payType, notifyUrl, orderPrefix);
if (order == null) {
throw new ServiceException("下单失败,请稍候再试");
}
WxPayCheckBiz wxPayCheckBiz = new WxPayCheckBiz();
wxPayCheckBiz.setOrder(order);
wxPayCheckBiz.setWxPayAccountConfig(wxPayAccountConfig);
return wxPayCheckBiz;
}
@Override
public Map<String, Object> nativePay(String appId, String mchId, String body, String money, String notifyUrl, String attach ,String orderPrefix) {
Map<String, Object> map = new HashMap<String, Object>();
try {
WxPayCheckBiz wxPayCheckBiz = beforeCheck(appId, mchId, body, money, notifyUrl,PayConstant.NATIVEPAY , orderPrefix);
Order order = wxPayCheckBiz.getOrder();
WxPayAccountConfig wxPayAccountConfig = wxPayCheckBiz.getWxPayAccountConfig();
String codeUrl = null;
Integer apiType = wxPayAccountConfig.getApiType();
switch (apiType) {
case 0:
//微信官方接口
codeUrl = wxPayApiService.nativePay(order, wxPayAccountConfig, attach);
break;
case 1:
//YunGouOS服务商平台接口,文档:https://open.pay.yungouos.com/#/api/api/pay/wxpay/nativePay
codeUrl = WxPay.nativePay(order.getOrderNo(), order.getMoney(), order.getMchId(), body, "1", attach, order.getNotifyUrl(), null, null, null, null, null, null, wxPayAccountConfig.getPayKey());
break;
default:
throw new ServiceException("该渠道暂不支持");
}
String path = PathUtil.getJarPath() + File.separator + order.getOrderNo() + ".png";
File file = QrCodeUtil.generate(codeUrl, 240, 240, FileUtil.file(path));
file = new File(path);
BufferedInputStream inputStream = FileUtil.getInputStream(file);
BladeFile bladeFile = ossBuilder.template().putFile(order.getOrderNo() + ".png", inputStream);
map.put("url", bladeFile.getLink());
map.put("order", order);
inputStream.close();
FileUtil.del(path);
} catch (PayException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (WxPayException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
return map;
}
@Override
public Map<String, String> jsPay(String appId, String mchId, String openId, String body, String money, String notifyUrl, String attach ,String orderPrefix) {
try {
WxPayCheckBiz wxPayCheckBiz = beforeCheck(appId, mchId, body, money, notifyUrl,PayConstant.JSPAY, orderPrefix);
Order order = wxPayCheckBiz.getOrder();
WxPayAccountConfig wxPayAccountConfig = wxPayCheckBiz.getWxPayAccountConfig();
Integer apiType = wxPayAccountConfig.getApiType();
Map<String, String> jsApiParams = null;
switch (apiType) {
case 0:
//微信官方接口
String prepayId = wxPayApiService.jsPay(openId, order, wxPayAccountConfig, attach);
jsApiParams = wxPayV3ParamsUtil.jsApiCreateSign(appId, prepayId, wxPayAccountConfig);
break;
case 1:
//YunGouOS服务商平台接口,文档:https://open.pay.yungouos.com/#/api/api/pay/wxpay/jsapi
String jsPayStr = WxPay.jsapiPay(order.getOrderNo(), order.getMoney(), order.getMchId(), body, openId, attach, order.getNotifyUrl(), null, null, null, null, null, null, wxPayAccountConfig.getPayKey());
JSONObject jsonObject = JSON.parseObject(jsPayStr);
jsApiParams = JSON.toJavaObject(jsonObject, Map.class);
break;
default:
throw new ServiceException("该渠道暂不支持");
}
return jsApiParams;
} catch (PayException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (ServiceException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
}
@Override
public Map<String, String> wxApp(String appId, String mchId, String openId, String body, String money, String notifyUrl, String attach, String orderPrefix) {
try {
WxPayCheckBiz wxPayCheckBiz = beforeCheck(appId, mchId, body, money, notifyUrl,PayConstant.WXMAPPPAY, orderPrefix);
Order order = wxPayCheckBiz.getOrder();
WxPayAccountConfig wxPayAccountConfig = wxPayCheckBiz.getWxPayAccountConfig();
Integer apiType = wxPayAccountConfig.getApiType();
Map<String, String> jsApiParams = null;
switch (apiType) {
case 0:
//微信官方接口
String prepayId = wxPayApiService.jsPay(openId, order, wxPayAccountConfig, attach);
jsApiParams = wxPayV3ParamsUtil.jsApiCreateSign(appId, prepayId, wxPayAccountConfig);
break;
case 1:
//YunGouOS服务商平台接口,文档:https://open.pay.yungouos.com/#/api/api/pay/wxpay/minPay
JSONObject minAppPayParams = WxPay.minAppPaySend(openId, order.getOrderNo(), order.getMoney(), order.getMchId(), body, attach, notifyUrl, null, null, null, null, null, wxPayAccountConfig.getPayKey());
jsApiParams = JSON.toJavaObject(minAppPayParams, Map.class);
break;
default:
throw new ServiceException("该渠道暂不支持");
}
return jsApiParams;
} catch (PayException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (ServiceException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
}
@Override
public String h5Pay(String appId, String mchId, String body, String money, String notifyUrl, String returnUrl, String attach, String orderPrefix) {
try {
WxPayCheckBiz wxPayCheckBiz = beforeCheck(appId, mchId, body, money, notifyUrl,PayConstant.H5PAY, orderPrefix);
Order order = wxPayCheckBiz.getOrder();
WxPayAccountConfig wxPayAccountConfig = wxPayCheckBiz.getWxPayAccountConfig();
Integer apiType = wxPayAccountConfig.getApiType();
String h5Url = null;
switch (apiType) {
case 0:
//微信官方接口
h5Url = wxPayApiService.h5Pay(order, wxPayAccountConfig, returnUrl, attach);
break;
case 1:
//YunGouOS服务商平台接口,文档:https://open.pay.yungouos.com/#/api/api/pay/wxpay/wapPay
h5Url = WxPay.H5Pay(order.getOrderNo(), order.getMoney(), order.getMchId(), body, attach, notifyUrl, returnUrl, null, null, null, null, null, wxPayAccountConfig.getPayKey());
break;
default:
throw new ServiceException("该渠道暂不支持");
}
return h5Url;
} catch (PayException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
} catch (ServiceException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
}
@Override
public Map<String, String> appPay(String appId, String mchId, String body, String money, String notifyUrl, String attach, String orderPrefix, Long orderId) {
Map<String, String> appPayParams = null;
try {
WxPayCheckBiz wxPayCheckBiz = beforeCheck(appId, mchId, body, money, notifyUrl,PayConstant.APPPAY , orderPrefix);
Order order = wxPayCheckBiz.getOrder();
CommonPayOrderEntity commonPayOrderEntity = new CommonPayOrderEntity();
commonPayOrderEntity.setId(order.getId());
commonPayOrderEntity.setOrderId(orderId);
commonPayOrderEntity.setStatus(OrderStatus.PENDING_PAYMENT.getCode());
commonPayOrderEntity.setPaymentStatus(PaymentStatus.UNPAID.getCode());
commonPayOrderEntity.setOrderNo(order.getOrderNo());
commonPayOrderEntity.setPaymentType(PaymentType.WECHAT.getCode());
commonPayOrderService.save(commonPayOrderEntity);
WxPayAccountConfig wxPayAccountConfig = wxPayCheckBiz.getWxPayAccountConfig();
Integer apiType = wxPayAccountConfig.getApiType();
switch (apiType) {
case 0:
//微信官方接口
String prepayId = wxPayApiService.appPay(appId, order, wxPayAccountConfig, attach);
appPayParams = WxPayV3ParamsUtil.appCreateSign(appId, prepayId, wxPayAccountConfig);
break;
case 1:
//YunGouOS服务商平台接口,文档:https://open.pay.yungouos.com/#/api/api/pay/wxpay/appPay
JSONObject appPay = WxPay.appPay(appId, order.getOrderNo(), order.getMoney(), order.getMchId(), body, attach, notifyUrl, null, null, null, null, wxPayAccountConfig.getPayKey());
appPayParams = JSON.toJavaObject(appPay, Map.class);
break;
default:
throw new ServiceException("该渠道暂不支持");
}
} catch (ServiceException e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
return appPayParams;
}
@Override
public WxPayRefundBiz refund(String orderNo, String mchId, String refundMoney, String reason, String notifyUrl) {
try {
Order order = orderService.getOrderInfoByOrderNoAndMchId(orderNo, mchId);
if (order == null) {
throw new ServiceException("订单不存在");
}
if (order.getStatus().intValue() != 1) {
throw new ServiceException("订单尚未支付");
}
if (order.getIsRefund().intValue() == 1 && NumberUtil.isGreaterOrEqual(new BigDecimal(order.getRefundMoney()), new BigDecimal(order.getMoney()))) {
throw new ServiceException("订单已全额退款");
}
WxPayAccountConfig wxPayAccountConfig = wxPayAccountConfigService.getInfoByMchId(order.getMchId());
if (wxPayAccountConfig == null) {
throw new ServiceException("商户未接入");
}
Refund refund = new Refund();
refund.setRefundNo(OrderUtil.createOrderNo("R"));
refund.setOrderNo(order.getOrderNo());
refund.setPayNo(order.getPayNo());
refund.setRefundMchId(order.getMchId());
refund.setRefundDesc(reason);
refund.setRefundMoney(refundMoney);
refund.setStatus(0);
if (StringUtil.isBlank(notifyUrl)) {
notifyUrl = wxPayAccountConfig.getRefundNotifyUrl();
}
refund.setNotifyUrl(notifyUrl);
boolean save = refundService.save(refund);
if (!save) {
throw new ServiceException("退款发起失败");
}
Integer apiType = wxPayAccountConfig.getApiType();
WxPayRefundBiz wxPayRefundBiz = null;
switch (apiType) {
case 0:
//微信官方接口
wxPayRefundBiz = wxPayApiService.refund(refund, wxPayAccountConfig, order.getMoney());
break;
case 1:
//YunGouOS服务商平台接口,文档:https://open.pay.yungouos.com/#/api/api/pay/wxpay/refundOrder
RefundOrder refundOrder = WxPay.orderRefund(refund.getOrderNo(), refund.getRefundMchId(), refund.getRefundMoney(), refund.getRefundNo(), refund.getRefundDesc(), refund.getNotifyUrl(), wxPayAccountConfig.getPayKey());
//转换为微信退款对象
wxPayRefundBiz = new WxPayRefundBiz();
wxPayRefundBiz.setRefund_id(refundOrder.getPayRefundNo());
wxPayRefundBiz.setOut_refund_no(refundOrder.getOutTradeRefundNo());
wxPayRefundBiz.setTransaction_id(refundOrder.getPayNo());
wxPayRefundBiz.setOut_trade_no(refundOrder.getOrderNo());
wxPayRefundBiz.setChannel(null);
wxPayRefundBiz.setUser_received_account(null);
wxPayRefundBiz.setSuccess_time(refundOrder.getApiRefundTime());
wxPayRefundBiz.setCreate_time(refundOrder.getRefundTime());
wxPayRefundBiz.setStatus("PROCESSING");
if (1 == refundOrder.getRefundStatus()) {
//退款成功
wxPayRefundBiz.setStatus("SUCCESS");
}
wxPayRefundBiz.setFunds_account(null);
break;
default:
throw new ServiceException("该渠道暂不支持");
}
return wxPayRefundBiz;
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
}
@Override
public JSONObject getOrderInfo(String orderNo, String payNo, String mchId) {
try {
WxPayAccountConfig wxPayAccountConfig = wxPayAccountConfigService.getInfoByMchId(mchId);
if (wxPayAccountConfig == null) {
throw new ServiceException("商户未接入");
}
Integer apiType = wxPayAccountConfig.getApiType();
JSONObject result = null;
switch (apiType) {
case 0:
//微信官方接口
result = wxPayApiService.getOrderInfo(orderNo, payNo, wxPayAccountConfig);
break;
case 1:
//YunGouOS服务商平台接口,文档:https://open.pay.yungouos.com/#/api/api/system/order/getPayOrderInfo
PayOrder payOrder = SystemOrder.getOrderInfoByOutTradeNo(orderNo, mchId, wxPayAccountConfig.getPayKey());
result = (JSONObject) JSONObject.toJSON(payOrder);
break;
default:
throw new ServiceException("该渠道暂不支持");
}
return result;
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
}
}

View File

@@ -0,0 +1,91 @@
package org.springblade.plugin.pay.util;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* 支付宝接口工具类
*
* @author YunGouOS技术部-029
* @time 2022/5/1 22:58
*/
public class AliPayApiUtil {
// -- header 常量定义 --//
private static final String HEADER_ENCODING = "encoding";
private static final String HEADER_NOCACHE = "no-cache";
private static final String DEFAULT_ENCODING = "UTF-8";
private static final boolean DEFAULT_NOCACHE = true;
/**
* 将异步通知的参数转化为Map
* Params:
* request – {HttpServletRequest}
* Returns:
* {Map }
*/
public static Map<String, String> toMap(HttpServletRequest request) {
Map<String, String> params = new HashMap<String, String>();
Map<String, String[]> requestParams = request.getParameterMap();
for (Iterator<String> iter = requestParams.keySet().iterator(); iter.hasNext(); ) {
String name = (String) iter.next();
String[] values = (String[]) requestParams.get(name);
String valueStr = "";
for (int i = 0; i < values.length; i++) {
valueStr = (i == values.length - 1) ? valueStr + values[i] : valueStr + values[i] + ",";
}
// 乱码解决,这段代码在出现乱码时使用。
// valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8");
params.put(name, valueStr);
}
return params;
}
/**
* 响应支付宝通知
*
* @param response
* @param contentType
* @param content
* @param headers
*/
public static void render(HttpServletResponse response, String contentType, String content, String... headers) {
// 分析headers参数
String encoding = DEFAULT_ENCODING;
boolean noCache = DEFAULT_NOCACHE;
try {
for (String header : headers) {
String headerName = StringUtils.substringBefore(header, ":");
String headerValue = StringUtils.substringAfter(header, ":");
if (StringUtils.equalsIgnoreCase(headerName, HEADER_ENCODING)) {
encoding = headerValue;
} else if (StringUtils.equalsIgnoreCase(headerName, HEADER_NOCACHE)) {
noCache = Boolean.parseBoolean(headerValue);
} else {
throw new IllegalArgumentException(headerName + "不是一个合法的header类型");
}
}
// 设置headers参数
String fullContentType = contentType + ";charset=" + encoding;
response.setContentType(fullContentType);
if (noCache) {
//Http 1.0 header
response.setDateHeader("Expires", 0);
response.addHeader("Pragma", "no-cache");
//Http 1.1 header
response.setHeader("Cache-Control", "no-cache");
}
response.getWriter().write(content);
response.getWriter().flush();
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
}

View File

@@ -0,0 +1,215 @@
package org.springblade.plugin.pay.util;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.*;
import com.alipay.api.request.AlipayTradeAppPayRequest;
import lombok.AllArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springblade.core.log.logger.BladeLogger;
import org.springblade.plugin.pay.common.AliPayException;
import org.springblade.plugin.pay.entity.AliPayAccountConfig;
import org.springframework.stereotype.Component;
/**
* 支付宝接口统一请求封装
*/
@Component
@AllArgsConstructor
public class AliPayHttpUtil {
private final BladeLogger bladeLogger;
private static final String JSON = "json";
private static final String CHARSETUTF8 = "UTF-8";
/**
* 发送POST请求
*
* @param aliPayAccountConfig 支付宝配置对象
* @param request 支付宝请求对象
* @param appAuthToken 三方模式授权tokne
* @param autoResult 是否自动判断结果
* @return
* @throws AlipayApiException
*/
public AlipayResponse doPost(AliPayAccountConfig aliPayAccountConfig, AlipayRequest request, String appAuthToken, boolean autoResult) throws AlipayApiException {
AlipayResponse response = null;
try {
request.setNotifyUrl(aliPayAccountConfig.getNotifyUrl());
// 支付宝请求链接对象
AlipayClient alipayClient = getAliPayClient(aliPayAccountConfig);
// 判断模式
if (!StringUtils.isBlank(aliPayAccountConfig.getAppCert())) {
// 证书模式
if (StringUtils.isBlank(appAuthToken)) {
// 直连
response = alipayClient.certificateExecute(request);
} else {
// 三方调用
response = alipayClient.certificateExecute(request, null, appAuthToken);
}
} else {
// 非证书模式
if (StringUtils.isBlank(appAuthToken)) {
// 直连
response = alipayClient.execute(request);
} else {
// 三方调用
response = alipayClient.execute(request, null, appAuthToken);
}
}
JSONObject json = new JSONObject();
json.put("请求参数", com.alibaba.fastjson.JSON.toJSONString(request.getBizModel()));
json.put("返回结果", com.alibaba.fastjson.JSON.toJSONString(response));
bladeLogger.info("alipay-api", json.toJSONString());
if (autoResult) {
if (response == null || !response.isSuccess()) {
throw new AlipayApiException(response.getSubMsg());
}
}
} catch (AlipayApiException e) {
e.printStackTrace();
throw new AlipayApiException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new AlipayApiException(e.getMessage());
}
return response;
}
/**
* 表单请求
*
* @author YunGouOS
* @date 2021年1月5日 下午2:51:24
*/
public AlipayResponse doPostPage(AliPayAccountConfig aliPayAccountConfig, AlipayRequest request, boolean autoResult) throws AlipayApiException {
AlipayResponse response = null;
try {
request.setNotifyUrl(aliPayAccountConfig.getNotifyUrl());
// 支付宝请求链接对象
AlipayClient alipayClient = getAliPayClient(aliPayAccountConfig);
response = alipayClient.pageExecute(request);
JSONObject json = new JSONObject();
json.put("请求参数", com.alibaba.fastjson.JSON.toJSONString(request.getBizModel()));
json.put("返回结果", com.alibaba.fastjson.JSON.toJSONString(response));
bladeLogger.info("alipay-api", json.toJSONString());
if (autoResult) {
if (response == null || !response.isSuccess()) {
throw new AlipayApiException(response.getSubMsg());
}
}
} catch (AlipayApiException e) {
e.printStackTrace();
throw new AlipayApiException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new AlipayApiException(e.getMessage());
}
return response;
}
/**
* APP请求
*
* @author YunGouOS
* @date 2021年1月5日 下午3:09:15
*/
public AlipayResponse doPostSdk(AliPayAccountConfig aliPayAccountConfig, AlipayTradeAppPayRequest request, String appAuthToken, boolean autoResult) throws AlipayApiException {
AlipayResponse response = null;
try {
request.setNotifyUrl(aliPayAccountConfig.getNotifyUrl());
// 支付宝请求链接对象
AlipayClient alipayClient = getAliPayClient(aliPayAccountConfig);
if (!StringUtils.isBlank(appAuthToken)) {
// 三方调用
request.putOtherTextParam("app_auth_token", appAuthToken);
}
response = alipayClient.sdkExecute(request);
JSONObject json = new JSONObject();
json.put("请求参数", com.alibaba.fastjson.JSON.toJSONString(request.getBizModel()));
json.put("返回结果", com.alibaba.fastjson.JSON.toJSONString(response));
bladeLogger.info("alipay-api", json.toJSONString());
if (autoResult) {
if (response == null || !response.isSuccess()) {
throw new AlipayApiException(response.getSubMsg());
}
}
} catch (AlipayApiException e) {
e.printStackTrace();
throw new AlipayApiException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new AlipayApiException(e.getMessage());
}
return response;
}
/**
* 支付宝链接对象
*
* @author YunGouOS
* @date 2022年04月27日 下午10:32:49
*/
public AlipayClient getAliPayClient(AliPayAccountConfig aliPayAccountConfig) {
AlipayClient aliPayClient = null;
try {
//证书不为空,返回证书模式
if (!StringUtils.isBlank(aliPayAccountConfig.getAppCert())) {
return getAliPayCertClient(aliPayAccountConfig);
}
String serviceUrl = aliPayAccountConfig.getServiceUrl();
String appId = aliPayAccountConfig.getAppId();
String privateKey = aliPayAccountConfig.getPrivateKey();
String pubKey = aliPayAccountConfig.getPubKey();
String signType = aliPayAccountConfig.getSignType();
aliPayClient = new DefaultAlipayClient(serviceUrl, appId, privateKey, JSON, CHARSETUTF8, pubKey, signType);
((DefaultAlipayClient)aliPayClient).setEncryptKey(aliPayAccountConfig.getPayKey());
} catch (Exception e) {
e.printStackTrace();
throw new AliPayException("支付宝商户初始化失败,请稍候再试!");
}
return aliPayClient;
}
/**
* 支付宝证书链接对象
*
* @author YunGouOS
* @date 2022年04月27日 下午10:35:41
*/
public AlipayClient getAliPayCertClient(AliPayAccountConfig aliPayAccountConfig) {
AlipayClient aliPayClient = null;
try {
CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
certAlipayRequest.setServerUrl(aliPayAccountConfig.getServiceUrl());
certAlipayRequest.setAppId(aliPayAccountConfig.getAppId());
certAlipayRequest.setPrivateKey(aliPayAccountConfig.getPrivateKey());
certAlipayRequest.setFormat(JSON);
certAlipayRequest.setCharset(CHARSETUTF8);
certAlipayRequest.setSignType(aliPayAccountConfig.getSignType());
if (StringUtils.isBlank(aliPayAccountConfig.getAppCert())) {
throw new AliPayException("未配置应用证书");
}
if (StringUtils.isBlank(aliPayAccountConfig.getAlipayPubCert())) {
throw new AliPayException("未配置支付宝公钥证书");
}
if (StringUtils.isBlank(aliPayAccountConfig.getRootCert())) {
throw new AliPayException("未配置支付宝根证书");
}
certAlipayRequest.setCertContent(aliPayAccountConfig.getAppCert());
certAlipayRequest.setAlipayPublicCertContent(aliPayAccountConfig.getAlipayPubCert());
certAlipayRequest.setRootCertContent(aliPayAccountConfig.getRootCert());
aliPayClient = new DefaultAlipayClient(certAlipayRequest);
} catch (Exception e) {
e.printStackTrace();
throw new AliPayException("支付宝商户初始化失败,请稍候再试!");
}
return aliPayClient;
}
}

View File

@@ -0,0 +1,188 @@
package org.springblade.plugin.pay.util;
import com.alipay.api.domain.*;
import lombok.AllArgsConstructor;
import org.springblade.plugin.pay.common.AliPayException;
import org.springblade.plugin.pay.constant.PayConstant;
import org.springblade.plugin.pay.entity.AliPayAccountConfig;
import org.springframework.stereotype.Component;
/**
* 支付宝接口请求参数工具类
*
* @author YunGouOS技术部-029
* @time 2022/4/28 15:11
*/
@Component
@AllArgsConstructor
public class AliPayParamsUtil {
/**
* 支付宝统一收单交易支付
*
* @author YunGouOS
* @date 2019年7月31日 下午4:51:06
*/
public AlipayTradePayModel getAliPayTradePayParams(AliPayAccountConfig aliPayAccountConfig, String type, String body, String money, String orderNo, String authCode) {
AlipayTradePayModel model = null;
try {
model = new AlipayTradePayModel();
model.setOutTradeNo(orderNo);
model.setTotalAmount(money);
model.setSubject(body);
switch (type) {
case PayConstant.CODEPAY:
// 条码支付
model.setScene("bar_code");
break;
case PayConstant.FACEPAY:
// 刷脸支付
model.setScene("security_code");
break;
default:
break;
}
model.setAuthCode(authCode);
model.setSellerId(aliPayAccountConfig.getMchId());
model.setTimeoutExpress("2d");
} catch (Exception e) {
e.printStackTrace();
throw new AliPayException("支付宝下单失败");
}
return model;
}
/**
* 支付宝统一预下单对象
*
* @author YunGouOS
* @date 2019年7月31日 下午4:51:06
*/
public AlipayTradePrecreateModel getAliPayServicePushOrderParam(AliPayAccountConfig aliPayAccountConfig, String body, String money, String orderNo) {
AlipayTradePrecreateModel model = null;
try {
model = new AlipayTradePrecreateModel();
model.setOutTradeNo(orderNo);
model.setSellerId(aliPayAccountConfig.getMchId());
model.setSubject(body);
//二维码超时时间
model.setQrCodeTimeoutExpress("2d");
model.setTimeoutExpress("2d");
model.setTotalAmount(money);
} catch (Exception e) {
e.printStackTrace();
throw new AliPayException("支付宝下单失败");
}
return model;
}
/**
* 支付宝统一下单
*
* @author YunGouOS
* @date 2020年12月31日 下午5:34:27
*/
public AlipayTradeCreateModel getAliPayServicePushOrderCreateParam(AliPayAccountConfig aliPayAccountConfig, String buyerId, String body, String money, String orderNo) {
AlipayTradeCreateModel model = null;
try {
model = new AlipayTradeCreateModel();
model.setOutTradeNo(orderNo);
model.setSellerId(aliPayAccountConfig.getMchId());
model.setBuyerId(buyerId);
model.setSubject(body);
model.setTimeoutExpress("2d");
model.setTotalAmount(money);
} catch (Exception e) {
e.printStackTrace();
throw new AliPayException("支付宝下单失败");
}
return model;
}
/**
* PC网站支付
*
* @author YunGouOS
* @date 2021年1月4日 下午8:42:20
*/
public AlipayTradePagePayModel getAliPayServiceWebParam(String orderNo, String money, String body) {
AlipayTradePagePayModel model = null;
try {
model = new AlipayTradePagePayModel();
model.setOutTradeNo(orderNo);
model.setProductCode("FAST_INSTANT_TRADE_PAY");
model.setTotalAmount(money);
model.setSubject(body);
} catch (Exception e) {
e.printStackTrace();
throw new AliPayException("支付宝下单失败");
}
return model;
}
/**
* 支付宝手机网站支付
*
* @author YunGouOS
* @date 2020年2月12日 下午1:59:45
*/
public AlipayTradeWapPayModel getAliPayServiceH5Param(AliPayAccountConfig aliPayAccountConfig, String body, String money, String orderNo, String returnUrl) {
AlipayTradeWapPayModel model = null;
try {
model = new AlipayTradeWapPayModel();
model.setSubject(body);
model.setOutTradeNo(orderNo);
model.setTotalAmount(money);
model.setQuitUrl(returnUrl);
model.setProductCode("QUICK_WAP_WAY");
} catch (Exception e) {
e.printStackTrace();
throw new AliPayException("支付宝下单失败");
}
return model;
}
/**
* APP支付
*
* @author YunGouOS
* @date 2021年1月5日 下午1:49:53
*/
public AlipayTradeAppPayModel getAliPayServiceAppParam(String orderNo, String money, String body) {
AlipayTradeAppPayModel model = null;
try {
model = new AlipayTradeAppPayModel();
model.setOutTradeNo(orderNo);
model.setProductCode("QUICK_MSECURITY_PAY");
model.setTotalAmount(money);
model.setSubject(body);
} catch (Exception e) {
e.printStackTrace();
throw new AliPayException("支付宝下单失败");
}
return model;
}
/**
* 支付宝退款对象
*
* @author YunGouOS
* @date 2019年8月13日 下午6:41:25
*/
public AlipayTradeRefundModel getAliPayRefundParam(String refundNo, String orderNo, String payNo, String refundMoney, String refundDesc) {
AlipayTradeRefundModel model = new AlipayTradeRefundModel();
model.setOutTradeNo(orderNo);
model.setTradeNo(payNo);
model.setRefundAmount(refundMoney);
model.setRefundReason(refundDesc);
model.setOutRequestNo(refundNo);
return model;
}
}

View File

@@ -0,0 +1,31 @@
package org.springblade.plugin.pay.util;
import cn.hutool.http.HttpRequest;
import java.io.File;
import java.io.InputStream;
/**
* @author YunGouOS技术部-029
* @time 2021/12/28 23:46
*/
public class FileUtil {
/**
* 从网络下载文件
*
* @param url
* @return
*/
public static String downloadFile(String url) {
try {
InputStream inputStream = HttpRequest.get(url).execute().bodyStream();
String type = url.substring(url.lastIndexOf("."), url.length());
File filetemp = File.createTempFile(java.util.UUID.randomUUID().toString().toUpperCase().replaceAll("-", ""), type);
File file = cn.hutool.core.io.FileUtil.writeFromStream(inputStream, filetemp);
return file.getPath();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

View File

@@ -0,0 +1,58 @@
package org.springblade.plugin.pay.util;
import cn.hutool.core.util.NumberUtil;
import java.math.BigDecimal;
public class MoneyUtil {
/**
* 元转分
* @param amount
* @return
*/
public static String getMoney(String amount) {
if (amount == null) {
return "";
}
// 金额转化为分为单位
String currency = amount.replaceAll("\\$|\\¥|\\,", ""); // 处理包含, ¥
// 或者$的金额
int index = currency.indexOf(".");
int length = currency.length();
Long amLong = 0l;
if (index == -1) {
amLong = Long.valueOf(currency + "00");
} else if (length - index >= 3) {
amLong = Long.valueOf((currency.substring(0, index + 3)).replace(".", ""));
} else if (length - index == 2) {
amLong = Long.valueOf((currency.substring(0, index + 2)).replace(".", "") + 0);
} else {
amLong = Long.valueOf((currency.substring(0, index + 1)).replace(".", "") + "00");
}
return amLong.toString();
}
/**
*
* 分转元
* @author YunGouOS
* @date 2019年4月29日 下午4:31:11
*/
public static String getMoneyYuan(String amount) {
if (amount == null) {
return "";
}
return BigDecimal.valueOf(Long.valueOf(amount)).divide(new BigDecimal(100)).toString();
}
/**
* 将元为单位的转换为分 (乘100)
*
* @param amount
* @return
*/
public static String changeY2F(String amount){
return NumberUtil.mul(amount,"100").toString();
}
}

View File

@@ -0,0 +1,47 @@
package org.springblade.plugin.pay.util;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* 订单工具类
*
* @author YunGouOS
*
*/
public class OrderUtil {
/**
* 生成订单号
*
* @param str
* 前缀
* @return
*/
public static String createOrderNo(String str) {
String currTime = getCurrTime();
String strTime = currTime.substring(8, currTime.length());
String strRandom = buildRandom(8) + "";
String strReq = str + strTime + strRandom;
return strReq;
}
private static String getCurrTime() {
Date now = new Date();
SimpleDateFormat outFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String s = outFormat.format(now);
return s;
}
private static int buildRandom(int length) {
int num = 1;
double random = Math.random();
if (random < 0.1) {
random = random + 0.1;
}
for (int i = 0; i < length; i++) {
num = num * 10;
}
return (int) ((random * num));
}
}

View File

@@ -0,0 +1,64 @@
package org.springblade.plugin.pay.util;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.codec.Base64Decoder;
import cn.hutool.core.io.FileUtil;
import javax.crypto.Cipher;
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.BufferedInputStream;
import java.io.IOException;
/**
* 微信证书初始化类
*/
public class WxPayInitUtil {
/**
* p12文件读取
*
* @author YunGouOS
* @date 2020年12月2日 下午6:19:59
*/
public static String initPks(String certpath) throws IOException {
String result = null;
BufferedInputStream inputStream = null;
try {
// P12证书文件路径
inputStream = FileUtil.getInputStream(certpath);
result = Base64.encode(inputStream);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (inputStream != null) {
inputStream.close();
}
}
return result;
}
/**
* 获取微信公钥证书值
*
* @author YunGouOS
* @date 2020年8月15日 下午3:20:14
*/
public static String getWxPayPublicKey(String associatedData, String nonce, String cipherText, String v3Key) {
String ALGORITHM = "AES/GCM/NoPadding";
int TAG_LENGTH_BIT = 128;
try {
Cipher cipher = Cipher.getInstance(ALGORITHM, "SunJCE");
SecretKeySpec key = new SecretKeySpec(v3Key.getBytes(), "AES");
GCMParameterSpec spec = new GCMParameterSpec(TAG_LENGTH_BIT, nonce.getBytes());
cipher.init(Cipher.DECRYPT_MODE, key, spec);
cipher.updateAAD(associatedData.getBytes());
String wxPayCert = new String(cipher.doFinal(Base64Decoder.decode(cipherText)));
return wxPayCert;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

View File

@@ -0,0 +1,141 @@
package org.springblade.plugin.pay.util;
import com.ijpay.core.IJPayHttpResponse;
import com.ijpay.core.kit.PayKit;
import com.ijpay.core.kit.WxPayKit;
import jakarta.servlet.http.HttpServletRequest;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.plugin.pay.common.WxPayException;
import org.springblade.plugin.pay.entity.WxPayAccountConfig;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.security.cert.X509Certificate;
/**
* 订单工具类
*
* @author YunGouOS
*/
public class WxPayUtil {
/**
* 验证微信支付API返回请求头签名
*/
public static void checkApiResultSign(IJPayHttpResponse response, WxPayAccountConfig wxPayAccountConfig) {
boolean verifySignature = false;
try {
String serialNo = response.getHeader("Wechatpay-Serial");
if (StringUtil.isBlank(serialNo)) {
throw new WxPayException("微信支付API证书编号错误!");
}
String timestamp = response.getHeader("Wechatpay-Timestamp");
String nonceStr = response.getHeader("Wechatpay-Nonce");
String signature = response.getHeader("Wechatpay-Signature");
String body = response.getBody();
String wxPubKeyId = wxPayAccountConfig.getWxPubKeyId();
String wxPubKey = wxPayAccountConfig.getWxPubKey();
if (serialNo.startsWith("PUB_KEY_ID")) {
//微信支付公钥验证签名
if (StringUtil.isBlank(wxPubKeyId) || jodd.util.StringUtil.isBlank(wxPubKey)) {
throw new WxPayException("微信支付API签名验证失败!公钥信息未上传");
}
verifySignature = WxPayKit.verifySignature(signature, body, nonceStr, timestamp, PayKit.getPublicKeyByContent(wxPubKey));
} else {
//平台证书验证模式
String signatureType = response.getHeader("Wechatpay-Signature-Type");
ByteArrayInputStream pubKeyStream = wxPayAccountConfig.getCertPubKeyStream();
verifySignature = WxPayKit.verifySignature(signatureType, signature, body, nonceStr, timestamp, pubKeyStream);
}
if (response.getStatus() == 200 && !verifySignature) {
throw new WxPayException("微信支付API签名验证失败!");
}
} catch (Exception e) {
e.printStackTrace();
throw new WxPayException(e.getMessage());
}
}
/**
* 验证微信支付回调(兼容微信平台证书与微信支付公钥双模式)
*
* @param request 回调请求对象
* @param wxPayAccountConfig 微信支付配置对象
* @throws WxPayException
*/
public static void checkNotifySign(HttpServletRequest request, WxPayAccountConfig wxPayAccountConfig) throws WxPayException {
try {
String serialNo = request.getHeader("Wechatpay-Serial");
if (StringUtil.isBlank(serialNo)) {
throw new WxPayException("微信支付API证书编号错误!");
}
String timestamp = request.getHeader("Wechatpay-Timestamp");
String nonce = request.getHeader("Wechatpay-Nonce");
String signature = request.getHeader("Wechatpay-Signature");
String body = readData(request);
if (StringUtil.isBlank(body)) {
throw new WxPayException("微信支付回调参数为空!");
}
String wxPubKeyId = wxPayAccountConfig.getWxPubKeyId();
String wxPubKey = wxPayAccountConfig.getWxPubKey();
boolean verifySignature = false;
if (serialNo.startsWith("PUB_KEY_ID")) {
if (StringUtil.isBlank(wxPubKeyId) || jodd.util.StringUtil.isBlank(wxPubKey)) {
throw new WxPayException("微信支付API签名验证失败!公钥信息未上传");
}
//微信支付公钥验签模式
if (StringUtil.isBlank(timestamp) || StringUtil.isBlank(nonce) || StringUtil.isBlank(serialNo) || StringUtil.isBlank(signature) || StringUtil.isBlank(body)) {
throw new WxPayException("微信支付回调参数缺失!");
}
if (!StringUtil.equals(serialNo, wxPubKeyId)) {
throw new WxPayException("微信支付公钥ID验证失败!");
}
verifySignature = WxPayKit.verifySignature(signature, body, nonce, timestamp,
PayKit.getPublicKeyByContent(wxPubKey));
} else {
//平台证书验证模式
// 获取平台证书序列号
X509Certificate certificate = PayKit.getCertificate(wxPayAccountConfig.getCertPubKeyStream());
verifySignature = WxPayKit.verifySignature(signature, body, nonce, timestamp,
certificate.getPublicKey());
}
if (!verifySignature) {
throw new WxPayException("签名验证失败!");
}
} catch (Exception e) {
e.printStackTrace();
throw new WxPayException(e.getMessage());
}
}
public static String readData(HttpServletRequest request) {
BufferedReader br = null;
try {
StringBuilder result = new StringBuilder();
br = request.getReader();
for (String line; (line = br.readLine()) != null; ) {
if (result.length() > 0) {
result.append("\n");
}
result.append(line);
}
return result.toString();
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}

View File

@@ -0,0 +1,54 @@
package org.springblade.plugin.pay.util;
import com.ijpay.core.kit.WxPayKit;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.core.tool.utils.WebUtil;
import org.springblade.plugin.pay.entity.Order;
import org.springblade.plugin.pay.entity.WxPayAccountConfig;
import org.springframework.stereotype.Component;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* 微信支付v2接口参数工具类
*
* @author YunGouOS技术部-029
* @action
* @time 2020年6月5日 下午10:38:40
*/
@Component
@AllArgsConstructor
public class WxPayV2ParamsUtil implements Serializable {
/**
* 构建微信支付付款码参数
*
* @author YunGouOS
* @date 2020年3月5日 下午10:48:02
*/
public Map<String, String> getCodePayParam(String authCode, Order order, WxPayAccountConfig wxPayAccountConfig, String attach) {
Map<String, String> params = new HashMap<String, String>();
try {
params.put("appid", order.getAppId());
params.put("mch_id", order.getMchId());
params.put("body", order.getBody());
params.put("out_trade_no", order.getOrderNo());
params.put("total_fee", MoneyUtil.getMoney(order.getMoney()));
params.put("auth_code", authCode);
if (!StringUtil.isBlank(attach)) {
params.put("attach", attach);
}
params.put("nonce_str", String.valueOf(System.currentTimeMillis()));
params.put("spbill_create_ip", WebUtil.getIP());
params.put("sign", WxPayKit.createSign(params, wxPayAccountConfig.getPayKey()));
} catch (Exception e) {
e.printStackTrace();
}
return params;
}
}

View File

@@ -0,0 +1,235 @@
package org.springblade.plugin.pay.util;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ijpay.core.IJPayHttpResponse;
import com.ijpay.core.enums.RequestMethodEnum;
import com.ijpay.wxpay.WxPayApi;
import com.ijpay.wxpay.enums.WxDomainEnum;
import lombok.AllArgsConstructor;
import org.springblade.core.log.logger.BladeLogger;
import org.springblade.plugin.pay.common.Common;
import org.springblade.plugin.pay.common.WxPayException;
import org.springblade.plugin.pay.entity.WxPayAccountConfig;
import org.springframework.stereotype.Component;
import java.io.File;
import java.security.PrivateKey;
import java.util.Map;
/**
* 微信支付V3接口 http请求
*
* @author YunGouOS技术部-029
* @action
* @time 2020年8月14日 下午11:37:22
*/
@Component
@AllArgsConstructor
public class WxPayV3ApiHttpUtil {
private final BladeLogger bladeLogger;
/**
* 发送GET请求(未验证返回签名,一般都是服务端请求,不验证也没关系)
*
* @author YunGouOS
* @date 2020年8月14日 下午11:42:49
*/
public JSONObject doGet(String url, String mchId, String certficatesNo, String platSerialNo, PrivateKey privateKey, Map<String, String> params) {
try {
IJPayHttpResponse ijPayHttpResponse = WxPayApi.v3(RequestMethodEnum.GET, WxDomainEnum.CHINA.toString(), url, mchId, certficatesNo, platSerialNo, privateKey, params);
Map<String, Object> resultMap = WxPayApi.buildResMap(ijPayHttpResponse);
JSONObject json = new JSONObject();
json.put("请求参数", JSON.toJSONString(params));
json.put("返回结果", JSON.toJSONString(resultMap));
bladeLogger.info("wxpay-api-v3", json.toJSONString());
JSONObject body = Common.doWxPayApiV3Result(resultMap);
return body;
} catch (WxPayException e) {
throw new WxPayException(e.getMessage());
} catch (Exception e) {
throw new WxPayException(e.getMessage());
}
}
/**
* 发送get请求(会验证返回签名)
*
* @return
*/
public JSONObject doGet(String url, Map<String, String> params, WxPayAccountConfig wxPayAccountConfig) {
try {
String certficatesNo = wxPayAccountConfig.getCertSerialNo();
String platSerialNo = wxPayAccountConfig.getCertPlatSerialNo();
PrivateKey privateKey = wxPayAccountConfig.getPrivateKey();
String mchId = wxPayAccountConfig.getMchId();
IJPayHttpResponse ijPayHttpResponse = WxPayApi.v3(RequestMethodEnum.GET, WxDomainEnum.CHINA.toString(), url, mchId, certficatesNo, platSerialNo, privateKey, params);
Map<String, Object> resultMap = WxPayApi.buildResMap(ijPayHttpResponse);
JSONObject json = new JSONObject();
json.put("请求参数", JSON.toJSONString(params));
json.put("返回结果", JSON.toJSONString(resultMap));
bladeLogger.info("wxpay-api-v3", json.toJSONString());
JSONObject body = Common.doWxPayApiV3Result(resultMap);
WxPayUtil.checkApiResultSign(ijPayHttpResponse, wxPayAccountConfig);
return body;
} catch (WxPayException e) {
throw new WxPayException(e.getMessage());
} catch (Exception e) {
throw new WxPayException(e.getMessage());
}
}
/**
* 发送POST请求(未验证返回签名,一般都是服务端请求,不验证也没关系)
*
* @author YunGouOS
* @date 2020年8月15日 上午9:33:50
*/
public JSONObject doPost(String url, String mchId, String certficatesNo, String platSerialNo, PrivateKey privateKey, Map<String, Object> params) {
try {
IJPayHttpResponse ijPayHttpResponse = WxPayApi.v3(RequestMethodEnum.POST, WxDomainEnum.CHINA.toString(), url, mchId, certficatesNo, platSerialNo, privateKey, JSON.toJSONString(params));
Map<String, Object> resultMap = WxPayApi.buildResMap(ijPayHttpResponse);
JSONObject json = new JSONObject();
json.put("请求参数", JSON.toJSONString(params));
json.put("返回结果", JSON.toJSONString(resultMap));
bladeLogger.info("wxpay-api-v3", json.toJSONString());
JSONObject body = Common.doWxPayApiV3Result(resultMap);
return body;
} catch (WxPayException e) {
throw new WxPayException(e.getMessage());
} catch (Exception e) {
throw new WxPayException(e.getMessage());
}
}
/**
* 发送POST请求(会验证返回签名)
*
* @author YunGouOS
* @date 2025年2月16日 下午23:15:50
*/
public JSONObject doPost(String url, Map<String, Object> params, WxPayAccountConfig wxPayAccountConfig) {
try {
String certficatesNo = wxPayAccountConfig.getCertSerialNo();
String platSerialNo = wxPayAccountConfig.getCertPlatSerialNo();
PrivateKey privateKey = wxPayAccountConfig.getPrivateKey();
String mchId = wxPayAccountConfig.getMchId();
IJPayHttpResponse ijPayHttpResponse = WxPayApi.v3(RequestMethodEnum.POST, WxDomainEnum.CHINA.toString(), url, mchId, certficatesNo, platSerialNo, privateKey, JSON.toJSONString(params));
Map<String, Object> resultMap = WxPayApi.buildResMap(ijPayHttpResponse);
JSONObject json = new JSONObject();
json.put("请求参数", JSON.toJSONString(params));
json.put("返回结果", JSON.toJSONString(resultMap));
bladeLogger.info("wxpay-api-v3", json.toJSONString());
JSONObject body = Common.doWxPayApiV3Result(resultMap);
WxPayUtil.checkApiResultSign(ijPayHttpResponse, wxPayAccountConfig);
return body;
} catch (WxPayException e) {
throw new WxPayException(e.getMessage());
} catch (Exception e) {
throw new WxPayException(e.getMessage());
}
}
/**
* 发送put请求(未验证返回签名,一般都是服务端请求,不验证也没关系)
*
* @author YunGouOS
* @date 2021年6月8日 上午11:11:21
*/
public JSONObject doPut(String url, String mchId, String certficatesNo, String platSerialNo, PrivateKey privateKey, Map<String, Object> params) {
try {
IJPayHttpResponse ijPayHttpResponse = WxPayApi.v3(RequestMethodEnum.PUT, WxDomainEnum.CHINA.toString(), url, mchId, certficatesNo, platSerialNo, privateKey, JSON.toJSONString(params));
Map<String, Object> resultMap = WxPayApi.buildResMap(ijPayHttpResponse);
JSONObject json = new JSONObject();
json.put("请求参数", JSON.toJSONString(params));
json.put("返回结果", JSON.toJSONString(resultMap));
bladeLogger.info("wxpay-api-v3", json.toJSONString());
JSONObject body = Common.doWxPayApiV3Result(resultMap);
return body;
} catch (WxPayException e) {
throw new WxPayException(e.getMessage());
} catch (Exception e) {
throw new WxPayException(e.getMessage());
}
}
/**
* 发送put请求(会验证返回签名)
*
* @author YunGouOS
* @date 2025年2月16日 下午23:16:21
*/
public JSONObject doPut(String url, Map<String, Object> params, WxPayAccountConfig wxPayAccountConfig) {
try {
String certficatesNo = wxPayAccountConfig.getCertSerialNo();
String platSerialNo = wxPayAccountConfig.getCertPlatSerialNo();
PrivateKey privateKey = wxPayAccountConfig.getPrivateKey();
String mchId = wxPayAccountConfig.getMchId();
IJPayHttpResponse ijPayHttpResponse = WxPayApi.v3(RequestMethodEnum.PUT, WxDomainEnum.CHINA.toString(), url, mchId, certficatesNo, platSerialNo, privateKey, JSON.toJSONString(params));
Map<String, Object> resultMap = WxPayApi.buildResMap(ijPayHttpResponse);
JSONObject json = new JSONObject();
json.put("请求参数", JSON.toJSONString(params));
json.put("返回结果", JSON.toJSONString(resultMap));
bladeLogger.info("wxpay-api-v3", json.toJSONString());
JSONObject body = Common.doWxPayApiV3Result(resultMap);
WxPayUtil.checkApiResultSign(ijPayHttpResponse, wxPayAccountConfig);
return body;
} catch (WxPayException e) {
throw new WxPayException(e.getMessage());
} catch (Exception e) {
throw new WxPayException(e.getMessage());
}
}
/**
* 上传文件(未验证返回签名,一般都是服务端请求,不验证也没关系)
*
* @author YunGouOS
* @date 2020年8月15日 上午9:51:27
*/
public JSONObject doUpload(String url, String mchId, String certficatesNo, String platSerialNo, PrivateKey privateKey, String body, File file) {
try {
IJPayHttpResponse response = WxPayApi.v3(WxDomainEnum.CHINA.toString(), url, mchId, certficatesNo, platSerialNo, privateKey, body, file);
Map<String, Object> resultMap = WxPayApi.buildResMap(response);
JSONObject json = new JSONObject();
json.put("返回结果", JSON.toJSONString(resultMap));
bladeLogger.info("wxpay-api-v3", json.toJSONString());
JSONObject result = Common.doWxPayApiV3Result(resultMap);
return result;
} catch (WxPayException e) {
throw new WxPayException(e.getMessage());
} catch (Exception e) {
throw new WxPayException(e.getMessage());
}
}
/**
* 上传文件(会验证返回签名)
*
* @return
*/
public JSONObject doUpload(String url, String body, File file, WxPayAccountConfig wxPayAccountConfig) {
try {
String certficatesNo = wxPayAccountConfig.getCertSerialNo();
String platSerialNo = wxPayAccountConfig.getCertPlatSerialNo();
PrivateKey privateKey = wxPayAccountConfig.getPrivateKey();
String mchId = wxPayAccountConfig.getMchId();
IJPayHttpResponse response = WxPayApi.v3(WxDomainEnum.CHINA.toString(), url, mchId, certficatesNo, platSerialNo, privateKey, body, file);
Map<String, Object> resultMap = WxPayApi.buildResMap(response);
JSONObject json = new JSONObject();
json.put("返回结果", JSON.toJSONString(resultMap));
bladeLogger.info("wxpay-api-v3", json.toJSONString());
JSONObject result = Common.doWxPayApiV3Result(resultMap);
WxPayUtil.checkApiResultSign(response, wxPayAccountConfig);
return result;
} catch (WxPayException e) {
throw new WxPayException(e.getMessage());
} catch (Exception e) {
throw new WxPayException(e.getMessage());
}
}
}

View File

@@ -0,0 +1,290 @@
package org.springblade.plugin.pay.util;
import com.ijpay.core.enums.SignType;
import com.ijpay.core.kit.PayKit;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.plugin.pay.entity.WxPayAccountConfig;
import org.springframework.stereotype.Component;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
/**
* 微信支付v3接口参数工具类
*
* @author YunGouOS技术部-029
* @action
* @time 2020年6月5日 下午10:38:40
*/
@Component
@AllArgsConstructor
public class WxPayV3ParamsUtil implements Serializable {
private static final long serialVersionUID = -9221844757164136418L;
/**
* 微信支付扫码接口下单参数
*
* @param orderNo
* @param appId
* @param mchId
* @param body
* @param money
* @param attach
* @param notifyUrl
* @return
*/
public Map<String, Object> getNativePayParams(String orderNo, String appId, String mchId, String body, String money, String attach, String notifyUrl) {
Map<String, Object> params = new HashMap<String, Object>();
try {
params.put("appid", appId);
params.put("mchid", mchId);
params.put("description", body);
params.put("out_trade_no", orderNo);
if (!StringUtil.isBlank(attach)) {
params.put("attach", attach);
}
params.put("notify_url", notifyUrl);
Map<String, Object> amount = new HashMap<String, Object>();
amount.put("total", Integer.valueOf(MoneyUtil.getMoney(money)));
params.put("amount", amount);
} catch (Exception e) {
e.printStackTrace();
}
return params;
}
/**
* 微信jsapi支付参数
*
* @param orderNo
* @param appId
* @param mchId
* @param openId
* @param body
* @param money
* @param attach
* @param notifyUrl
* @return
*/
public Map<String, Object> getJsApiParams(String orderNo, String appId, String mchId, String openId, String body, String money, String attach, String notifyUrl) {
Map<String, Object> params = new HashMap<String, Object>();
try {
params.put("appid", appId);
params.put("mchid", mchId);
params.put("description", body);
params.put("out_trade_no", orderNo);
if (!StringUtil.isBlank(attach)) {
params.put("attach", attach);
}
params.put("notify_url", notifyUrl);
Map<String, Object> amount = new HashMap<String, Object>();
amount.put("total", Integer.valueOf(MoneyUtil.getMoney(money)));
params.put("amount", amount);
Map<String, Object> payer = new HashMap<String, Object>();
payer.put("openid", openId);
params.put("payer", payer);
} catch (Exception e) {
e.printStackTrace();
}
return params;
}
/**
* 获取微信支付H5参数
*
* @param orderNo
* @param appId
* @param mchId
* @param body
* @param money
* @param attach
* @param notifyUrl
* @param returnUrl
* @return
*/
public Map<String, Object> getH5PayParams(String orderNo, String appId, String mchId, String body, String money, String attach, String notifyUrl, String returnUrl, String ip) {
Map<String, Object> params = new HashMap<String, Object>();
try {
params.put("appid", appId);
params.put("mchid", mchId);
params.put("description", body);
params.put("out_trade_no", orderNo);
if (!StringUtil.isBlank(attach)) {
params.put("attach", attach);
}
params.put("notify_url", notifyUrl);
Map<String, Object> amount = new HashMap<String, Object>();
amount.put("total", Integer.valueOf(MoneyUtil.getMoney(money)));
params.put("amount", amount);
Map<String, Object> scene_info = new HashMap<String, Object>();
scene_info.put("payer_client_ip", ip);
Map<String, Object> h5_info = new HashMap<String, Object>();
h5_info.put("type", "Wap");
h5_info.put("app_url", returnUrl);
scene_info.put("h5_info", h5_info);
params.put("scene_info", scene_info);
} catch (Exception e) {
e.printStackTrace();
}
return params;
}
/**
* 获取微信APP支付参数
*
* @param orderNo
* @param appId
* @param mchId
* @param body
* @param money
* @param attach
* @param notifyUrl
* @return
*/
public Map<String, Object> getAppPayParams(String orderNo, String appId, String mchId, String body, String money, String attach, String notifyUrl) {
Map<String, Object> params = new HashMap<String, Object>();
try {
params.put("appid", appId);
params.put("mchid", mchId);
params.put("description", body);
params.put("out_trade_no", orderNo);
if (!StringUtil.isBlank(attach)) {
params.put("attach", attach);
}
params.put("notify_url", notifyUrl);
Map<String, Object> amount = new HashMap<String, Object>();
amount.put("total", Integer.valueOf(MoneyUtil.getMoney(money)));
params.put("amount", amount);
} catch (Exception e) {
e.printStackTrace();
}
return params;
}
/**
* JSAPI支付调起签名
*
* @param appId
* @param prepayId
* @param wxPayAccountConfig
* @return
*/
public static Map<String, String> jsApiCreateSign(String appId, String prepayId, WxPayAccountConfig wxPayAccountConfig) {
Map<String, String> packageParams = null;
try {
String timeStamp = String.valueOf(System.currentTimeMillis() / 1000);
String nonceStr = String.valueOf(System.currentTimeMillis());
String packageStr = "prepay_id=" + prepayId;
packageParams = new HashMap<>(6);
packageParams.put("appId", appId);
packageParams.put("timeStamp", timeStamp);
packageParams.put("nonceStr", nonceStr);
packageParams.put("package", packageStr);
packageParams.put("signType", SignType.RSA.toString());
ArrayList<String> list = new ArrayList<>();
list.add(appId);
list.add(timeStamp);
list.add(nonceStr);
list.add(packageStr);
String packageSign = PayKit.createSign(
PayKit.buildSignMessage(list),
wxPayAccountConfig.getPrivateKey()
);
packageParams.put("paySign", packageSign);
} catch (Exception e) {
e.printStackTrace();
}
return packageParams;
}
/**
* APP调起支付签名
*
* @param appId
* @param prepayId
* @param wxPayAccountConfig
* @return
*/
public static Map<String, String> appCreateSign(String appId, String prepayId, WxPayAccountConfig wxPayAccountConfig) {
Map<String, String> packageParams = null;
try {
String timeStamp = String.valueOf(System.currentTimeMillis() / 1000);
String nonceStr = String.valueOf(System.currentTimeMillis());
packageParams = new HashMap<>(8);
packageParams.put("appid", appId);
packageParams.put("partnerid", wxPayAccountConfig.getMchId());
packageParams.put("prepayid", prepayId);
packageParams.put("package", "Sign=WXPay");
packageParams.put("timestamp", timeStamp);
packageParams.put("noncestr", nonceStr);
packageParams.put("signType", SignType.RSA.toString());
ArrayList<String> list = new ArrayList<>();
list.add(appId);
list.add(timeStamp);
list.add(nonceStr);
list.add(prepayId);
String packageSign = PayKit.createSign(
PayKit.buildSignMessage(list),
wxPayAccountConfig.getPrivateKey()
);
packageParams.put("sign", packageSign);
} catch (Exception e) {
e.printStackTrace();
}
return packageParams;
}
/**
* 构建微信支付退款参数
*
* @param orderNo
* @param payNo
* @param refundNo
* @param orderMoney
* @param refundMoney
* @param reason
* @param notifyUrl
* @return
*/
public Map<String, Object> getRefundParams(String orderNo, String payNo, String refundNo, String orderMoney, String refundMoney, String reason, String notifyUrl) {
Map<String, Object> params = new HashMap<String, Object>();
try {
params.put("out_refund_no", refundNo);
if (!StringUtil.isBlank(orderNo)) {
params.put("out_trade_no", orderNo);
}
if (!StringUtil.isBlank(payNo)) {
params.put("transaction_id", payNo);
}
params.put("reason", reason);
params.put("notify_url", notifyUrl);
Map<String, Object> amount = new HashMap<String, Object>();
amount.put("refund", Integer.valueOf(MoneyUtil.getMoney(refundMoney)));
amount.put("total", Integer.valueOf(MoneyUtil.getMoney(orderMoney)));
amount.put("currency", "CNY");
params.put("amount", amount);
} catch (Exception e) {
e.printStackTrace();
}
return params;
}
/**
* 构建微信查询订单参数
*
* @param mchId
* @return
*/
public Map<String, String> getOrderInfoParams(String mchId) {
Map<String, String> params = new HashMap<String, String>();
params.put("mchid", mchId);
return params;
}
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.plugin.pay.entity.AliPayAccountConfig;
/**
* 视图实体类
*
* @author BladeX
* @since 2021-12-31
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Schema(description = "AliPayAccountConfigVO对象")
public class AliPayAccountConfigVO extends AliPayAccountConfig {
private static final long serialVersionUID = 1L;
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.plugin.pay.entity.MergePayConfig;
/**
* 视图实体类
*
* @author BladeX
* @since 2022-06-27
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Schema(description = "MergePayConfigVO对象")
public class MergePayConfigVO extends MergePayConfig {
private static final long serialVersionUID = 1L;
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.plugin.pay.entity.Order;
/**
* 视图实体类
*
* @author BladeX
* @since 2021-12-31
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Schema(description = "OrderVO对象")
public class OrderVO extends Order {
private static final long serialVersionUID = 1L;
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.plugin.pay.entity.Refund;
/**
* 订单退款表视图实体类
*
* @author BladeX
* @since 2022-01-03
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Schema(description = "订单退款表")
public class RefundVO extends Refund {
private static final long serialVersionUID = 1L;
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.plugin.pay.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.plugin.pay.entity.WxPayAccountConfig;
/**
* 视图实体类
*
* @author BladeX
* @since 2021-12-31
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Schema(description = "WxpayAccountConfigVO对象")
public class WxPayAccountConfigVO extends WxPayAccountConfig {
private static final long serialVersionUID = 1L;
}