Commit 1ef7cc88 authored by liuyang's avatar liuyang

添加支付宝app付款支持

parent 59df2705
package com.qkdata.alipay.service; package com.qkdata.alipay.service;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alipay.api.*; import com.alipay.api.*;
import com.alipay.api.domain.AlipayTradeAppPayModel;
import com.alipay.api.domain.AlipayTradeCloseModel; import com.alipay.api.domain.AlipayTradeCloseModel;
import com.alipay.api.domain.AlipayTradeQueryModel; import com.alipay.api.domain.AlipayTradeQueryModel;
import com.alipay.api.domain.AlipayTradeWapPayModel; import com.alipay.api.domain.AlipayTradeWapPayModel;
import com.alipay.api.request.AlipayTradeAppPayRequest;
import com.alipay.api.request.AlipayTradeCloseRequest; import com.alipay.api.request.AlipayTradeCloseRequest;
import com.alipay.api.request.AlipayTradeQueryRequest; import com.alipay.api.request.AlipayTradeQueryRequest;
import com.alipay.api.request.AlipayTradeWapPayRequest; import com.alipay.api.request.AlipayTradeWapPayRequest;
import com.alipay.api.response.AlipayTradeAppPayResponse;
import com.alipay.api.response.AlipayTradeCloseResponse; import com.alipay.api.response.AlipayTradeCloseResponse;
import com.alipay.api.response.AlipayTradeQueryResponse; import com.alipay.api.response.AlipayTradeQueryResponse;
import com.alipay.api.response.AlipayTradeWapPayResponse; import com.alipay.api.response.AlipayTradeWapPayResponse;
import com.qkdata.alipay.config.AlipayProperties; import com.qkdata.alipay.config.AlipayProperties;
import com.qkdata.biz.enums.PaySourceEnum;
import com.qkdata.biz.management.entity.ProductOrderPO;
import com.qkdata.common.base.exception.BusinessException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
...@@ -49,23 +56,58 @@ public class AlipayService { ...@@ -49,23 +56,58 @@ public class AlipayService {
/** /**
* 统一下单调用 * 统一下单调用
* @param model * @param orderPO
* @param source
* @param returnUrl
* @return * @return
* @throws AlipayApiException * @throws AlipayApiException
*/ */
public String prePayOrder(AlipayTradeWapPayModel model) throws AlipayApiException { public Object prePayOrder(ProductOrderPO orderPO, PaySourceEnum source, String returnUrl) throws AlipayApiException {
AlipayTradeWapPayRequest alipay_request=new AlipayTradeWapPayRequest(); AlipayRequest alipay_request=null;
alipay_request.setBizModel(model); if (source == PaySourceEnum.MWEB){
AlipayTradeWapPayModel requestObj = new AlipayTradeWapPayModel();
requestObj.setOutTradeNo(orderPO.getOrderNo());
requestObj.setSubject(orderPO.getOrderName());
requestObj.setTotalAmount(orderPO.getPaymentMoney().toString());
requestObj.setProductCode("QUICK_WAP_WAY");
requestObj.setQuitUrl(returnUrl+"&result=true");
alipay_request = new AlipayTradeWapPayRequest();
alipay_request.setBizModel(requestObj);
alipay_request.setNotifyUrl(frontendDomain + "/online-edu-backend/alipay/notify/order");
alipay_request.setReturnUrl(returnUrl+"&result=true");
}else if (source == PaySourceEnum.APP){
AlipayTradeAppPayModel requestObj = new AlipayTradeAppPayModel();
requestObj.setGoodsType("1");
requestObj.setOutTradeNo(orderPO.getOrderNo());
requestObj.setSubject(orderPO.getOrderName());
requestObj.setTotalAmount(orderPO.getPaymentMoney().toString());
requestObj.setProductCode("QUICK_MSECURITY_PAY");
alipay_request = new AlipayTradeAppPayRequest();
alipay_request.setBizModel(requestObj);
alipay_request.setNotifyUrl(frontendDomain + "/online-edu-backend/alipay/notify/order"); alipay_request.setNotifyUrl(frontendDomain + "/online-edu-backend/alipay/notify/order");
alipay_request.setReturnUrl(model.getQuitUrl()+"&result=true");
String form = ""; }else {
AlipayTradeWapPayResponse response = alipayClient.pageExecute(alipay_request); throw new BusinessException("暂不支持该支付类型。source:"+source);
}
Object rtObj = null;
AlipayResponse response = null;
if (source == PaySourceEnum.MWEB){
response = alipayClient.pageExecute(alipay_request);
}else if (source == PaySourceEnum.APP){
response = alipayClient.sdkExecute(alipay_request);
}else {
throw new BusinessException("暂不支持该支付类型。source:"+source);
}
if (response.isSuccess()){ if (response.isSuccess()){
form = response.getBody(); rtObj = response.getBody();
return rtObj;
}else { }else {
log.info("Alipay prePay request faild:"+ JSONObject.toJSONString(response)); log.info("Alipay prePay request faild:"+ JSONObject.toJSONString(response));
} }
return form; return rtObj;
} }
/** /**
......
...@@ -134,15 +134,9 @@ public class ProductOrderService extends ServiceImpl<ProductOrderMapper, Product ...@@ -134,15 +134,9 @@ public class ProductOrderService extends ServiceImpl<ProductOrderMapper, Product
throw new BusinessException("微信支付异常"); throw new BusinessException("微信支付异常");
} }
}else if (orderPO.getPayMethod() == PayMethodEnum.AliPay){ }else if (orderPO.getPayMethod() == PayMethodEnum.AliPay){
AlipayTradeWapPayModel payModel = new AlipayTradeWapPayModel();
payModel.setOutTradeNo(orderPO.getOrderNo());
payModel.setSubject(orderPO.getOrderName());
payModel.setTotalAmount(orderPO.getPaymentMoney().toString());
payModel.setQuitUrl(returnUrl+"&result=true");
payModel.setProductCode("QUICK_WAP_WAY");
try { try {
String form = alipayService.prePayOrder(payModel); Object rtObj = alipayService.prePayOrder(orderPO,source,returnUrl);
return form; return rtObj;
} catch (AlipayApiException e) { } catch (AlipayApiException e) {
log.error(e.getMessage(),e); log.error(e.getMessage(),e);
throw new BusinessException("支付宝创建订单异常"); throw new BusinessException("支付宝创建订单异常");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment