|
@@ -3,6 +3,7 @@ package com.caimei.module.pay.service.impl;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.caimei.module.base.entity.bo.JsonModel;
|
|
import com.caimei.module.base.entity.bo.JsonModel;
|
|
import com.caimei.module.base.entity.bo.Payment;
|
|
import com.caimei.module.base.entity.bo.Payment;
|
|
|
|
+import com.caimei.module.base.entity.po.SeconHandProduct;
|
|
import com.caimei.module.base.entity.vo.*;
|
|
import com.caimei.module.base.entity.vo.*;
|
|
import com.caimei.module.pay.dao.PayDao;
|
|
import com.caimei.module.pay.dao.PayDao;
|
|
import com.caimei.module.pay.service.PayService;
|
|
import com.caimei.module.pay.service.PayService;
|
|
@@ -253,25 +254,13 @@ public class PayServiceImpl implements PayService {
|
|
String curDateStr = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date());
|
|
String curDateStr = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date());
|
|
DiscernReceiptVo discernReceipt = new DiscernReceiptVo();
|
|
DiscernReceiptVo discernReceipt = new DiscernReceiptVo();
|
|
discernReceipt.setPayWay("1");
|
|
discernReceipt.setPayWay("1");
|
|
- if ("ALIPAY_H5".equals(payType)) {
|
|
|
|
- //支付宝H5
|
|
|
|
- discernReceipt.setPayType("14");
|
|
|
|
- } else if ("JSAPI_WEIXIN".equals(payType)) {
|
|
|
|
- //微信公众号支付
|
|
|
|
- discernReceipt.setPayType("13");
|
|
|
|
- } else if ("MINIAPP_WEIXIN".equals(payType)) {
|
|
|
|
- //微信小程序支付
|
|
|
|
- discernReceipt.setPayType("15");
|
|
|
|
- } else {
|
|
|
|
- //银联
|
|
|
|
- discernReceipt.setPayType("12");
|
|
|
|
- }
|
|
|
|
|
|
+ discernReceipt.setPayType(getPayType(payType));
|
|
discernReceipt.setReceiptType("1");
|
|
discernReceipt.setReceiptType("1");
|
|
discernReceipt.setReceiptStatus("3");
|
|
discernReceipt.setReceiptStatus("3");
|
|
discernReceipt.setReceiptAmount(amount);
|
|
discernReceipt.setReceiptAmount(amount);
|
|
discernReceipt.setConfirmType("4");
|
|
discernReceipt.setConfirmType("4");
|
|
discernReceipt.setRePayFlag("1");
|
|
discernReceipt.setRePayFlag("1");
|
|
- discernReceipt.setFormData(data);
|
|
|
|
|
|
+ discernReceipt.setFormData(json.toJSONString());
|
|
discernReceipt.setReceiptDate(curDateStr);
|
|
discernReceipt.setReceiptDate(curDateStr);
|
|
discernReceipt.setConfirmDate(curDateStr);
|
|
discernReceipt.setConfirmDate(curDateStr);
|
|
discernReceipt.setReviewDate(curDateStr);
|
|
discernReceipt.setReviewDate(curDateStr);
|
|
@@ -291,6 +280,25 @@ public class PayServiceImpl implements PayService {
|
|
return "SUCCESS";
|
|
return "SUCCESS";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 支付状态转换
|
|
|
|
+ */
|
|
|
|
+ private String getPayType(String payType) {
|
|
|
|
+ if ("ALIPAY_H5".equals(payType)) {
|
|
|
|
+ //支付宝H5
|
|
|
|
+ return "14";
|
|
|
|
+ } else if ("JSAPI_WEIXIN".equals(payType)) {
|
|
|
|
+ //微信公众号支付
|
|
|
|
+ return "13";
|
|
|
|
+ } else if ("MINIAPP_WEIXIN".equals(payType)) {
|
|
|
|
+ //微信小程序支付
|
|
|
|
+ return "15";
|
|
|
|
+ } else {
|
|
|
|
+ //银联
|
|
|
|
+ return "12";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public JsonModel payLink(OrderPayLinkVo orderPayLink) {
|
|
public JsonModel payLink(OrderPayLinkVo orderPayLink) {
|
|
if (null == orderPayLink) {
|
|
if (null == orderPayLink) {
|
|
@@ -401,4 +409,96 @@ public class PayServiceImpl implements PayService {
|
|
return model.success(result);
|
|
return model.success(result);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public JsonModel secondHandPay(Payment payment, HttpServletRequest request) {
|
|
|
|
+ JSONObject result = null;
|
|
|
|
+ try {
|
|
|
|
+ // 时间戳
|
|
|
|
+ long time = System.currentTimeMillis() / 1000;
|
|
|
|
+ // 商户订单号
|
|
|
|
+ String orderId = payment.getProductId() + "#" + time;
|
|
|
|
+ //商品名称
|
|
|
|
+ String product = "采美订单" + orderId;
|
|
|
|
+ String userType = "ENTERPRISE";
|
|
|
|
+ //用户IP地址
|
|
|
|
+ String userIp = IPUtil.getIpAddr(request);
|
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
|
+ json.put("merAccount", merAccount);
|
|
|
|
+ json.put("merNo", merNo);
|
|
|
|
+ json.put("orderId", orderId);
|
|
|
|
+ json.put("time", time);
|
|
|
|
+ //支付金额
|
|
|
|
+ json.put("amount", payment.getPayAmount());
|
|
|
|
+ json.put("product", product);
|
|
|
|
+ json.put("payWay", payment.getPayWay());
|
|
|
|
+ json.put("payType", payment.getPayType());
|
|
|
|
+ json.put("userIp", userIp);
|
|
|
|
+ json.put("returnUrl", payment.getReturnUrl());
|
|
|
|
+ json.put("notifyUrl", payment.getNotifyUrl());
|
|
|
|
+ String attach = payment.getProductId() + "," + payment.getPayType();
|
|
|
|
+ json.put("attach", attach);
|
|
|
|
+ if (null != payment.getBankCode()) {
|
|
|
|
+ json.put("bankCode", payment.getBankCode());
|
|
|
|
+ }
|
|
|
|
+ json.put("userType", userType);
|
|
|
|
+ if (null != payment.getOrderId()) {
|
|
|
|
+ json.put("openId", payment.getOpenid());
|
|
|
|
+ }
|
|
|
|
+ String sign = PayUtils.buildSign(json, merKey);
|
|
|
|
+ json.put("sign", sign);
|
|
|
|
+ String data = "";
|
|
|
|
+ try {
|
|
|
|
+ data = PayUtils.buildDataPrivate(json, merKey);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ result = PayUtils.httpGet("https://platform.mhxxkj.com/paygateway/mbpay/order/v1", merAccount, data);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return model.error("支付失败");
|
|
|
|
+ }
|
|
|
|
+ String code = result.getString("code");
|
|
|
|
+ if (!"000000".equals(code)) {
|
|
|
|
+ String msg = result.getString("msg");
|
|
|
|
+ log.info("第三方支付失败>>>>>>>msg:" + msg);
|
|
|
|
+ return model.error(msg);
|
|
|
|
+ }
|
|
|
|
+ return model.success(result);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String secondHandPayCallBack(String data) throws Exception {
|
|
|
|
+ //公钥解密
|
|
|
|
+ JSONObject json = PayUtils.decryptDataPublic(data, publicKey);
|
|
|
|
+ log.info("公钥解密>>>>>>" + json);
|
|
|
|
+ //公钥验签
|
|
|
|
+ String signaa = json.getString("sign");
|
|
|
|
+ json.remove("sign");
|
|
|
|
+ String signbb = PayUtils.buildSign(json, publicKey);
|
|
|
|
+ if (!signaa.equals(signbb)) {
|
|
|
|
+ return "验签失败";
|
|
|
|
+ }
|
|
|
|
+ //订单状态
|
|
|
|
+ String orderStatus = json.getString("orderStatus");
|
|
|
|
+ //附加数据,下单时若有传输则原样返回,下单时为空,则不返回该数据
|
|
|
|
+ String attach = json.getString("attach");
|
|
|
|
+ //订单金额,以元为单位
|
|
|
|
+ BigDecimal amount = json.getBigDecimal("amount");
|
|
|
|
+ log.info("订单状态>>>>>>" + orderStatus);
|
|
|
|
+ if ("FAILED".equals(orderStatus)) {
|
|
|
|
+ return "支付失败";
|
|
|
|
+ }
|
|
|
|
+ String[] split = attach.split(",");
|
|
|
|
+ //订单id
|
|
|
|
+ Integer productId = Integer.valueOf(split[0]);
|
|
|
|
+ //支付类型
|
|
|
|
+ String payType = split[1];
|
|
|
|
+ SeconHandProduct seconHandProduct = new SeconHandProduct();
|
|
|
|
+ seconHandProduct.setPayAmount(amount.doubleValue());
|
|
|
|
+ seconHandProduct.setPayFormData(json.toJSONString());
|
|
|
|
+ seconHandProduct.setPayType(getPayType(payType));
|
|
|
|
+ seconHandProduct.setProductID(productId);
|
|
|
|
+ payDao.updateSeconHand(seconHandProduct);
|
|
|
|
+ return "SUCCESS";
|
|
|
|
+ }
|
|
}
|
|
}
|