com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult Java Examples
The following examples show how to use
com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PayController.java From supplierShop with MIT License | 6 votes |
@PostMapping(value = "/shop/notify") @ApiOperation(value = "异步通知",notes = "异步通知") public String payNotify(@RequestBody String xmlData){ try { WxPayOrderNotifyResult notifyResult = wxPayService.parseOrderNotifyResult(xmlData); String orderNo = notifyResult.getOutTradeNo(); QueryWrapper<StoreOrder> wrapper = new QueryWrapper<>(); wrapper.eq("deleted",0).eq("pay_status",0).eq("order_sn",orderNo); StoreOrder storeOrder = orderService.getOne(wrapper); if(ObjectUtil.isNull(storeOrder)) { return WxPayNotifyResponse.success("处理成功!"); } orderService.notifyHandle(storeOrder); return WxPayNotifyResponse.success("处理成功!"); } catch (WxPayException e) { log.error(e.getMessage()); return WxPayNotifyResponse.fail(e.getMessage()); } // return WxPayNotifyResponse.success("处理成功!"); }
Example #2
Source File: AppWxPayController.java From charging_pile_cloud with MIT License | 6 votes |
/** * 微信充值回调 */ @ResponseBody @RequestMapping("/wxBack") public String payNotify(HttpServletRequest request, HttpServletResponse response) { try { String xmlResult = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding()); WxPayOrderNotifyResult result = wxPayService.parseOrderNotifyResult(xmlResult); // 结果正确 String orderId = result.getOutTradeNo(); String tradeNo = result.getTransactionId(); //自己处理订单的业务逻辑,需要判断订单是否已经支付过,否则可能会重复调用 StockUserCharge stockUserCharge = stockUserChargeService.getOne(new QueryWrapper<StockUserCharge>() .eq("swift_no",orderId)); if(stockUserCharge.getWithdrawStatus() == WithdrawStatusEnum.STATUS_4.getCode().byteValue()){ //更新付款状态 用户付款成功 stockUserCharge.setTranId(tradeNo); stockUserChargeService.withdrawStatusSuccess(stockUserCharge); } return WxPayNotifyResponse.success("处理成功!"); } catch (Exception e) { log.error("微信回调结果异常,异常原因{}", e.getMessage()); return WxPayNotifyResponse.fail(e.getMessage()); } }
Example #3
Source File: WxPayOrderNotifyResultConverter.java From weixin-java-tools with Apache License 2.0 | 6 votes |
@Override public void marshal(Object original, HierarchicalStreamWriter writer, MarshallingContext context) { super.marshal(original, writer, context); WxPayOrderNotifyResult obj = (WxPayOrderNotifyResult) original; List<WxPayOrderNotifyCoupon> list = obj.getCouponList(); if (list == null || list.size() == 0) { return; } for (int i = 0; i < list.size(); i++) { WxPayOrderNotifyCoupon coupon = list.get(i); writer.startNode("coupon_id_" + i); writer.setValue(coupon.getCouponId()); writer.endNode(); writer.startNode("coupon_type_" + i); writer.setValue(coupon.getCouponType()); writer.endNode(); writer.startNode("coupon_fee_" + i); writer.setValue(coupon.getCouponFee() + ""); writer.endNode(); } }
Example #4
Source File: WxPayOrderNotifyResultConverter.java From weixin-java-tools with Apache License 2.0 | 5 votes |
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { WxPayOrderNotifyResult obj = new WxPayOrderNotifyResult(); List<Field> fields = new ArrayList<>(Arrays.asList(obj.getClass().getDeclaredFields())); fields.addAll(Arrays.asList(obj.getClass().getSuperclass().getDeclaredFields())); Map<String, Field> fieldMap = getFieldMap(fields); Map<Integer, WxPayOrderNotifyCoupon> coupons = Maps.newTreeMap(); while (reader.hasMoreChildren()) { reader.moveDown(); if (fieldMap.containsKey(reader.getNodeName())) { Field field = fieldMap.get(reader.getNodeName()); this.setFieldValue(context, obj, field); } else if (StringUtils.startsWith(reader.getNodeName(), "coupon_id_")) { String id = (String) context.convertAnother(obj, String.class); this.getElement(coupons, reader.getNodeName()).setCouponId(id); } else if (StringUtils.startsWith(reader.getNodeName(), "coupon_type_")) { String type = (String) context.convertAnother(obj, String.class); this.getElement(coupons, reader.getNodeName()).setCouponType(type); } else if (StringUtils.startsWith(reader.getNodeName(), "coupon_fee_")) { Integer fee = (Integer) context.convertAnother(obj, Integer.class); this.getElement(coupons, reader.getNodeName()).setCouponFee(fee); } reader.moveUp(); } obj.setCouponList(Lists.newArrayList(coupons.values())); return obj; }
Example #5
Source File: WxPayOrderNotifyResultConverter.java From weixin-java-tools with Apache License 2.0 | 5 votes |
private void setFieldValue(UnmarshallingContext context, WxPayOrderNotifyResult obj, Field field) { Object val = context.convertAnother(obj, field.getType()); try { if (val != null) { PropertyDescriptor pd = new PropertyDescriptor(field.getName(), obj.getClass()); pd.getWriteMethod().invoke(obj, val); } } catch (Exception ignored) { } }
Example #6
Source File: BaseWxPayServiceImplTest.java From weixin-java-tools with Apache License 2.0 | 5 votes |
/** * @see {@link com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResultTest} * @throws Exception */ @Test public void testParseOrderNotifyResult() throws Exception { // 请参考com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResultTest 里的单元测试 String xmlString = "<xml>\n" + " <appid><![CDATA[wx2421b1c4370ec43b]]></appid>\n" + " <attach><![CDATA[支付测试]]></attach>\n" + " <bank_type><![CDATA[CFT]]></bank_type>\n" + " <fee_type><![CDATA[CNY]]></fee_type>\n" + " <is_subscribe><![CDATA[Y]]></is_subscribe>\n" + " <mch_id><![CDATA[10000100]]></mch_id>\n" + " <nonce_str><![CDATA[5d2b6c2a8db53831f7eda20af46e531c]]></nonce_str>\n" + " <openid><![CDATA[oUpF8uMEb4qRXf22hE3X68TekukE]]></openid>\n" + " <out_trade_no><![CDATA[1409811653]]></out_trade_no>\n" + " <result_code><![CDATA[SUCCESS]]></result_code>\n" + " <return_code><![CDATA[SUCCESS]]></return_code>\n" + " <sign><![CDATA[B552ED6B279343CB493C5DD0D78AB241]]></sign>\n" + " <sub_mch_id><![CDATA[10000100]]></sub_mch_id>\n" + " <time_end><![CDATA[20140903131540]]></time_end>\n" + " <total_fee>1</total_fee>\n" + " <trade_type><![CDATA[JSAPI]]></trade_type>\n" + " <transaction_id><![CDATA[1004400740201409030005092168]]></transaction_id>\n" + " <coupon_count>2</coupon_count>\n" + " <coupon_type_0><![CDATA[CASH]]></coupon_type_0>\n" + " <coupon_id_0>10000</coupon_id_0>\n" + " <coupon_fee_0>100</coupon_fee_0>\n" + " <coupon_type_1><![CDATA[NO_CASH]]></coupon_type_1>\n" + " <coupon_id_1>10001</coupon_id_1>\n" + " <coupon_fee_1>200</coupon_fee_1>\n" + "</xml>"; WxPayOrderNotifyResult result = this.payService.parseOrderNotifyResult(xmlString); System.out.println(result); }
Example #7
Source File: ParkThirdAPI.java From springboot-seed with MIT License | 5 votes |
@PostMapping("/pay_callback/{type}/{id}/{rid}/{uid}") public ResponseEntity<?> parseOrderNotifyResult(@ApiParam("支付类型") @PathVariable("type") Integer type, @ApiParam("主键") @PathVariable("id") long id, @ApiParam("外键") @PathVariable("rid") long rid, @ApiParam("用户id") @PathVariable("uid") long uid, @RequestBody String xmlData) throws WxPayException { WxPayOrderNotifyResult result = wxPayAPI.parseOrderNotifyResult(xmlData); if (result.getReturnCode().equals("SUCCESS")) { if (type == 1) { Payment payment = paymentService.selectByID(id).get(); payment.setBankType(result.getBankType()); payment.setOutTradeNo(result.getOutTradeNo()); payment.setTransactionNo(result.getTransactionId()); payment.setComment(result.getReturnCode()); paymentService.modifyById(payment); CarFee carFee = carFeeService.selectByID(rid).get(); carFee.setPaymentAmount(new BigDecimal(payment.getTotalFee()).divide(new BigDecimal(100))); carFee.setPaymentTime(new Date()); carFee.setPaymentMode("微信支付"); carFee.setPaymentId(id); carFee.setUserId(uid); carFeeService.modifyById(carFee); } else { // todo: 会员充值 } return ResponseEntity.status(HttpStatus.OK).body("SUCCESS"); } else { return ResponseEntity.status(HttpStatus.OK).body("FAIL"); } }
Example #8
Source File: CallbackController.java From unimall with Apache License 2.0 | 4 votes |
@RequestMapping("/wxpay") @Transactional(rollbackFor = Exception.class) public Object wxpay(@RequestBody String body) throws Exception { WxPayOrderNotifyResult result = null; try { result = wxPayService.parseOrderNotifyResult(body); } catch (WxPayException e) { logger.error("[微信解析回调请求] 异常", e); return WxPayNotifyResponse.fail(e.getMessage()); } logger.info("处理腾讯支付平台的订单支付"); logger.info(JSONObject.toJSONString(result)); /* 之前传过去的我们系统的订单ID */ String orderNo = result.getOutTradeNo(); String payId = result.getTransactionId(); List<OrderDO> orderDOList = orderMapper.selectList( new EntityWrapper<OrderDO>() .eq("order_no", orderNo)); if (CollectionUtils.isEmpty(orderDOList)) { return WxPayNotifyResponse.fail("订单不存在 orderNo=" + orderNo); } OrderDO order = orderDOList.get(0); // 检查这个订单是否已经处理过 if (order.getStatus() != OrderStatusType.UNPAY.getCode()) { return WxPayNotifyResponse.success("订单已经处理成功!"); } Integer totalFee = result.getTotalFee(); // 检查支付订单金额 if (!totalFee.equals(order.getActualPrice())) { return WxPayNotifyResponse.fail(order.getOrderNo() + " : 支付金额不符合 totalFee=" + totalFee); } //**************** 在此之前都没有 数据库修改 操作 所以前面是直接返回错误的 **********************// OrderDO updateOrderDO = new OrderDO(); updateOrderDO.setPayId(payId); updateOrderDO.setPayChannel("WX"); updateOrderDO.setPayPrice(result.getTotalFee()); updateOrderDO.setGmtPay(new Date()); updateOrderDO.setGmtUpdate(order.getGmtPay()); if (order.getGroupShopId() != null) { updateOrderDO.setStatus(OrderStatusType.GROUP_SHOP_WAIT.getCode()); } else { updateOrderDO.setStatus(OrderStatusType.WAIT_STOCK.getCode()); } orderBizService.changeOrderStatus(orderNo, OrderStatusType.UNPAY.getCode(), updateOrderDO); List<OrderSkuDO> orderSkuDOList = orderSkuMapper.selectList( new EntityWrapper<OrderSkuDO>() .eq("order_no", orderNo)); orderSkuDOList.forEach(item -> { //增加销量 spuMapper.incSales(item.getSpuId(), item.getNum()); if (order.getGroupShopId() != null) { //增加团购人数, 若想算商品数这里就获取orderSku的数量,若想算人数,这里就写1 groupShopMapper.incCurrentNum(order.getGroupShopId(), item.getNum()); } }); OrderDTO orderDTO = new OrderDTO(); BeanUtils.copyProperties(order, orderDTO); orderDTO.setPayChannel(updateOrderDO.getPayChannel()); orderDTO.setSkuList(orderSkuDOList); List<IPluginPaySuccess> plugins = pluginsManager.getPlugins(IPluginPaySuccess.class); if (!CollectionUtils.isEmpty(plugins)) { String formId = userBizService.getValidFormIdByUserId(orderDTO.getUserId()).getFormId(); for (IPluginPaySuccess paySuccess : plugins) { orderDTO = paySuccess.invoke(orderDTO, formId); } } //通知管理员发货 OrderDTO finalOrderDTO = orderDTO; GlobalExecutor.execute(() -> { adminNotifyBizService.newOrder(finalOrderDTO); }); return WxPayNotifyResponse.success("支付成功"); }
Example #9
Source File: WxPayOrderNotifyResultConverter.java From weixin-java-tools with Apache License 2.0 | 4 votes |
@Override @SuppressWarnings("rawtypes") public boolean canConvert(Class type) { return type.equals(WxPayOrderNotifyResult.class); }
Example #10
Source File: WxPayOrderNotifyResultTest.java From weixin-java-tools with Apache License 2.0 | 4 votes |
@Test public void testFromXML() { String xmlString = "<xml>\n" + " <appid><![CDATA[wx2421b1c4370ec43b]]></appid>\n" + " <attach><![CDATA[支付测试]]></attach>\n" + " <bank_type><![CDATA[CFT]]></bank_type>\n" + " <fee_type><![CDATA[CNY]]></fee_type>\n" + " <is_subscribe><![CDATA[Y]]></is_subscribe>\n" + " <mch_id><![CDATA[10000100]]></mch_id>\n" + " <nonce_str><![CDATA[5d2b6c2a8db53831f7eda20af46e531c]]></nonce_str>\n" + " <openid><![CDATA[oUpF8uMEb4qRXf22hE3X68TekukE]]></openid>\n" + " <out_trade_no><![CDATA[1409811653]]></out_trade_no>\n" + " <result_code><![CDATA[SUCCESS]]></result_code>\n" + " <return_code><![CDATA[SUCCESS]]></return_code>\n" + " <sign><![CDATA[B552ED6B279343CB493C5DD0D78AB241]]></sign>\n" + " <sub_mch_id><![CDATA[10000100]]></sub_mch_id>\n" + " <time_end><![CDATA[20140903131540]]></time_end>\n" + " <total_fee>1</total_fee>\n" + " <trade_type><![CDATA[JSAPI]]></trade_type>\n" + " <transaction_id><![CDATA[1004400740201409030005092168]]></transaction_id>\n" + " <coupon_count>2</coupon_count>\n" + " <coupon_type_1><![CDATA[NO_CASH]]></coupon_type_1>\n" + " <coupon_id_1>10001</coupon_id_1>\n" + " <coupon_fee_1>200</coupon_fee_1>\n" + " <coupon_type_0><![CDATA[CASH]]></coupon_type_0>\n" + " <coupon_id_0>10000</coupon_id_0>\n" + " <coupon_fee_0>100</coupon_fee_0>\n" + "</xml>"; WxPayOrderNotifyResult result = WxPayOrderNotifyResult.fromXML(xmlString); Assert.assertEquals(result.getCouponCount().intValue(), 2); Assert.assertNotNull(result.getCouponList()); Assert.assertEquals(result.getCouponList().size(), 2); Assert.assertEquals(result.getCouponList().get(0).getCouponFee().intValue(), 100); Assert.assertEquals(result.getCouponList().get(1).getCouponFee().intValue(), 200); Assert.assertEquals(result.getCouponList().get(0).getCouponType(), "CASH"); Assert.assertEquals(result.getCouponList().get(1).getCouponType(), "NO_CASH"); Assert.assertEquals(result.getCouponList().get(0).getCouponId(), "10000"); Assert.assertEquals(result.getCouponList().get(1).getCouponId(), "10001"); }
Example #11
Source File: WxPayAPI.java From springboot-seed with MIT License | 4 votes |
/** * TODO 此方法需要改造,根据实际需要返回com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse对象 */ @PostMapping("/parseOrderNotifyResult") public WxPayOrderNotifyResult parseOrderNotifyResult(@RequestBody String xmlData) throws WxPayException { return this.wxService.parseOrderNotifyResult(xmlData); }
Example #12
Source File: NotifyPayServiceImpl.java From xxpay-master with MIT License | 4 votes |
/** * 验证微信支付通知参数 * @return */ public boolean verifyWxPayParams(Map<String, Object> payContext) { WxPayOrderNotifyResult params = (WxPayOrderNotifyResult)payContext.get("parameters"); //校验结果是否成功 if (!PayConstant.RETURN_VALUE_SUCCESS.equalsIgnoreCase(params.getResultCode()) && !PayConstant.RETURN_VALUE_SUCCESS.equalsIgnoreCase(params.getReturnCode())) { _log.error("returnCode={},resultCode={},errCode={},errCodeDes={}", params.getReturnCode(), params.getResultCode(), params.getErrCode(), params.getErrCodeDes()); payContext.put("retMsg", "notify data failed"); return false; } Integer total_fee = params.getTotalFee(); // 总金额 String out_trade_no = params.getOutTradeNo(); // 商户系统订单号 // 查询payOrder记录 String payOrderId = out_trade_no; PayOrder payOrder = super.baseSelectPayOrder(payOrderId); if (payOrder==null) { _log.error("Can't found payOrder form db. payOrderId={}, ", payOrderId); payContext.put("retMsg", "Can't found payOrder"); return false; } // 查询payChannel记录 String mchId = payOrder.getMchId(); String channelId = payOrder.getChannelId(); PayChannel payChannel = super.baseSelectPayChannel(mchId, channelId); if(payChannel == null) { _log.error("Can't found payChannel form db. mchId={} channelId={}, ", payOrderId, mchId, channelId); payContext.put("retMsg", "Can't found payChannel"); return false; } payContext.put("wxPayConfig", WxPayUtil.getWxPayConfig(payChannel.getParam())); // 核对金额 long wxPayAmt = new BigDecimal(total_fee).longValue(); long dbPayAmt = payOrder.getAmount().longValue(); if (dbPayAmt != wxPayAmt) { _log.error("db payOrder record payPrice not equals total_fee. total_fee={},payOrderId={}", total_fee, payOrderId); payContext.put("retMsg", "total_fee is not the same"); return false; } payContext.put("payOrder", payOrder); return true; }
Example #13
Source File: Notify4WxPayController.java From xxpay-master with MIT License | 4 votes |
/** * 验证微信支付通知参数 * @return */ public boolean verifyWxPayParams(Map<String, Object> payContext) { WxPayOrderNotifyResult params = (WxPayOrderNotifyResult)payContext.get("parameters"); //校验结果是否成功 if (!PayConstant.RETURN_VALUE_SUCCESS.equalsIgnoreCase(params.getResultCode()) && !PayConstant.RETURN_VALUE_SUCCESS.equalsIgnoreCase(params.getReturnCode())) { _log.error("returnCode={},resultCode={},errCode={},errCodeDes={}", params.getReturnCode(), params.getResultCode(), params.getErrCode(), params.getErrCodeDes()); payContext.put("retMsg", "notify data failed"); return false; } Integer total_fee = params.getTotalFee(); // 总金额 String out_trade_no = params.getOutTradeNo(); // 商户系统订单号 // 查询payOrder记录 String payOrderId = out_trade_no; PayOrder payOrder = payOrderService.selectPayOrder(payOrderId); if (payOrder==null) { _log.error("Can't found payOrder form db. payOrderId={}, ", payOrderId); payContext.put("retMsg", "Can't found payOrder"); return false; } // 查询payChannel记录 String mchId = payOrder.getMchId(); String channelId = payOrder.getChannelId(); PayChannel payChannel = payChannelService.selectPayChannel(channelId, mchId); if(payChannel == null) { _log.error("Can't found payChannel form db. mchId={} channelId={}, ", payOrderId, mchId, channelId); payContext.put("retMsg", "Can't found payChannel"); return false; } payContext.put("wxPayConfig", WxPayUtil.getWxPayConfig(payChannel.getParam())); // 核对金额 long wxPayAmt = new BigDecimal(total_fee).longValue(); long dbPayAmt = payOrder.getAmount().longValue(); if (dbPayAmt != wxPayAmt) { _log.error("db payOrder record payPrice not equals total_fee. total_fee={},payOrderId={}", total_fee, payOrderId); payContext.put("retMsg", "total_fee is not the same"); return false; } payContext.put("payOrder", payOrder); return true; }
Example #14
Source File: NotifyPayServiceImpl.java From xxpay-master with MIT License | 4 votes |
/** * 验证微信支付通知参数 * @return */ public boolean verifyWxPayParams(Map<String, Object> payContext) { WxPayOrderNotifyResult params = (WxPayOrderNotifyResult)payContext.get("parameters"); //校验结果是否成功 if (!PayConstant.RETURN_VALUE_SUCCESS.equalsIgnoreCase(params.getResultCode()) && !PayConstant.RETURN_VALUE_SUCCESS.equalsIgnoreCase(params.getReturnCode())) { _log.error("returnCode={},resultCode={},errCode={},errCodeDes={}", params.getReturnCode(), params.getResultCode(), params.getErrCode(), params.getErrCodeDes()); payContext.put("retMsg", "notify data failed"); return false; } Integer total_fee = params.getTotalFee(); // 总金额 String out_trade_no = params.getOutTradeNo(); // 商户系统订单号 // 查询payOrder记录 String payOrderId = out_trade_no; PayOrder payOrder = super.baseSelectPayOrder(payOrderId); if (payOrder==null) { _log.error("Can't found payOrder form db. payOrderId={}, ", payOrderId); payContext.put("retMsg", "Can't found payOrder"); return false; } // 查询payChannel记录 String mchId = payOrder.getMchId(); String channelId = payOrder.getChannelId(); PayChannel payChannel = super.baseSelectPayChannel(mchId, channelId); if(payChannel == null) { _log.error("Can't found payChannel form db. mchId={} channelId={}, ", payOrderId, mchId, channelId); payContext.put("retMsg", "Can't found payChannel"); return false; } payContext.put("wxPayConfig", WxPayUtil.getWxPayConfig(payChannel.getParam())); // 核对金额 long wxPayAmt = new BigDecimal(total_fee).longValue(); long dbPayAmt = payOrder.getAmount().longValue(); if (dbPayAmt != wxPayAmt) { _log.error("db payOrder record payPrice not equals total_fee. total_fee={},payOrderId={}", total_fee, payOrderId); payContext.put("retMsg", "total_fee is not the same"); return false; } payContext.put("payOrder", payOrder); return true; }
Example #15
Source File: PayNoticeController.java From mall4j with GNU Affero General Public License v3.0 | 3 votes |
@RequestMapping("/order") public ResponseEntity<Void> submit(@RequestBody String xmlData) throws WxPayException { WxPayOrderNotifyResult parseOrderNotifyResult = wxMiniPayService.parseOrderNotifyResult(xmlData); String payNo = parseOrderNotifyResult.getOutTradeNo(); String bizPayNo = parseOrderNotifyResult.getTransactionId(); // 根据内部订单号更新order settlement payService.paySuccess(payNo, bizPayNo); return ResponseEntity.ok().build(); }
Example #16
Source File: WxPayService.java From weixin-java-tools with Apache License 2.0 | 2 votes |
/** * 解析支付结果通知. * 详见https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7 */ WxPayOrderNotifyResult parseOrderNotifyResult(String xmlData) throws WxPayException;