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;
}
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);
}
Aggregations