@Test public void getPrepay() throws Exception { Assert.assertNotNull(prepayData); WechatPrepayResponseDto responseDto = WechatPrepayService.getPrepay(prepayData, ""); Assert.assertNotNull(responseDto); Assert.assertEquals("SUCCESS", responseDto.getReturn_code()); Assert.assertNotNull(responseDto.getPrepay_id()); Assert.assertNotNull(responseDto.getSign()); Assert.assertNotNull(responseDto.getAmount()); Assert.assertTrue(responseDto.getAmount() > 0); logger.info("prepay response : {}", responseDto); }
static WechatPrepayResponseDto getPrepay(WechatPrepayData prepayData, String hostEndpoint) throws Exception { Assert.isNotNull(hostEndpoint); WechatPrepayRequestDto prepayDto = new WechatPrepayRequestDto( prepayData.getAppId(), prepayData.getMchId(), prepayData.getMchSecret()); prepayDto.setNonce_str(DateUtil.format(new Date(), DateUtil.DATE_KEY_STR) + ValidateCode.randomCode(10)); prepayDto.setBody(prepayData.getProductName()); prepayDto.setProductId(prepayData.getProductId()); prepayDto.setOut_trade_no(prepayData.getOrderNo()); Integer totalFee = prepayData.getTotal_fee().multiply(DECIMAL_100).intValue(); prepayDto.setTotal_fee(totalFee); prepayDto.setSpbill_create_ip("127.0.0.1"); prepayDto.setNotify_url(hostEndpoint.concat(WeChatConstant.WECHAT_PREPAY_NOTIFY_URL)); prepayDto.setTrade_type(prepayData.getTradeType()); prepayDto.setOpenid(prepayData.getOpenId() != null ? prepayData.getOpenId() : ""); String wechatXml = prepayDto.getWechatXml(); logger.info("WX Prepay Request: " + wechatXml); String content = HttpClientPostUtils.getHttpPostContentByEntity( WeChatConstant.CREATE_ORDER_URL, new StringEntity(wechatXml, StandardCharsets.UTF_8.name()), HttpClientConstants.HEADER_VALUE_FORM, StandardCharsets.UTF_8.name()); logger.info("WX Prepay Response: {} ", content.getBytes("UTF-8")); WechatPrepayResponseDto result = parsePrepayXml(content); result.setAmount(totalFee); result.setAppId(prepayData.getAppId()); result.setSecurityKey(prepayData.getMchSecret()); return result; }
WechatPrepayService { static WechatPrepayResponseDto getPrepay(WechatPrepayData prepayData, String hostEndpoint) throws Exception { Assert.isNotNull(hostEndpoint); WechatPrepayRequestDto prepayDto = new WechatPrepayRequestDto( prepayData.getAppId(), prepayData.getMchId(), prepayData.getMchSecret()); prepayDto.setNonce_str(DateUtil.format(new Date(), DateUtil.DATE_KEY_STR) + ValidateCode.randomCode(10)); prepayDto.setBody(prepayData.getProductName()); prepayDto.setProductId(prepayData.getProductId()); prepayDto.setOut_trade_no(prepayData.getOrderNo()); Integer totalFee = prepayData.getTotal_fee().multiply(DECIMAL_100).intValue(); prepayDto.setTotal_fee(totalFee); prepayDto.setSpbill_create_ip("127.0.0.1"); prepayDto.setNotify_url(hostEndpoint.concat(WeChatConstant.WECHAT_PREPAY_NOTIFY_URL)); prepayDto.setTrade_type(prepayData.getTradeType()); prepayDto.setOpenid(prepayData.getOpenId() != null ? prepayData.getOpenId() : ""); String wechatXml = prepayDto.getWechatXml(); logger.info("WX Prepay Request: " + wechatXml); String content = HttpClientPostUtils.getHttpPostContentByEntity( WeChatConstant.CREATE_ORDER_URL, new StringEntity(wechatXml, StandardCharsets.UTF_8.name()), HttpClientConstants.HEADER_VALUE_FORM, StandardCharsets.UTF_8.name()); logger.info("WX Prepay Response: {} ", content.getBytes("UTF-8")); WechatPrepayResponseDto result = parsePrepayXml(content); result.setAmount(totalFee); result.setAppId(prepayData.getAppId()); result.setSecurityKey(prepayData.getMchSecret()); return result; } }
WechatPrepayService { static WechatPrepayResponseDto getPrepay(WechatPrepayData prepayData, String hostEndpoint) throws Exception { Assert.isNotNull(hostEndpoint); WechatPrepayRequestDto prepayDto = new WechatPrepayRequestDto( prepayData.getAppId(), prepayData.getMchId(), prepayData.getMchSecret()); prepayDto.setNonce_str(DateUtil.format(new Date(), DateUtil.DATE_KEY_STR) + ValidateCode.randomCode(10)); prepayDto.setBody(prepayData.getProductName()); prepayDto.setProductId(prepayData.getProductId()); prepayDto.setOut_trade_no(prepayData.getOrderNo()); Integer totalFee = prepayData.getTotal_fee().multiply(DECIMAL_100).intValue(); prepayDto.setTotal_fee(totalFee); prepayDto.setSpbill_create_ip("127.0.0.1"); prepayDto.setNotify_url(hostEndpoint.concat(WeChatConstant.WECHAT_PREPAY_NOTIFY_URL)); prepayDto.setTrade_type(prepayData.getTradeType()); prepayDto.setOpenid(prepayData.getOpenId() != null ? prepayData.getOpenId() : ""); String wechatXml = prepayDto.getWechatXml(); logger.info("WX Prepay Request: " + wechatXml); String content = HttpClientPostUtils.getHttpPostContentByEntity( WeChatConstant.CREATE_ORDER_URL, new StringEntity(wechatXml, StandardCharsets.UTF_8.name()), HttpClientConstants.HEADER_VALUE_FORM, StandardCharsets.UTF_8.name()); logger.info("WX Prepay Response: {} ", content.getBytes("UTF-8")); WechatPrepayResponseDto result = parsePrepayXml(content); result.setAmount(totalFee); result.setAppId(prepayData.getAppId()); result.setSecurityKey(prepayData.getMchSecret()); return result; }  }
WechatPrepayService { static WechatPrepayResponseDto getPrepay(WechatPrepayData prepayData, String hostEndpoint) throws Exception { Assert.isNotNull(hostEndpoint); WechatPrepayRequestDto prepayDto = new WechatPrepayRequestDto( prepayData.getAppId(), prepayData.getMchId(), prepayData.getMchSecret()); prepayDto.setNonce_str(DateUtil.format(new Date(), DateUtil.DATE_KEY_STR) + ValidateCode.randomCode(10)); prepayDto.setBody(prepayData.getProductName()); prepayDto.setProductId(prepayData.getProductId()); prepayDto.setOut_trade_no(prepayData.getOrderNo()); Integer totalFee = prepayData.getTotal_fee().multiply(DECIMAL_100).intValue(); prepayDto.setTotal_fee(totalFee); prepayDto.setSpbill_create_ip("127.0.0.1"); prepayDto.setNotify_url(hostEndpoint.concat(WeChatConstant.WECHAT_PREPAY_NOTIFY_URL)); prepayDto.setTrade_type(prepayData.getTradeType()); prepayDto.setOpenid(prepayData.getOpenId() != null ? prepayData.getOpenId() : ""); String wechatXml = prepayDto.getWechatXml(); logger.info("WX Prepay Request: " + wechatXml); String content = HttpClientPostUtils.getHttpPostContentByEntity( WeChatConstant.CREATE_ORDER_URL, new StringEntity(wechatXml, StandardCharsets.UTF_8.name()), HttpClientConstants.HEADER_VALUE_FORM, StandardCharsets.UTF_8.name()); logger.info("WX Prepay Response: {} ", content.getBytes("UTF-8")); WechatPrepayResponseDto result = parsePrepayXml(content); result.setAmount(totalFee); result.setAppId(prepayData.getAppId()); result.setSecurityKey(prepayData.getMchSecret()); return result; }   }
WechatPrepayService { static WechatPrepayResponseDto getPrepay(WechatPrepayData prepayData, String hostEndpoint) throws Exception { Assert.isNotNull(hostEndpoint); WechatPrepayRequestDto prepayDto = new WechatPrepayRequestDto( prepayData.getAppId(), prepayData.getMchId(), prepayData.getMchSecret()); prepayDto.setNonce_str(DateUtil.format(new Date(), DateUtil.DATE_KEY_STR) + ValidateCode.randomCode(10)); prepayDto.setBody(prepayData.getProductName()); prepayDto.setProductId(prepayData.getProductId()); prepayDto.setOut_trade_no(prepayData.getOrderNo()); Integer totalFee = prepayData.getTotal_fee().multiply(DECIMAL_100).intValue(); prepayDto.setTotal_fee(totalFee); prepayDto.setSpbill_create_ip("127.0.0.1"); prepayDto.setNotify_url(hostEndpoint.concat(WeChatConstant.WECHAT_PREPAY_NOTIFY_URL)); prepayDto.setTrade_type(prepayData.getTradeType()); prepayDto.setOpenid(prepayData.getOpenId() != null ? prepayData.getOpenId() : ""); String wechatXml = prepayDto.getWechatXml(); logger.info("WX Prepay Request: " + wechatXml); String content = HttpClientPostUtils.getHttpPostContentByEntity( WeChatConstant.CREATE_ORDER_URL, new StringEntity(wechatXml, StandardCharsets.UTF_8.name()), HttpClientConstants.HEADER_VALUE_FORM, StandardCharsets.UTF_8.name()); logger.info("WX Prepay Response: {} ", content.getBytes("UTF-8")); WechatPrepayResponseDto result = parsePrepayXml(content); result.setAmount(totalFee); result.setAppId(prepayData.getAppId()); result.setSecurityKey(prepayData.getMchSecret()); return result; }    }