|
@@ -10,6 +10,7 @@ import com.caimei365.order.mapper.OrderCommonMapper;
|
|
import com.caimei365.order.model.ResponseJson;
|
|
import com.caimei365.order.model.ResponseJson;
|
|
import com.caimei365.order.model.bo.PayParamBo;
|
|
import com.caimei365.order.model.bo.PayParamBo;
|
|
import com.caimei365.order.model.dto.PayDto;
|
|
import com.caimei365.order.model.dto.PayDto;
|
|
|
|
+import com.caimei365.order.model.dto.PayLinkDto;
|
|
import com.caimei365.order.model.po.BalanceRecordPo;
|
|
import com.caimei365.order.model.po.BalanceRecordPo;
|
|
import com.caimei365.order.model.po.DiscernReceiptPo;
|
|
import com.caimei365.order.model.po.DiscernReceiptPo;
|
|
import com.caimei365.order.model.po.OrderReceiptRelationPo;
|
|
import com.caimei365.order.model.po.OrderReceiptRelationPo;
|
|
@@ -20,9 +21,10 @@ import com.caimei365.order.model.vo.OrderProductVo;
|
|
import com.caimei365.order.model.vo.OrderVo;
|
|
import com.caimei365.order.model.vo.OrderVo;
|
|
import com.caimei365.order.service.PayOrderService;
|
|
import com.caimei365.order.service.PayOrderService;
|
|
import com.caimei365.order.service.RemoteCallService;
|
|
import com.caimei365.order.service.RemoteCallService;
|
|
|
|
+import com.caimei365.order.utils.CodeUtil;
|
|
import com.caimei365.order.utils.MathUtil;
|
|
import com.caimei365.order.utils.MathUtil;
|
|
|
|
+import com.caimei365.order.utils.Md5Util;
|
|
import com.caimei365.order.utils.PayUtil;
|
|
import com.caimei365.order.utils.PayUtil;
|
|
-import com.caimei365.order.utils.pay.HttpRequest;
|
|
|
|
import com.caimei365.order.utils.pay.RSAUtil;
|
|
import com.caimei365.order.utils.pay.RSAUtil;
|
|
import com.google.common.util.concurrent.AtomicDouble;
|
|
import com.google.common.util.concurrent.AtomicDouble;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -34,14 +36,10 @@ import org.springframework.http.HttpHeaders;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
-import java.math.BigDecimal;
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
import java.security.NoSuchAlgorithmException;
|
|
import java.security.spec.InvalidKeySpecException;
|
|
import java.security.spec.InvalidKeySpecException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
-import java.util.Date;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.util.*;
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -65,10 +63,13 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
private ProductService productService;
|
|
private ProductService productService;
|
|
@Resource
|
|
@Resource
|
|
private WeChatService weChatService;
|
|
private WeChatService weChatService;
|
|
- @Value("${caimei.notifyUrl}")
|
|
|
|
- private String notifyUrl;
|
|
|
|
@Resource
|
|
@Resource
|
|
private RemoteCallService remoteCallService;
|
|
private RemoteCallService remoteCallService;
|
|
|
|
+ @Value("${caimei.notifyUrl}")
|
|
|
|
+ private String notifyUrl;
|
|
|
|
+ @Value("${caimei.redirectLink}")
|
|
|
|
+ private String redirectLink;
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* 订单支付前效验付款规则
|
|
* 订单支付前效验付款规则
|
|
@@ -268,6 +269,54 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
return ResponseJson.success(map);
|
|
return ResponseJson.success(map);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 生成网银支付链接
|
|
|
|
+ *
|
|
|
|
+ * @param payLinkDto {
|
|
|
|
+ * orderId 订单ID
|
|
|
|
+ * }
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson<String> getPayLink(PayLinkDto payLinkDto) {
|
|
|
|
+ // 订单信息
|
|
|
|
+ OrderVo order = payOrderMapper.getOrderByOrderId(payLinkDto.getOrderId());
|
|
|
|
+ if (null == order) {
|
|
|
|
+ return ResponseJson.error("订单不存在", null);
|
|
|
|
+ }
|
|
|
|
+ // 时间戳
|
|
|
|
+ long time = System.currentTimeMillis() / 1000;
|
|
|
|
+ String linkLogo = CodeUtil.randomLetter(4);
|
|
|
|
+ try {
|
|
|
|
+ linkLogo = Md5Util.MD5To16Bit(linkLogo + time);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ Date date = new Date();
|
|
|
|
+ GregorianCalendar calendar = new GregorianCalendar();
|
|
|
|
+ calendar.setTime(date);
|
|
|
|
+ calendar.add(Calendar.DATE, 1);
|
|
|
|
+ OrderPayLinkVo orderPayLink = payOrderMapper.getOrderPayLink(payLinkDto.getOrderId(), null);
|
|
|
|
+ if (null == orderPayLink) {
|
|
|
|
+ orderPayLink = new OrderPayLinkVo();
|
|
|
|
+ orderPayLink.setOrderId(payLinkDto.getOrderId());
|
|
|
|
+ orderPayLink.setPayType(payLinkDto.getPayType());
|
|
|
|
+ orderPayLink.setUnpaidAmount(payLinkDto.getUnpaidAmount());
|
|
|
|
+ }
|
|
|
|
+ orderPayLink.setRedirectLink(redirectLink);
|
|
|
|
+ orderPayLink.setLinkLogo(linkLogo);
|
|
|
|
+ orderPayLink.setGenerateTime(date);
|
|
|
|
+ orderPayLink.setEffectiveTime(calendar.getTime());
|
|
|
|
+ orderPayLink.setPayStatus(0);
|
|
|
|
+ orderPayLink.setDelFlag(0);
|
|
|
|
+ if (null == orderPayLink.getId()) {
|
|
|
|
+ payOrderMapper.insertOrderPayLink(orderPayLink);
|
|
|
|
+ } else {
|
|
|
|
+ payOrderMapper.updateOrderPayLink(orderPayLink);
|
|
|
|
+ }
|
|
|
|
+ String link = orderPayLink.getRedirectLink() + "?linkLogo=" + linkLogo;
|
|
|
|
+ return ResponseJson.success(link);
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 微信线上支付
|
|
* 微信线上支付
|
|
*
|
|
*
|
|
@@ -282,7 +331,7 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
* @param headers HttpHeaders
|
|
* @param headers HttpHeaders
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public ResponseJson<JSONObject> weChatPay(PayDto payDto, HttpHeaders headers) {
|
|
|
|
|
|
+ public ResponseJson<JSONObject> payByWeChat(PayDto payDto, HttpHeaders headers) {
|
|
PayParamBo payParam = new PayParamBo();
|
|
PayParamBo payParam = new PayParamBo();
|
|
// payDto -> payParam
|
|
// payDto -> payParam
|
|
BeanUtils.copyProperties(payDto, payParam);
|
|
BeanUtils.copyProperties(payDto, payParam);
|
|
@@ -317,6 +366,61 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
payParam.setOpenId(openId);
|
|
payParam.setOpenId(openId);
|
|
payParam.setNotifyUrl(notifyUrl);
|
|
payParam.setNotifyUrl(notifyUrl);
|
|
log.info("【微信支付】>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>获取openId:" + openId);
|
|
log.info("【微信支付】>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>获取openId:" + openId);
|
|
|
|
+ return toPay(payParam, headers);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 支付宝线上支付
|
|
|
|
+ *
|
|
|
|
+ * @param payDto {
|
|
|
|
+ * orderId 订单ID
|
|
|
|
+ * payAmount 支付金额,单位分,必须大于2
|
|
|
|
+ * returnUrl 页面回调地址
|
|
|
|
+ * }
|
|
|
|
+ * @param headers
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson<JSONObject> payByAlipay(PayDto payDto, HttpHeaders headers) {
|
|
|
|
+ PayParamBo payParam = new PayParamBo();
|
|
|
|
+ // payDto -> payParam
|
|
|
|
+ BeanUtils.copyProperties(payDto, payParam);
|
|
|
|
+ //支付宝支付
|
|
|
|
+ payParam.setPayWay("ALIPAY");
|
|
|
|
+ payParam.setPayType("ALIPAY_H5");
|
|
|
|
+ payParam.setNotifyUrl(notifyUrl);
|
|
|
|
+ log.info("【支付宝支付】>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>orderId:" + payParam.getOrderId());
|
|
|
|
+ return toPay(payParam, headers);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 银联线上支付
|
|
|
|
+ *
|
|
|
|
+ * @param payDto {
|
|
|
|
+ * orderId 订单ID
|
|
|
|
+ * payAmount 支付金额,单位分,必须大于2
|
|
|
|
+ * returnUrl 页面回调地址
|
|
|
|
+ * bankCode 银行编码(银联支付使用)
|
|
|
|
+ * userType 用户类型(银联支付使用)企业:ENTERPRISE,个人:USER
|
|
|
|
+ * }
|
|
|
|
+ * @param headers
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson<JSONObject> payByUnionPay(PayDto payDto, HttpHeaders headers) {
|
|
|
|
+ PayParamBo payParam = new PayParamBo();
|
|
|
|
+ // payDto -> payParam
|
|
|
|
+ BeanUtils.copyProperties(payDto, payParam);
|
|
|
|
+ //支付宝支付
|
|
|
|
+ payParam.setPayWay("UNIONPAY");
|
|
|
|
+ payParam.setPayType("GATEWAY_UNIONPAY");
|
|
|
|
+ payParam.setNotifyUrl(notifyUrl);
|
|
|
|
+ log.info("【银联支付】>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>orderId:" + payParam.getOrderId());
|
|
|
|
+ return toPay(payParam, headers);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 线上支付
|
|
|
|
+ */
|
|
|
|
+ private ResponseJson<JSONObject> toPay(PayParamBo payParam, HttpHeaders headers) {
|
|
// 订单信息
|
|
// 订单信息
|
|
OrderVo order = payOrderMapper.getOrderByOrderId(payParam.getOrderId());
|
|
OrderVo order = payOrderMapper.getOrderByOrderId(payParam.getOrderId());
|
|
if (null == order) {
|
|
if (null == order) {
|
|
@@ -338,7 +442,7 @@ public class PayOrderServiceImpl implements PayOrderService {
|
|
return ResponseJson.error("已经线下支付过,只能线下支付!", null);
|
|
return ResponseJson.error("已经线下支付过,只能线下支付!", null);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- log.info("【微信支付】>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>本次付款金额:" + payParam.getPayAmount());
|
|
|
|
|
|
+ log.info(">>>>>>>>>>>>>>本次付款金额:" + payParam.getPayAmount());
|
|
if (MathUtil.compare(MathUtil.mul(order.getPayableAmount(), 100), payParam.getPayAmount()) < 0) {
|
|
if (MathUtil.compare(MathUtil.mul(order.getPayableAmount(), 100), payParam.getPayAmount()) < 0) {
|
|
return ResponseJson.error("付款金额错误!", null);
|
|
return ResponseJson.error("付款金额错误!", null);
|
|
}
|
|
}
|