com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult Java Examples
The following examples show how to use
com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult.
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 mall4j with GNU Affero General Public License v3.0 | 6 votes |
/** * 支付接口 */ @PostMapping("/pay") @ApiOperation(value = "根据订单号进行支付", notes = "根据订单号进行支付") @SneakyThrows public ResponseEntity<WxPayMpOrderResult> pay(@RequestBody PayParam payParam) { YamiUser user = SecurityUtils.getUser(); String userId = user.getUserId(); String openId = user.getBizUserId(); PayInfoDto payInfo = payService.pay(userId, payParam); WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest(); orderRequest.setBody(payInfo.getBody()); orderRequest.setOutTradeNo(payInfo.getPayNo()); orderRequest.setTotalFee((int) Arith.mul(payInfo.getPayAmount(), 100)); orderRequest.setSpbillCreateIp(IPHelper.getIpAddr()); orderRequest.setNotifyUrl(apiConfig.getDomainName() + "/notice/pay/order"); orderRequest.setTradeType(WxPayConstants.TradeType.JSAPI); orderRequest.setOpenid(openId); return ResponseEntity.ok(wxMiniPayService.createOrder(orderRequest)); }
Example #2
Source File: StockUserChargeServiceImpl.java From charging_pile_cloud with MIT License | 6 votes |
@Override @Transactional(rollbackFor = {}) public Object createUserCharge(StockUser stockUser, StockUserCharge charge) throws WxPayException { BigDecimal fee = charge.getFee().setScale(CommonConstant.DECIMAL_PLACE, RoundingMode.DOWN); WxPayUnifiedOrderRequest orderRequest =new WxPayUnifiedOrderRequest(); String orderNum = System.currentTimeMillis() + StringUtils.getRandom(9); orderRequest.setOpenid(stockUser.getOpenId()); orderRequest.setOutTradeNo(orderNum); orderRequest.setTradeType(WxPayConstants.TradeType.JSAPI); orderRequest.setSpbillCreateIp(HttpRequestUtil.getIpAddr(request)); orderRequest.setTotalFee(BaseWxPayRequest.yuanToFen(fee.toPlainString())); orderRequest.setBody("充电付款"); orderRequest.setNonceStr(String.valueOf(System.currentTimeMillis())); StockUserCapitalFund stockUserCapitalFund = stockUserCapitalFundService.getOne(new QueryWrapper<StockUserCapitalFund>() .eq("stock_user_id",stockUser.getId())); if(stockUserCapitalFund ==null){ throw new CommonException("用户未办卡,暂不能充值"); } WxPayMpOrderResult object = wxPayService.createOrder(orderRequest); addChargeRecord(null,stockUser.getId(), charge.getFee(), stockUserCapitalFund.getStockCode(),PayTypeEnum.STATUS_1, WithdrawStatusEnum.STATUS_4, orderNum); return object; }
Example #3
Source File: YxPayService.java From yshopmall with Apache License 2.0 | 6 votes |
/** * 微信公众号支付 * * @param orderId * @param openId 公众号openid * @param body * @param totalFee * @return * @throws WxPayException */ public WxPayMpOrderResult wxPay(String orderId, String openId, 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("JSAPI"); orderRequest.setOpenid(openId); orderRequest.setBody(body); orderRequest.setOutTradeNo(orderId); orderRequest.setTotalFee(totalFee); orderRequest.setSpbillCreateIp("127.0.0.1"); orderRequest.setNotifyUrl(apiUrl + "/api/wechat/notify"); orderRequest.setAttach(attach); WxPayMpOrderResult orderResult = wxPayService.createOrder(orderRequest); return orderResult; }
Example #4
Source File: YxMiniPayService.java From yshopmall with Apache License 2.0 | 6 votes |
/** * 小程序支付 * * @param orderId * @param openId 小程序openid * @param body * @param totalFee * @return * @throws WxPayException */ public WxPayMpOrderResult wxPay(String orderId, String openId, 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.getWxAppPayService(); WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest(); orderRequest.setTradeType("JSAPI"); orderRequest.setOpenid(openId); orderRequest.setBody(body); orderRequest.setOutTradeNo(orderId); orderRequest.setTotalFee(totalFee); orderRequest.setSpbillCreateIp("127.0.0.1"); orderRequest.setNotifyUrl(apiUrl + "/api/wechat/notify"); orderRequest.setAttach(attach); WxPayMpOrderResult orderResult = wxPayService.createOrder(orderRequest); return orderResult; }
Example #5
Source File: BaseWxPayServiceImplTest.java From weixin-java-tools with Apache License 2.0 | 5 votes |
@Test public void testCreateOrder_jsapi() throws Exception { WxPayMpOrderResult result = this.payService .createOrder(WxPayUnifiedOrderRequest.newBuilder() .body("我去") .totalFee(1) .spbillCreateIp("11.1.11.1") .notifyUrl("111111") .tradeType(TradeType.JSAPI) .openid(((XmlWxPayConfig) this.payService.getConfig()).getOpenid()) .outTradeNo("1111112") .build()); this.logger.info(result.toString()); this.logger.warn(this.payService.getWxApiData().toString()); }
Example #6
Source File: PayController.java From supplierShop with MIT License | 4 votes |
/** * 调用统一下单接口,并组装生成支付所需参数对象. * * @param request 统一下单请求参数 * @param <T> 请使用{@link com.github.binarywang.wxpay.bean.order}包下的类 * @return 返回 {@link com.github.binarywang.wxpay.bean.order}包下的类对象 */ @PostMapping(value = "/shop/pay-do-pay") @ApiOperation(value = "开始支付",notes = "开始支付") public R doPay(@Validated @RequestBody String jsonStr){ JSONObject jsonObject = JSON.parseObject(jsonStr); String orderNo = jsonObject.get("order_no").toString(); //1-余额支付 2-微信支付 int payType = 1; if(StrUtil.isEmpty(orderNo)){ return R.error(4000,"订单号缺失"); } if(ObjectUtil.isNotNull(jsonObject.get("pay_type"))){ payType = Integer.valueOf(jsonObject.get("pay_type").toString()); } int userId = userOperator.getUser().getId(); StoreOrder storeOrder = orderService.orderInfo(orderNo,userId); if(ObjectUtil.isNull(storeOrder)){ return R.error(4000,"订单不存在"); } if(payType == 1){ orderService.payYue(storeOrder); return R.success("余额支付成功"); }else{ //判断库存 QueryWrapper<StoreOrderGoods> wrapperGoods = new QueryWrapper<>(); wrapperGoods.eq("order_id",storeOrder.getOrderId()); List<StoreOrderGoods> orderGoodsList = storeOrderGoodsMapper .selectList(wrapperGoods); for (StoreOrderGoods storeGood : orderGoodsList) { int storeCount = orderService.checkStore(storeGood.getGoodsId(),storeGood.getSpecKey()); if(storeCount < storeGood.getGoodsNum()){ return R.error(4000,"库存不足"); } } WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest(); StoreMember member = memberService.getById(userId); orderRequest.setBody("商品购买"); orderRequest.setOutTradeNo(orderNo); BigDecimal bigDecimal = new BigDecimal(100); orderRequest.setTotalFee(bigDecimal.multiply(storeOrder.getOrderAmount()).intValue());//元转成分 orderRequest.setOpenid(member.getOpenid()); orderRequest.setSpbillCreateIp("127.0.0.1"); orderRequest.setNotifyUrl("https://app2.dayouqiantu.cn/shop/notify"); orderRequest.setTradeType("JSAPI"); try { WxPayMpOrderResult orderResult = wxPayService.createOrder(orderRequest); return R.success(orderResult); } catch (WxPayException e) { return R.error(4000,e.getMessage()); } } }
Example #7
Source File: WxOrderService.java From BigDataPlatform with GNU General Public License v3.0 | 4 votes |
/** * 付款订单的预支付会话标识 * <p> * 1. 检测当前订单是否能够付款 * 2. 微信商户平台返回支付订单ID * 3. 设置订单付款状态 * * @param userId 用户ID * @param body 订单信息,{ orderId:xxx } * @return 支付订单ID */ @Transactional public Object prepay(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(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, "订单不能支付"); } LitemallUser user = userService.findById(userId); String openid = user.getWeixinOpenid(); if (openid == null) { return ResponseUtil.fail(AUTH_OPENID_UNACCESS, "订单不能支付"); } WxPayMpOrderResult result = null; try { WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest(); orderRequest.setOutTradeNo(order.getOrderSn()); orderRequest.setOpenid(openid); 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); //缓存prepayID用于后续模版通知 String prepayId = result.getPackageValue(); prepayId = prepayId.replace("prepay_id=", ""); LitemallUserFormid userFormid = new LitemallUserFormid(); userFormid.setOpenid(user.getWeixinOpenid()); userFormid.setFormid(prepayId); userFormid.setIsprepay(true); userFormid.setUseamount(3); userFormid.setExpireTime(LocalDateTime.now().plusDays(7)); formIdService.addUserFormid(userFormid); } catch (Exception e) { e.printStackTrace(); return ResponseUtil.fail(ORDER_PAY_FAIL, "订单不能支付"); } if (orderService.updateWithOptimisticLocker(order) == 0) { return ResponseUtil.updatedDateExpired(); } return ResponseUtil.ok(result); }
Example #8
Source File: WxOrderService.java From dts-shop with GNU Lesser General Public License v3.0 | 4 votes |
/** * 付款订单的预支付会话标识 * <p> * 1. 检测当前订单是否能够付款 2. 微信商户平台返回支付订单ID 3. 设置订单付款状态 * * @param userId * 用户ID * @param body * 订单信息,{ orderId:xxx } * @return 支付订单ID */ @Transactional public Object prepay(Integer userId, String body, HttpServletRequest request) { if (userId == null) { logger.error("付款订单的预支付会话标识失败:用户未登录!"); return ResponseUtil.unlogin(); } Integer orderId = JacksonUtil.parseInteger(body, "orderId"); if (orderId == null) { return ResponseUtil.badArgument(); } DtsOrder order = orderService.findById(orderId); if (order == null) { return ResponseUtil.badArgumentValue(); } if (!order.getUserId().equals(userId)) { return ResponseUtil.badArgumentValue(); } // 检测是否能够取消 OrderHandleOption handleOption = OrderUtil.build(order); if (!handleOption.isPay()) { logger.error("付款订单的预支付会话标识失败:{}", WxResponseCode.ORDER_REPAY_OPERATION.desc()); return WxResponseUtil.fail(WxResponseCode.ORDER_REPAY_OPERATION); } DtsUser user = userService.findById(userId); String openid = user.getWeixinOpenid(); if (openid == null) { logger.error("付款订单的预支付会话标识失败:{}", AUTH_OPENID_UNACCESS.desc()); return WxResponseUtil.fail(AUTH_OPENID_UNACCESS); } WxPayMpOrderResult result = null; try { WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest(); orderRequest.setOutTradeNo(order.getOrderSn()); orderRequest.setOpenid(openid); orderRequest.setBody(CommConsts.DEFAULT_ORDER_FIX + 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); // 缓存prepayID用于后续模版通知 String prepayId = result.getPackageValue(); prepayId = prepayId.replace("prepay_id=", ""); DtsUserFormid userFormid = new DtsUserFormid(); userFormid.setOpenid(user.getWeixinOpenid()); userFormid.setFormid(prepayId); userFormid.setIsprepay(true); userFormid.setUseamount(3); userFormid.setExpireTime(LocalDateTime.now().plusDays(7)); formIdService.addUserFormid(userFormid); } catch (Exception e) { logger.error("付款订单的预支付会话标识失败:{}", ORDER_PAY_FAIL.desc()); e.printStackTrace(); return WxResponseUtil.fail(ORDER_PAY_FAIL); } if (orderService.updateWithOptimisticLocker(order) == 0) { logger.error("付款订单的预支付会话标识失败:{}", "更新订单信息失败"); return ResponseUtil.updatedDateExpired(); } logger.info("【请求结束】购物车商品删除成功:清理的productIds:{}", JSONObject.toJSONString(result)); return ResponseUtil.ok(result); }
Example #9
Source File: WxOrderService.java From mall with MIT License | 4 votes |
/** * 付款订单的预支付会话标识 * <p> * 1. 检测当前订单是否能够付款 * 2. 微信商户平台返回支付订单ID * 3. 设置订单付款状态 * * @param userId 用户ID * @param body 订单信息,{ orderId:xxx } * @return 支付订单ID */ @Transactional public Object prepay(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(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, "订单不能支付"); } LitemallUser user = userService.findById(userId); String openid = user.getWeixinOpenid(); if (openid == null) { return ResponseUtil.fail(AUTH_OPENID_UNACCESS, "订单不能支付"); } WxPayMpOrderResult result = null; try { WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest(); orderRequest.setOutTradeNo(order.getOrderSn()); orderRequest.setOpenid(openid); 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); //缓存prepayID用于后续模版通知 String prepayId = result.getPackageValue(); prepayId = prepayId.replace("prepay_id=", ""); LitemallUserFormid userFormid = new LitemallUserFormid(); userFormid.setOpenid(user.getWeixinOpenid()); userFormid.setFormid(prepayId); userFormid.setIsprepay(true); userFormid.setUseamount(3); userFormid.setExpireTime(LocalDateTime.now().plusDays(7)); formIdService.addUserFormid(userFormid); } catch (Exception e) { e.printStackTrace(); return ResponseUtil.fail(ORDER_PAY_FAIL, "订单不能支付"); } if (orderService.updateWithOptimisticLocker(order) == 0) { return ResponseUtil.updatedDateExpired(); } return ResponseUtil.ok(result); }
Example #10
Source File: BaseWxPayServiceImpl.java From weixin-java-tools with Apache License 2.0 | 4 votes |
@Override public <T> T createOrder(WxPayUnifiedOrderRequest request) throws WxPayException { WxPayUnifiedOrderResult unifiedOrderResult = this.unifiedOrder(request); String prepayId = unifiedOrderResult.getPrepayId(); if (StringUtils.isBlank(prepayId)) { throw new WxPayException(String.format("无法获取prepay id,错误代码: '%s',信息:%s。", unifiedOrderResult.getErrCode(), unifiedOrderResult.getErrCodeDes())); } String timestamp = String.valueOf(System.currentTimeMillis() / 1000); String nonceStr = String.valueOf(System.currentTimeMillis()); switch (request.getTradeType()) { case TradeType.MWEB: { return (T) new WxPayMwebOrderResult(unifiedOrderResult.getMwebUrl()); } case TradeType.NATIVE: { return (T) new WxPayNativeOrderResult(unifiedOrderResult.getCodeURL()); } case TradeType.APP: { // APP支付绑定的是微信开放平台上的账号,APPID为开放平台上绑定APP后发放的参数 String appId = unifiedOrderResult.getAppid(); if (StringUtils.isNotEmpty(unifiedOrderResult.getSubAppId())) { appId = unifiedOrderResult.getSubAppId(); } Map<String, String> configMap = new HashMap<>(8); // 此map用于参与调起sdk支付的二次签名,格式全小写,timestamp只能是10位,格式固定,切勿修改 String partnerId; if (StringUtils.isEmpty(request.getMchId())) { partnerId = this.getConfig().getMchId(); } else { partnerId = request.getMchId(); } configMap.put("prepayid", prepayId); configMap.put("partnerid", partnerId); String packageValue = "Sign=WXPay"; configMap.put("package", packageValue); configMap.put("timestamp", timestamp); configMap.put("noncestr", nonceStr); configMap.put("appid", appId); final WxPayAppOrderResult result = WxPayAppOrderResult.builder() .sign(SignUtils.createSign(configMap, null, this.getConfig().getMchKey(), false)) .prepayId(prepayId) .partnerId(partnerId) .appId(appId) .packageValue(packageValue) .timeStamp(timestamp) .nonceStr(nonceStr) .build(); return (T) result; } case TradeType.JSAPI: { String signType = SignType.MD5; String appid = unifiedOrderResult.getAppid(); if (StringUtils.isNotEmpty(unifiedOrderResult.getSubAppId())) { appid = unifiedOrderResult.getSubAppId(); } WxPayMpOrderResult payResult = WxPayMpOrderResult.builder() .appId(appid) .timeStamp(timestamp) .nonceStr(nonceStr) .packageValue("prepay_id=" + prepayId) .signType(signType) .build(); payResult.setPaySign(SignUtils.createSign(payResult, signType, this.getConfig().getMchKey(), false)); return (T) payResult; } default: { throw new WxPayException("该交易类型暂不支持"); } } }
Example #11
Source File: WxOrderService.java From litemall with MIT License | 4 votes |
/** * 付款订单的预支付会话标识 * <p> * 1. 检测当前订单是否能够付款 * 2. 微信商户平台返回支付订单ID * 3. 设置订单付款状态 * * @param userId 用户ID * @param body 订单信息,{ orderId:xxx } * @return 支付订单ID */ @Transactional public Object prepay(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, "订单不能支付"); } LitemallUser user = userService.findById(userId); String openid = user.getWeixinOpenid(); if (openid == null) { return ResponseUtil.fail(AUTH_OPENID_UNACCESS, "订单不能支付"); } WxPayMpOrderResult result = null; try { WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest(); orderRequest.setOutTradeNo(order.getOrderSn()); orderRequest.setOpenid(openid); 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.fail(ORDER_PAY_FAIL, "订单不能支付"); } if (orderService.updateWithOptimisticLocker(order) == 0) { return ResponseUtil.updatedDateExpired(); } return ResponseUtil.ok(result); }