|
|
@@ -17,6 +17,12 @@ import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alipay.api.AlipayClient;
|
|
|
+import com.alipay.api.DefaultAlipayClient;
|
|
|
+import com.alipay.api.diagnosis.DiagnosisUtils;
|
|
|
+import com.alipay.api.domain.AlipayTradeAppPayModel;
|
|
|
+import com.alipay.api.request.AlipayTradeAppPayRequest;
|
|
|
+import com.alipay.api.response.AlipayTradeAppPayResponse;
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.fs.common.constant.FsConstants;
|
|
|
@@ -74,6 +80,7 @@ import com.github.binarywang.wxpay.exception.WxPayException;
|
|
|
import com.github.binarywang.wxpay.service.WxPayService;
|
|
|
import com.google.common.reflect.TypeToken;
|
|
|
import com.google.gson.Gson;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
@@ -84,12 +91,15 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+
|
|
|
/**
|
|
|
* 套餐订单Service业务层处理
|
|
|
*
|
|
|
* @author fs
|
|
|
* @date 2023-08-25
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class FsPackageOrderServiceImpl implements IFsPackageOrderService
|
|
|
{
|
|
|
@@ -964,7 +974,7 @@ public class FsPackageOrderServiceImpl implements IFsPackageOrderService
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public R payment(FsPackageOrderDoPayParam param) {
|
|
|
+ public R payment(FsPackageOrderDoPayParam param, HttpServletRequest request) {
|
|
|
//更新订单状态
|
|
|
FsPackageOrder fsPackageOrder=fsPackageOrderMapper.selectFsPackageOrderByOrderId(param.getOrderId());
|
|
|
if(!fsPackageOrder.getStatus().equals(FsPackageOrderStatusEnum.STATUS_1.getValue())){
|
|
|
@@ -1008,7 +1018,9 @@ public class FsPackageOrderServiceImpl implements IFsPackageOrderService
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if(user!=null&& StringUtils.isNotEmpty(openId)){
|
|
|
+ if (user != null
|
|
|
+ && ( "appPay".equals(payConfigDTO.getType()) // appPay类型:跳过openId校验
|
|
|
+ || StringUtils.isNotEmpty(openId) )) {
|
|
|
if(fsPackageOrder.getPayMoney().compareTo(new BigDecimal(0))==1){
|
|
|
String payCode = OrderCodeUtils.getOrderSn();
|
|
|
if(StringUtils.isEmpty(payCode)){
|
|
|
@@ -1021,7 +1033,7 @@ public class FsPackageOrderServiceImpl implements IFsPackageOrderService
|
|
|
storePayment.setPayCode(payCode);
|
|
|
storePayment.setPayMoney(fsPackageOrder.getPayMoney());
|
|
|
storePayment.setCreateTime(new Date());
|
|
|
- storePayment.setPayTypeCode("weixin");
|
|
|
+ storePayment.setPayTypeCode(!"appPay".equals(payConfigDTO.getType()) ? "weixin" : param.getPayType());
|
|
|
storePayment.setBusinessType(3);
|
|
|
storePayment.setCompanyId(fsPackageOrder.getCompanyId());
|
|
|
storePayment.setCompanyUserId(fsPackageOrder.getCompanyUserId());
|
|
|
@@ -1132,6 +1144,65 @@ public class FsPackageOrderServiceImpl implements IFsPackageOrderService
|
|
|
mt.setAppId(appId);
|
|
|
storePaymentService.updateFsStorePayment(mt);
|
|
|
return R.ok().put("isPay", 0).put("data", result).put("type", "hf");
|
|
|
+ } else if (payConfigDTO.getType().equals("appPay") && "wx".equals(param.getPayType())) {
|
|
|
+ //创建微信订单
|
|
|
+ WxPayConfig payConfig = new WxPayConfig();
|
|
|
+ SysConfig sysConfig = sysConfigMapper.selectConfigByConfigKey("his.pay");
|
|
|
+ FsPayConfig fsPayConfig = new Gson().fromJson(sysConfig.getConfigValue(), FsPayConfig.class);
|
|
|
+ payConfig.setAppId(appId);
|
|
|
+ payConfig.setMchId(fsPayConfig.getWxAppMchId());
|
|
|
+ payConfig.setMchKey(fsPayConfig.getWxAppMchKey());
|
|
|
+ payConfig.setSubAppId(org.apache.commons.lang3.StringUtils.trimToNull(null));
|
|
|
+ payConfig.setSubMchId(org.apache.commons.lang3.StringUtils.trimToNull(null));
|
|
|
+ payConfig.setKeyPath(null);
|
|
|
+ payConfig.setNotifyUrl(fsPayConfig.getWxAppNotifyUrl());
|
|
|
+ wxPayService.setConfig(payConfig);
|
|
|
+ WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
|
|
|
+ orderRequest.setBody("套餐包订单支付");
|
|
|
+ orderRequest.setOutTradeNo("package-"+storePayment.getPayCode());
|
|
|
+ orderRequest.setTotalFee(WxPayUnifiedOrderRequest.yuanToFen(storePayment.getPayMoney().toString()));
|
|
|
+ orderRequest.setTradeType("APP");
|
|
|
+ orderRequest.setSpbillCreateIp(IpUtils.getIpAddr(request));
|
|
|
+ orderRequest.setNotifyUrl(fsPayConfig.getNotifyUrlScrm());
|
|
|
+ //调用统一下单接口,获取"预支付交易会话标识"
|
|
|
+ try {
|
|
|
+ Object result = wxPayService.createOrder(orderRequest);
|
|
|
+ return R.ok().put("data",result).put("type","wxApp").put("isPay",0);
|
|
|
+ } catch (WxPayException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new CustomException("支付失败"+e.getMessage());
|
|
|
+ }
|
|
|
+ } else if (payConfigDTO.getType().equals("appPay") && "ali".equals(param.getPayType())) {
|
|
|
+ // 实例化客户端
|
|
|
+ SysConfig sysConfig = sysConfigMapper.selectConfigByConfigKey("his.pay");
|
|
|
+ FsPayConfig fsPayConfig = new Gson().fromJson(sysConfig.getConfigValue(), FsPayConfig.class);
|
|
|
+ AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", fsPayConfig.getAliAppId(), fsPayConfig.getAliPrivateKey(), "json", "utf-8", fsPayConfig.getAliPublicKey(), "RSA2");
|
|
|
+
|
|
|
+ // 构造请求参数以调用接口
|
|
|
+ AlipayTradeAppPayRequest aliRequest = new AlipayTradeAppPayRequest();
|
|
|
+ AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
|
|
|
+ // 商户订单号
|
|
|
+ model.setOutTradeNo("package-" + storePayment.getPayCode());
|
|
|
+ // 订单总金额
|
|
|
+ model.setTotalAmount(storePayment.getPayMoney().toString());
|
|
|
+ // 订单标题r
|
|
|
+ model.setSubject("套餐包订单支付");
|
|
|
+
|
|
|
+ aliRequest.setBizModel(model);
|
|
|
+ aliRequest.setNotifyUrl(fsPayConfig.getAliNotifyUrl());
|
|
|
+
|
|
|
+ try {
|
|
|
+ AlipayTradeAppPayResponse result = alipayClient.sdkExecute(aliRequest);
|
|
|
+ if (!result.isSuccess()) {
|
|
|
+ String diagnosisUrl = DiagnosisUtils.getDiagnosisUrl(result);
|
|
|
+ log.error("支付宝支付调用失败 诊断链接:{}", diagnosisUrl);
|
|
|
+ throw new CustomException(result.getSubMsg());
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.ok().put("isPay", 0).put("data", result).put("type", "aliPay");
|
|
|
+ } catch (Exception e){
|
|
|
+ log.info("支付宝支付异常: {}", e);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|