@Test public void testCreateTemporaryOrder() throws Exception { OrderFormData data = new OrderFormData(); List<CommodityAmount> amounts = new ArrayList<>(); CommodityAmount commodityAmount = new CommodityAmount(); commodityAmount.setAmount(10); commodityAmount.setCommodityId(100L); amounts.add(commodityAmount); data.setCaList(amounts); Orders orders = new Orders(); orders.setPrice(10); orders.setId(200l); orders.setUserAccountId(400l); data.setOrder(orders); JSONObject temporaryOrder = payService.createTemporaryOrder(data); String id = temporaryOrder.getString("id"); String order = temporaryOrder.getString("order"); System.out.println(id); System.out.println(order); }
public JSONObject createTemporaryOrder(OrderFormData data){ int totalPrice = 0; List<CommodityAmount> caList = data.getCaList(); for (CommodityAmount info:caList){ totalPrice+=info.getAmount(); } JSONObject info = new JSONObject(); try { Long orderId = OrderUtils.getOrderId(); data.getOrder().setId(orderId); data.getOrder().setPrice(totalPrice); String orderAttach = JSON.toJSONString(data); String order = OrderUtils.createAlipayInfo(orderAttach,String.valueOf(orderId),"惊喜商城-"+orderId,"惊喜商城",String.valueOf(totalPrice)); info.put("id",orderId); info.put("order",order); putCacheOrderFormData(data); } catch (Exception e) { e.printStackTrace(); LOG.error("订单创建失败",e); throw new RuntimeException("订单创建失败"); } return info; }
AliPayServiceImpl implements IAliPayService { public JSONObject createTemporaryOrder(OrderFormData data){ int totalPrice = 0; List<CommodityAmount> caList = data.getCaList(); for (CommodityAmount info:caList){ totalPrice+=info.getAmount(); } JSONObject info = new JSONObject(); try { Long orderId = OrderUtils.getOrderId(); data.getOrder().setId(orderId); data.getOrder().setPrice(totalPrice); String orderAttach = JSON.toJSONString(data); String order = OrderUtils.createAlipayInfo(orderAttach,String.valueOf(orderId),"惊喜商城-"+orderId,"惊喜商城",String.valueOf(totalPrice)); info.put("id",orderId); info.put("order",order); putCacheOrderFormData(data); } catch (Exception e) { e.printStackTrace(); LOG.error("订单创建失败",e); throw new RuntimeException("订单创建失败"); } return info; } }
AliPayServiceImpl implements IAliPayService { public JSONObject createTemporaryOrder(OrderFormData data){ int totalPrice = 0; List<CommodityAmount> caList = data.getCaList(); for (CommodityAmount info:caList){ totalPrice+=info.getAmount(); } JSONObject info = new JSONObject(); try { Long orderId = OrderUtils.getOrderId(); data.getOrder().setId(orderId); data.getOrder().setPrice(totalPrice); String orderAttach = JSON.toJSONString(data); String order = OrderUtils.createAlipayInfo(orderAttach,String.valueOf(orderId),"惊喜商城-"+orderId,"惊喜商城",String.valueOf(totalPrice)); info.put("id",orderId); info.put("order",order); putCacheOrderFormData(data); } catch (Exception e) { e.printStackTrace(); LOG.error("订单创建失败",e); throw new RuntimeException("订单创建失败"); } return info; }  }
AliPayServiceImpl implements IAliPayService { public JSONObject createTemporaryOrder(OrderFormData data){ int totalPrice = 0; List<CommodityAmount> caList = data.getCaList(); for (CommodityAmount info:caList){ totalPrice+=info.getAmount(); } JSONObject info = new JSONObject(); try { Long orderId = OrderUtils.getOrderId(); data.getOrder().setId(orderId); data.getOrder().setPrice(totalPrice); String orderAttach = JSON.toJSONString(data); String order = OrderUtils.createAlipayInfo(orderAttach,String.valueOf(orderId),"惊喜商城-"+orderId,"惊喜商城",String.valueOf(totalPrice)); info.put("id",orderId); info.put("order",order); putCacheOrderFormData(data); } catch (Exception e) { e.printStackTrace(); LOG.error("订单创建失败",e); throw new RuntimeException("订单创建失败"); } return info; }  JSONObject createTemporaryOrder(OrderFormData data); @CachePut(key = "#data.order.id+''+#data.order.userAccountId") OrderFormData putCacheOrderFormData(OrderFormData data); @Cacheable(key = "#data.order.id+''+#data.order.userAccountId") OrderFormData getCacheTemporaryOrder(OrderFormData data); @CacheEvict(key = "#data.order.id+''+#data.order.userAccountId") void removeTemporaryOrder(OrderFormData data); @Override boolean checkAliPayOrderValidator(Map params); @Override String createSign(Long accountId, OrderFormData formData); }
AliPayServiceImpl implements IAliPayService { public JSONObject createTemporaryOrder(OrderFormData data){ int totalPrice = 0; List<CommodityAmount> caList = data.getCaList(); for (CommodityAmount info:caList){ totalPrice+=info.getAmount(); } JSONObject info = new JSONObject(); try { Long orderId = OrderUtils.getOrderId(); data.getOrder().setId(orderId); data.getOrder().setPrice(totalPrice); String orderAttach = JSON.toJSONString(data); String order = OrderUtils.createAlipayInfo(orderAttach,String.valueOf(orderId),"惊喜商城-"+orderId,"惊喜商城",String.valueOf(totalPrice)); info.put("id",orderId); info.put("order",order); putCacheOrderFormData(data); } catch (Exception e) { e.printStackTrace(); LOG.error("订单创建失败",e); throw new RuntimeException("订单创建失败"); } return info; }  JSONObject createTemporaryOrder(OrderFormData data); @CachePut(key = "#data.order.id+''+#data.order.userAccountId") OrderFormData putCacheOrderFormData(OrderFormData data); @Cacheable(key = "#data.order.id+''+#data.order.userAccountId") OrderFormData getCacheTemporaryOrder(OrderFormData data); @CacheEvict(key = "#data.order.id+''+#data.order.userAccountId") void removeTemporaryOrder(OrderFormData data); @Override boolean checkAliPayOrderValidator(Map params); @Override String createSign(Long accountId, OrderFormData formData);  }