Java Code Examples for com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest#setNotifyUrl()

The following examples show how to use com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest#setNotifyUrl() . 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 vote down vote up
/**
 * 支付接口
 */
@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: YxPayService.java    From yshopmall with Apache License 2.0 6 votes vote down vote up
/**
 * 微信公众号支付
 *
 * @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 3
Source File: YxPayService.java    From yshopmall with Apache License 2.0 6 votes vote down vote up
/**
 * 微信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;

}
 
Example 4
Source File: YxPayService.java    From yshopmall with Apache License 2.0 6 votes vote down vote up
/**
 * 微信app支付
 *
 * @param orderId
 * @param body
 * @param totalFee
 * @return
 * @throws WxPayException
 */
public WxPayAppOrderResult appPay(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.getAppPayService();
    WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();

    orderRequest.setTradeType("APP");
    orderRequest.setBody(body);
    orderRequest.setOutTradeNo(orderId);
    orderRequest.setTotalFee(totalFee);
    orderRequest.setSpbillCreateIp("127.0.0.1");
    orderRequest.setNotifyUrl(apiUrl + "/api/wechat/notify");
    orderRequest.setAttach(attach);

    WxPayAppOrderResult appOrderResult = wxPayService.createOrder(orderRequest);

    return appOrderResult;

}
 
Example 5
Source File: YxMiniPayService.java    From yshopmall with Apache License 2.0 6 votes vote down vote up
/**
 * 小程序支付
 *
 * @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 6
Source File: PayController.java    From supplierShop with MIT License 4 votes vote down vote up
/**
 * 调用统一下单接口,并组装生成支付所需参数对象.
 *
 * @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: WxUnifiedOrderServiceImpl.java    From fw-cloud-framework with MIT License 4 votes vote down vote up
/**
 * 构建微信统一下单请求数据
 */
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 8
Source File: MyParkAPI.java    From springboot-seed with MIT License 4 votes vote down vote up
@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);
}