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

The following examples show how to use com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest#setDetail() . 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: 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 2
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);
}
 
Example 3
Source File: PayChannel4WxServiceImpl.java    From xxpay-master with MIT License 4 votes vote down vote up
/**
 * 构建微信统一下单请求数据
 * @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 4
Source File: PayChannel4WxController.java    From xxpay-master with MIT License 4 votes vote down vote up
/**
 * 构建微信统一下单请求数据
 * @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;
}