Bladeren bron

二手支付

plf 4 jaren geleden
bovenliggende
commit
5cf4d891bf

+ 5 - 0
base-module/src/main/java/com/caimei/module/base/entity/bo/Payment.java

@@ -67,4 +67,9 @@ public class Payment implements Serializable {
      * 微信公众号state参数
      */
     private String state;
+
+    /**
+     * 二手发布商品id
+     */
+    private Integer productId;
 }

+ 3 - 0
pay/src/main/java/com/caimei/module/pay/dao/PayDao.java

@@ -1,5 +1,6 @@
 package com.caimei.module.pay.dao;
 
+import com.caimei.module.base.entity.po.SeconHandProduct;
 import com.caimei.module.base.entity.vo.*;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -36,4 +37,6 @@ public interface PayDao {
     UserVo findUser(Long userID);
 
     List<OrderProductVo> fandAllOrderProduct(Integer orderId);
+
+    void updateSeconHand(SeconHandProduct seconHandProduct);
 }

+ 17 - 0
pay/src/main/java/com/caimei/module/pay/service/PayService.java

@@ -63,4 +63,21 @@ public interface PayService {
      * @return
      */
     JsonModel findOrderStatus(String mbOrderId);
+
+    /**
+     * 二手交易发布信息,银联,支付宝,微信
+     *
+     * @param payment 支付信息
+     * @param request
+     * @return
+     */
+    JsonModel secondHandPay(Payment payment, HttpServletRequest request);
+
+    /**
+     * 二手支付异步通知回调
+     *
+     * @param data 回调参数
+     * @return
+     */
+    String secondHandPayCallBack(String data) throws Exception;
 }

+ 114 - 14
pay/src/main/java/com/caimei/module/pay/service/impl/PayServiceImpl.java

@@ -3,6 +3,7 @@ package com.caimei.module.pay.service.impl;
 import com.alibaba.fastjson.JSONObject;
 import com.caimei.module.base.entity.bo.JsonModel;
 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.pay.dao.PayDao;
 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());
         DiscernReceiptVo discernReceipt = new DiscernReceiptVo();
         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.setReceiptStatus("3");
         discernReceipt.setReceiptAmount(amount);
         discernReceipt.setConfirmType("4");
         discernReceipt.setRePayFlag("1");
-        discernReceipt.setFormData(data);
+        discernReceipt.setFormData(json.toJSONString());
         discernReceipt.setReceiptDate(curDateStr);
         discernReceipt.setConfirmDate(curDateStr);
         discernReceipt.setReviewDate(curDateStr);
@@ -291,6 +280,25 @@ public class PayServiceImpl implements PayService {
         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
     public JsonModel payLink(OrderPayLinkVo orderPayLink) {
         if (null == orderPayLink) {
@@ -401,4 +409,96 @@ public class PayServiceImpl implements PayService {
         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";
+    }
 }

+ 13 - 0
pay/src/main/resources/com-caimei-module-pay/PayMapper.xml

@@ -363,4 +363,17 @@
         WHERE
           userID = #{userID}
     </select>
+
+    <update id="updateSeconHand">
+        UPDATE
+          cm_second_hand_detail
+        SET
+          payStatus = '2',
+          payAmount = #{payAmount},
+          payFormData = #{payFormData},
+          payType = #{payType},
+          payDate = NOW()
+        WHERE
+          productID = #{productID}
+    </update>
 </mapper>