Search in sources :

Example 1 with WxPayMwebOrderResult

use of com.github.binarywang.wxpay.bean.order.WxPayMwebOrderResult in project yshopmall by guchengwuyue.

the class YxPayService method wxH5Pay.

/**
 * 微信H5支付
 *
 * @param orderId
 * @param body
 * @param totalFee
 * @return
 * @throws WxPayException
 */
public WxPayMwebOrderResult wxH5Pay(String orderId, String body, Integer totalFee, String attach) throws WxPayException {
    String apiUrl = redisHandler.getVal(ShopKeyUtils.getApiUrl());
    if (StrUtil.isBlank(apiUrl)) {
        throw new ErrorRequestException("请配置api地址");
    }
    WxPayService wxPayService = WxPayConfiguration.getPayService();
    WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
    orderRequest.setTradeType("MWEB");
    orderRequest.setBody(body);
    orderRequest.setOutTradeNo(orderId);
    orderRequest.setTotalFee(totalFee);
    orderRequest.setSpbillCreateIp("127.0.0.1");
    orderRequest.setNotifyUrl(apiUrl + "/api/wechat/notify");
    orderRequest.setAttach(attach);
    WxPayMwebOrderResult orderResult = wxPayService.createOrder(orderRequest);
    return orderResult;
}
Also used : WxPayService(com.github.binarywang.wxpay.service.WxPayService) ErrorRequestException(co.yixiang.exception.ErrorRequestException) WxPayUnifiedOrderRequest(com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest) WxPayMwebOrderResult(com.github.binarywang.wxpay.bean.order.WxPayMwebOrderResult)

Example 2 with WxPayMwebOrderResult

use of com.github.binarywang.wxpay.bean.order.WxPayMwebOrderResult in project litemall by linlinjava.

the class WxOrderService method h5pay.

/**
 * 微信H5支付
 *
 * @param userId
 * @param body
 * @param request
 * @return
 */
@Transactional
public Object h5pay(Integer userId, String body, HttpServletRequest request) {
    if (userId == null) {
        return ResponseUtil.unlogin();
    }
    Integer orderId = JacksonUtil.parseInteger(body, "orderId");
    if (orderId == null) {
        return ResponseUtil.badArgument();
    }
    LitemallOrder order = orderService.findById(userId, orderId);
    if (order == null) {
        return ResponseUtil.badArgumentValue();
    }
    if (!order.getUserId().equals(userId)) {
        return ResponseUtil.badArgumentValue();
    }
    // 检测是否能够取消
    OrderHandleOption handleOption = OrderUtil.build(order);
    if (!handleOption.isPay()) {
        return ResponseUtil.fail(ORDER_INVALID_OPERATION, "订单不能支付");
    }
    WxPayMwebOrderResult result = null;
    try {
        WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
        orderRequest.setOutTradeNo(order.getOrderSn());
        orderRequest.setTradeType("MWEB");
        orderRequest.setBody("订单:" + order.getOrderSn());
        // 元转成分
        int fee = 0;
        BigDecimal actualPrice = order.getActualPrice();
        fee = actualPrice.multiply(new BigDecimal(100)).intValue();
        orderRequest.setTotalFee(fee);
        orderRequest.setSpbillCreateIp(IpUtil.getIpAddr(request));
        result = wxPayService.createOrder(orderRequest);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return ResponseUtil.ok(result);
}
Also used : OrderHandleOption(org.linlinjava.litemall.db.util.OrderHandleOption) WxPayUnifiedOrderRequest(com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest) WxPayMwebOrderResult(com.github.binarywang.wxpay.bean.order.WxPayMwebOrderResult) BigDecimal(java.math.BigDecimal) IOException(java.io.IOException) WxPayException(com.github.binarywang.wxpay.exception.WxPayException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

WxPayMwebOrderResult (com.github.binarywang.wxpay.bean.order.WxPayMwebOrderResult)2 WxPayUnifiedOrderRequest (com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest)2 ErrorRequestException (co.yixiang.exception.ErrorRequestException)1 WxPayException (com.github.binarywang.wxpay.exception.WxPayException)1 WxPayService (com.github.binarywang.wxpay.service.WxPayService)1 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 OrderHandleOption (org.linlinjava.litemall.db.util.OrderHandleOption)1 Transactional (org.springframework.transaction.annotation.Transactional)1