com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse Java Examples

The following examples show how to use com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse. 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 vote down vote up
@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 vote down vote up
/**
 * 微信充值回调
 */
@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: CallbackController.java    From unimall with Apache License 2.0 4 votes vote down vote up
@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 #4
Source File: PayNotifyController.java    From fw-cloud-framework with MIT License 4 votes vote down vote up
@RequestMapping("/notifyTest/{payOrderId}")
@ResponseBody
public String notifyTest(@PathVariable String payOrderId) {
	String logPrefix = "【微信支付回调通知】";
	log.info("====== 开始接收微信支付回调通知 ======");
	PayOrder payOrder = payOrderService.findPayOrderByOrderId(payOrderId);
	if (null == payOrder) {
		log.error("Can't found payOrder form db. payOrderId={}, ", payOrderId);
		return WxPayNotifyResponse.fail("未查询到相应订单信息");
	}

	// 查询payChannel记录
	String mchId = payOrder.getMch_id();
	String channelId = payOrder.getChannelId();
	PayChannel payChannel = payChannelService.findPayChannel(channelId, mchId);
	if (null == payChannel) {
		log.error("Can't found payChannel form db. mchId={} channelId={}, ", payOrderId, mchId, channelId);
		return WxPayNotifyResponse.fail("未查询到订单相关渠道信息");
	}

	// 处理订单
	int payStatus = payOrder.getStatus(); // 0:订单生成,1:支付中,-1:支付失败,2:支付成功,3:业务处理完成,-2:订单过期
	if (payStatus == PayConstant.PAY_STATUS_COMPLETE) { // 处理完成
		log.info("====== 订单已经完成直接返回 ======");
		return WxPayNotifyResponse.success("OK");
	}

	if (payStatus != PayConstant.PAY_STATUS_SUCCESS) {
		boolean updatePayOrderRows = payOrderService.updatePayOrderStatus4Success(payOrder.getPayOrderId());
		if (!updatePayOrderRows) {
			log.error("{}更新支付状态失败,将payOrderId={},更新payStatus={}失败", logPrefix, payOrder.getPayOrderId(), PayConstant.PAY_STATUS_SUCCESS);
			return WxPayNotifyResponse.fail("处理订单失败");
		}
		log.error("{}更新支付状态成功,将payOrderId={},更新payStatus={}成功", logPrefix, payOrder.getPayOrderId(), PayConstant.PAY_STATUS_SUCCESS);
		payOrder.setStatus(PayConstant.PAY_STATUS_SUCCESS);
	}
	// 业务系统后端通知
	this.notifyService.notifyPayOrder(payOrder);
	log.info("====== 完成接收微信支付回调通知 ======");
	return WxPayNotifyResponse.success("OK");
}