From 7f380994a4f2f5d84a4f2fcbfa97b8c0001b5119 Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Sat, 24 Jul 2021 15:54:01 +0800 Subject: [PATCH] =?UTF-8?q?'=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cweb/controller/HighTestController.java | 2 +- .../com/cweb/controller/tPigController.java | 2 +- .../com/hai/common/pay/entity/OrderType.java | 1 + .../java/com/hai/config/QianZhuConfig.java | 74 ++++++++++++++----- .../service/impl/HighQzOrderServiceImpl.java | 21 ++++++ .../pay/impl/MobileOrderServiceImpl.java | 52 +++++++++++++ 6 files changed, 130 insertions(+), 22 deletions(-) create mode 100644 hai-service/src/main/java/com/hai/service/pay/impl/MobileOrderServiceImpl.java diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighTestController.java b/hai-cweb/src/main/java/com/cweb/controller/HighTestController.java index 224a4426..88c15993 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighTestController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighTestController.java @@ -177,7 +177,7 @@ public class HighTestController { @ApiOperation(value = "测试") public ResponseData test2() { try { - return ResponseMsgUtil.success(QianZhuConfig.getKfcOrderByOrderNo("20210712230130341045846")); + return ResponseMsgUtil.success(QianZhuConfig.getMobileOrderByOrderNo("20210724151253346003684")); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); return ResponseMsgUtil.exception(e); diff --git a/hai-cweb/src/main/java/com/cweb/controller/tPigController.java b/hai-cweb/src/main/java/com/cweb/controller/tPigController.java index c6ad0469..6a1519aa 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/tPigController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/tPigController.java @@ -87,7 +87,7 @@ public class tPigController { String url = ""; if (token.getBoolean("success")) { JSONObject data = token.getJSONObject("data"); - url = "https://m-test.qianzhu8.com/mobile/?platformId=" + CommonSysConst.getSysConfig().getQinzhuPlatformId() + "&token=" + data.getString("accessToken"); + url = "https://m.qianzhu8.com/mobile/?platformId=" + CommonSysConst.getSysConfig().getQinzhuPlatformId() + "&token=" + data.getString("accessToken"); } return ResponseMsgUtil.success(url); } catch (Exception e) { diff --git a/hai-service/src/main/java/com/hai/common/pay/entity/OrderType.java b/hai-service/src/main/java/com/hai/common/pay/entity/OrderType.java index 1f251d4e..90fc2bf6 100644 --- a/hai-service/src/main/java/com/hai/common/pay/entity/OrderType.java +++ b/hai-service/src/main/java/com/hai/common/pay/entity/OrderType.java @@ -6,6 +6,7 @@ public enum OrderType { RECHARGE_ORDER("RECHARGE_ORDER", "rechargeOrderService", "充值订单"), KFC_ORDER("KFC", "kfcOrderService", "KFC订单"), CINEMA_ORDER("CINEMA", "cinemaOrderService", "电影票订单"), + MOBILE_ORDER("MOBILE", "mobileOrderService", "话费充值订单"), TEST("TEST", "testPayService", "支付测试"), ; diff --git a/hai-service/src/main/java/com/hai/config/QianZhuConfig.java b/hai-service/src/main/java/com/hai/config/QianZhuConfig.java index 497f328a..a54dd5fb 100644 --- a/hai-service/src/main/java/com/hai/config/QianZhuConfig.java +++ b/hai-service/src/main/java/com/hai/config/QianZhuConfig.java @@ -27,7 +27,7 @@ import java.util.*; public class QianZhuConfig { /** - * 生成Token + * 获取Token * @param platformUniqueId 用户唯一id * @param nickname 昵称 * @param mobile 电话号码 @@ -44,25 +44,6 @@ public class QianZhuConfig { return HttpsUtils.doGet(CommonSysConst.getSysConfig().getQinzhuUrl()+"/api/v2/platform/getToken", map); } - public static JSONObject getMobileToken(String platformUniqueId,String nickname,String mobile) throws Exception { - Map contentMap = new LinkedHashMap<>(); - contentMap.put("platformUniqueId", platformUniqueId); - contentMap.put("nickname", nickname); - contentMap.put("mobile", mobile); - - Map map = new HashMap<>(); - map.put("platformId", "10458"); - map.put("action", "users.getTokenV2"); - map.put("version", "1.0"); - map.put("content", JSON.toJSONString(contentMap)); - map.put("traceId", WxUtils.makeNonStr()); - map.put("timestamp", new Date().getTime()); - map.put("sign", MD5Util.encode(generateSignature(map,"nnl3gg4ss0pka11t").getBytes()).toLowerCase()); - // return HttpsUtils.doPost(CommonSysConst.getSysConfig().getQinzhuMobileUrl()+"/gateway", JSON.toJSONString(map)); - return HttpsUtils.doPost("https://live.qianzhu8.com/gateway", JSON.toJSONString(map)); - } - - /** * KFC * 根据订单号查询订单详情 @@ -128,6 +109,59 @@ public class QianZhuConfig { return HttpsUtils.doPost(CommonSysConst.getSysConfig().getQinzhuUrl()+"/openApi/v1/orders/payMovieOrder", JSONObject.toJSONString(map)); } + + /** + * 获取话费充值Token + * @param platformUniqueId 用户唯一id + * @param nickname 昵称 + * @param mobile 电话号码 + * @return Token + */ + public static JSONObject getMobileToken(String platformUniqueId,String nickname,String mobile) throws Exception { + Map contentMap = new LinkedHashMap<>(); + contentMap.put("platformUniqueId", platformUniqueId); + contentMap.put("nickname", nickname); + contentMap.put("mobile", mobile); + + Map map = new HashMap<>(); + map.put("platformId", "10458"); + map.put("action", "users.getTokenV2"); + map.put("version", "1.0"); + map.put("content", JSON.toJSONString(contentMap)); + map.put("traceId", WxUtils.makeNonStr()); + map.put("timestamp", new Date().getTime()); + map.put("sign", MD5Util.encode(generateSignature(map,"nnl3gg4ss0pka11t").getBytes()).toLowerCase()); + return HttpsUtils.doPost("https://live.qianzhu8.com/gateway", JSON.toJSONString(map)); + } + + public static JSONObject getMobileOrderByOrderNo(String orderNo) throws Exception { + Map contentMap = new LinkedHashMap<>(); + contentMap.put("orderNo", orderNo); + Map map = new HashMap<>(); + map.put("platformId", "10458"); + map.put("action", "mobileOrders.pay"); + map.put("version", "1.0"); + map.put("content", JSON.toJSONString(contentMap)); + map.put("traceId", WxUtils.makeNonStr()); + map.put("timestamp", new Date().getTime()); + map.put("sign", MD5Util.encode(generateSignature(map,"nnl3gg4ss0pka11t").getBytes()).toLowerCase()); + return HttpsUtils.doPost("https://nf.qianzhu8.com/gateway", JSON.toJSONString(map)); + } + + public static JSONObject payMobileOrder(String orderNo) throws Exception { + Map contentMap = new LinkedHashMap<>(); + contentMap.put("orderNo", orderNo); + Map map = new HashMap<>(); + map.put("platformId", "10458"); + map.put("action", "mobileOrders.pay"); + map.put("version", "1.0"); + map.put("content", JSON.toJSONString(contentMap)); + map.put("traceId", WxUtils.makeNonStr()); + map.put("timestamp", new Date().getTime()); + map.put("sign", MD5Util.encode(generateSignature(map,"nnl3gg4ss0pka11t").getBytes()).toLowerCase()); + return HttpsUtils.doPost("https://nf.qianzhu8.com/gateway", JSON.toJSONString(map)); + } + /** * 生成签名 * @param data 数据 diff --git a/hai-service/src/main/java/com/hai/service/impl/HighQzOrderServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighQzOrderServiceImpl.java index 8dfe8c52..4b44edfb 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighQzOrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighQzOrderServiceImpl.java @@ -39,6 +39,10 @@ public class HighQzOrderServiceImpl implements HighQzOrderService { orderDetail = QianZhuConfig.getCinemaOrderByOrderNo(orderNo); } + if (orderType.equals("MOBILE")) { + orderDetail = QianZhuConfig.getMobileOrderByOrderNo(orderNo); + } + if (orderDetail != null && orderDetail.getBoolean("success") == true) { JSONObject data = orderDetail.getJSONObject("data"); HighOrder order = highOrderService.getOrderByOrderNo(orderNo); @@ -132,6 +136,23 @@ public class HighQzOrderServiceImpl implements HighQzOrderService { highOrder.getHighChildOrderList().add(highChildOrder); } + + if (orderType.equals("MOBILE")) { + highChildOrder = new HighChildOrder(); + highChildOrder.setMemId(highOrder.getMemId()); + highChildOrder.setGoodsType(6); + highChildOrder.setGoodsName("手机充值"+data.getString("rechargeDenomination")+"元"); + highChildOrder.setGoodsSpecName(data.getString("rechargeMobile")); + highChildOrder.setGoodsPrice(new BigDecimal(data.getString("rechargeDenomination"))); + highChildOrder.setGoodsActualPrice(new BigDecimal(data.getString("unitPrice"))); + highChildOrder.setSaleCount(data.getInteger("quantity")); + highChildOrder.setTotalPrice(new BigDecimal(highChildOrder.getSaleCount().toString()).multiply(highChildOrder.getGoodsPrice())); + highChildOrder.setGiveawayType(false); + highChildOrder.setChildOrdeStatus(1); + highChildOrder.setPraiseStatus(0); + // 计算原始价格 + highOrder.setTotalPrice(highChildOrder.getGoodsPrice().multiply(new BigDecimal(highChildOrder.getSaleCount().toString()))); + } } highOrderService.insertOrder(highOrder); return highOrder; diff --git a/hai-service/src/main/java/com/hai/service/pay/impl/MobileOrderServiceImpl.java b/hai-service/src/main/java/com/hai/service/pay/impl/MobileOrderServiceImpl.java new file mode 100644 index 00000000..16c018d5 --- /dev/null +++ b/hai-service/src/main/java/com/hai/service/pay/impl/MobileOrderServiceImpl.java @@ -0,0 +1,52 @@ +package com.hai.service.pay.impl; + +import com.hai.config.QianZhuConfig; +import com.hai.entity.HighChildOrder; +import com.hai.entity.HighOrder; +import com.hai.service.HighOrderService; +import com.hai.service.pay.PayService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.util.Date; +import java.util.Map; + +/** + * @author hurui + * @version 1.0 + * @ClassName MobileOrderServiceImpl + * @description: TODO + * @date 2021/7/24 15:51 + */ +@Service("mobileOrderService") +public class MobileOrderServiceImpl implements PayService { + + @Resource + private HighOrderService highOrderService; + + @Override + public void paySuccess(Map map, String payType) throws Exception { + if (payType.equals("Alipay")) { + return; + } + if (payType.equals("WechatPay")) { + HighOrder order = highOrderService.getOrderByOrderNo(map.get("out_trade_no")); + if (order != null && order.getOrderStatus() == 1) { + order.setPaySerialNo(map.get("transaction_id")); // 支付流水号 + order.setPayRealPrice(new BigDecimal(map.get("total_fee")).divide(new BigDecimal("100"))); // 实付金额 + order.setPayTime(new Date()); // 支付时间 + order.setPayModel(2); // 支付模式:1 金币,2 第三方平台,3 混合 + order.setPayType(2); // 支付方式: 1:支付宝 2:微信 3:金币 + order.setOrderStatus(2); // 订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 + + for (HighChildOrder childOrder : order.getHighChildOrderList()) { + childOrder.setChildOrdeStatus(2); // 子订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 + } + highOrderService.updateOrder(order); + // 支付给千猪 + QianZhuConfig.payMobileOrder(order.getOrderNo()); + } + } + } +}