Java Code Examples for com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest#setOpenid()
The following examples show how to use
com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest#setOpenid() .
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: 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 6
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 7
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 8
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 9
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); }
Example 10
Source File: WxUnifiedOrderServiceImpl.java From fw-cloud-framework with MIT License | 4 votes |
/** * 构建微信统一下单请求数据 */ private WxPayUnifiedOrderRequest buildUnifiedOrderRequest(PayOrder payOrder, WxPayConfig wxPayConfig) { String tradeType = wxPayConfig.getTradeType(); String payOrderId = payOrder.getPayOrderId(); Integer totalFee = payOrder.getAmount().intValue();// 支付金额,单位分 String deviceInfo = payOrder.getDevice(); String body = payOrder.getBody(); String detail = null; String attach = null; String outTradeNo = payOrderId; String feeType = "CNY"; String spBillCreateIP = payOrder.getIp(); String timeStart = null; String timeExpire = null; String goodsTag = null; String notifyUrl = wxPayConfig.getNotifyUrl(); String productId = null; if (tradeType.equals(PayConstant.WxConstant.TRADE_TYPE_NATIVE)) productId = JSON.parseObject(payOrder.getExtra()).getString("productId"); String limitPay = null; String openId = null; if (tradeType.equals(PayConstant.WxConstant.TRADE_TYPE_JSPAI)) openId = JSON.parseObject(payOrder.getExtra()).getString("openId"); String sceneInfo = null; if (tradeType.equals(PayConstant.WxConstant.TRADE_TYPE_MWEB)) { JSONObject extraObject = JSON.parseObject(WebUtils.buildURLDecoder(payOrder.getExtra())); sceneInfo = extraObject.getJSONObject("sceneInfo").toJSONString(); } // 微信统一下单请求对象 WxPayUnifiedOrderRequest request = new WxPayUnifiedOrderRequest(); request.setDeviceInfo(deviceInfo); request.setBody(body); request.setDetail(detail); request.setAttach(attach); request.setOutTradeNo(outTradeNo); request.setFeeType(feeType); request.setTotalFee(totalFee); request.setSpbillCreateIp(spBillCreateIP); request.setTimeStart(timeStart); request.setTimeExpire(timeExpire); request.setGoodsTag(goodsTag); request.setNotifyUrl(notifyUrl); request.setTradeType(tradeType); request.setProductId(productId); request.setLimitPay(limitPay); request.setOpenid(openId); request.setSceneInfo(sceneInfo); return request; }
Example 11
Source File: MyParkAPI.java From springboot-seed with MIT License | 4 votes |
@ApiOperation(value = "支付停车费") @PostMapping(value = "/pay") public ResponseEntity<?> pay(HttpServletRequest httpRequest, @ApiParam("停车记录") @RequestParam("carFee") Long carFeeId) throws Exception { OAuth2Authentication auth = (OAuth2Authentication) SecurityContextHolder.getContext().getAuthentication(); WxPayUnifiedOrderRequest request = new WxPayUnifiedOrderRequest(); SecurityUser securityUser = (SecurityUser) (auth.getPrincipal()); CarFee carFee = carFeeService.selectByID(carFeeId).get(); if (carFee.getPaymentTime() != null) { return ResponseEntity.status(HttpStatus.NOT_ACCEPTABLE).body("Already Paid"); } Park park = parkService.selectByID(carFee.getParkId()).get(); Fee fee = feeService.selectByID(park.getFeeId()).get(); BigDecimal money = ParkThirdAPI.calculateMoney(fee, carFee.getInTime(), new Date()); money = money.multiply(BigDecimal.TEN).multiply(BigDecimal.TEN); Dictionary<String, String> map = new Hashtable<>(); if (money == BigDecimal.ZERO) { carFee.setPaymentAmount(money); carFee.setPaymentTime(new Date()); carFee.setPaymentMode("免费"); carFee.setUserId(securityUser.getId()); carFeeService.modifyById(carFee); map.put("money", "0"); } else { if (securityUser.getId() < 15) { money = BigDecimal.ONE; } request.setOpenid(securityUser.getOpenId()); request.setDeviceInfo("ma"); request.setBody(park.getName()); request.setDetail(carFee.getCarNumber() + "-停车费"); request.setFeeType("CNY"); request.setTotalFee(money.intValue()); request.setSpbillCreateIp(httpRequest.getLocalAddr()); request.setTradeType("JSAPI"); // save db Payment payment = new Payment(); payment.setBody(request.getBody()); payment.setDetail(request.getDetail()); payment.setTotalFee(money.intValue()); payment.setFeeType(request.getFeeType()); payment.setTradeType(request.getTradeType()); payment.setIp(request.getSpbillCreateIp()); paymentService.add(payment); // post wx request request.setNotifyUrl(String.format("https://app.lhzh.tech/third/park/pay_callback/1/%d/%d/%d", payment.getId(), carFeeId, securityUser.getId())); request.setOutTradeNo(String.format("1-%d-%d-%d-%d", securityUser.getId(), payment.getId(), carFeeId, new Random().nextInt(9999))); WxPayUnifiedOrderResult result = wxPayAPI.unifiedOrder(request); map.put("nonceStr", result.getNonceStr()); String timeStamp = Long.toString(new Date().getTime() / 1000); map.put("timeStamp", timeStamp); String pkg = "prepay_id=" + result.getPrepayId(); map.put("package", pkg); map.put("signType", "MD5"); String paySignString = String.format("appId=%s&nonceStr=%s&package=%s&signType=MD5&timeStamp=%s&key=%s", wxPayProperties.getAppId(), result.getNonceStr(), pkg, timeStamp, wxPayProperties.getMchKey()); String paySign = new BigInteger(1, MessageDigest.getInstance("MD5").digest(paySignString.getBytes())).toString(16); map.put("paySign", paySign); map.put("money", money.toString()); } return ResponseEntity.status(HttpStatus.OK).body(map); }
Example 12
Source File: PayChannel4WxServiceImpl.java From xxpay-master with MIT License | 4 votes |
/** * 构建微信统一下单请求数据 * @param payOrder * @param wxPayConfig * @return */ WxPayUnifiedOrderRequest buildUnifiedOrderRequest(PayOrder payOrder, WxPayConfig wxPayConfig) { String tradeType = wxPayConfig.getTradeType(); String payOrderId = payOrder.getPayOrderId(); Integer totalFee = payOrder.getAmount().intValue();// 支付金额,单位分 String deviceInfo = payOrder.getDevice(); String body = payOrder.getBody(); String detail = null; String attach = null; String outTradeNo = payOrderId; String feeType = "CNY"; String spBillCreateIP = payOrder.getClientIp(); String timeStart = null; String timeExpire = null; String goodsTag = null; String notifyUrl = wxPayConfig.getNotifyUrl(); String productId = null; if(tradeType.equals(PayConstant.WxConstant.TRADE_TYPE_NATIVE)) productId = JSON.parseObject(payOrder.getExtra()).getString("productId"); String limitPay = null; String openId = null; if(tradeType.equals(PayConstant.WxConstant.TRADE_TYPE_JSPAI)) openId = JSON.parseObject(payOrder.getExtra()).getString("openId"); String sceneInfo = null; if(tradeType.equals(PayConstant.WxConstant.TRADE_TYPE_MWEB)) sceneInfo = JSON.parseObject(payOrder.getExtra()).getString("sceneInfo"); // 微信统一下单请求对象 WxPayUnifiedOrderRequest request = new WxPayUnifiedOrderRequest(); request.setDeviceInfo(deviceInfo); request.setBody(body); request.setDetail(detail); request.setAttach(attach); request.setOutTradeNo(outTradeNo); request.setFeeType(feeType); request.setTotalFee(totalFee); request.setSpbillCreateIp(spBillCreateIP); request.setTimeStart(timeStart); request.setTimeExpire(timeExpire); request.setGoodsTag(goodsTag); request.setNotifyURL(notifyUrl); request.setTradeType(tradeType); request.setProductId(productId); request.setLimitPay(limitPay); request.setOpenid(openId); request.setSceneInfo(sceneInfo); return request; }
Example 13
Source File: PayChannel4WxController.java From xxpay-master with MIT License | 4 votes |
/** * 构建微信统一下单请求数据 * @param payOrder * @param wxPayConfig * @return */ WxPayUnifiedOrderRequest buildUnifiedOrderRequest(PayOrder payOrder, WxPayConfig wxPayConfig) { String tradeType = wxPayConfig.getTradeType(); String payOrderId = payOrder.getPayOrderId(); Integer totalFee = payOrder.getAmount().intValue();// 支付金额,单位分 String deviceInfo = payOrder.getDevice(); String body = payOrder.getBody(); String detail = null; String attach = null; String outTradeNo = payOrderId; String feeType = "CNY"; String spBillCreateIP = payOrder.getClientIp(); String timeStart = null; String timeExpire = null; String goodsTag = null; String notifyUrl = wxPayConfig.getNotifyUrl(); String productId = null; if(tradeType.equals(PayConstant.WxConstant.TRADE_TYPE_NATIVE)) productId = JSON.parseObject(payOrder.getExtra()).getString("productId"); String limitPay = null; String openId = null; if(tradeType.equals(PayConstant.WxConstant.TRADE_TYPE_JSPAI)) openId = JSON.parseObject(payOrder.getExtra()).getString("openId"); String sceneInfo = null; if(tradeType.equals(PayConstant.WxConstant.TRADE_TYPE_MWEB)) sceneInfo = JSON.parseObject(payOrder.getExtra()).getString("sceneInfo"); // 微信统一下单请求对象 WxPayUnifiedOrderRequest request = new WxPayUnifiedOrderRequest(); request.setDeviceInfo(deviceInfo); request.setBody(body); request.setDetail(detail); request.setAttach(attach); request.setOutTradeNo(outTradeNo); request.setFeeType(feeType); request.setTotalFee(totalFee); request.setSpbillCreateIp(spBillCreateIP); request.setTimeStart(timeStart); request.setTimeExpire(timeExpire); request.setGoodsTag(goodsTag); request.setNotifyURL(notifyUrl); request.setTradeType(tradeType); request.setProductId(productId); request.setLimitPay(limitPay); request.setOpenid(openId); request.setSceneInfo(sceneInfo); return request; }