@Test public void testCreateOrder() throws Exception { }
@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: { String appId = unifiedOrderResult.getAppid(); if (StringUtils.isNotEmpty(unifiedOrderResult.getSubAppId())) { appId = unifiedOrderResult.getSubAppId(); } Map<String, String> configMap = new HashMap<>(8); 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("该交易类型暂不支持"); } } }
BaseWxPayServiceImpl implements WxPayService { @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: { String appId = unifiedOrderResult.getAppid(); if (StringUtils.isNotEmpty(unifiedOrderResult.getSubAppId())) { appId = unifiedOrderResult.getSubAppId(); } Map<String, String> configMap = new HashMap<>(8); 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("该交易类型暂不支持"); } } } }
BaseWxPayServiceImpl implements WxPayService { @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: { String appId = unifiedOrderResult.getAppid(); if (StringUtils.isNotEmpty(unifiedOrderResult.getSubAppId())) { appId = unifiedOrderResult.getSubAppId(); } Map<String, String> configMap = new HashMap<>(8); 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("该交易类型暂不支持"); } } }  }
BaseWxPayServiceImpl implements WxPayService { @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: { String appId = unifiedOrderResult.getAppid(); if (StringUtils.isNotEmpty(unifiedOrderResult.getSubAppId())) { appId = unifiedOrderResult.getSubAppId(); } Map<String, String> configMap = new HashMap<>(8); 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("该交易类型暂不支持"); } } }  @Override EntPayService getEntPayService(); @Override void setEntPayService(EntPayService entPayService); @Override WxPayConfig getConfig(); @Override void setConfig(WxPayConfig config); @Override String getPayBaseUrl(); @Override WxPayRefundResult refund(WxPayRefundRequest request); @Override WxPayRefundQueryResult refundQuery(String transactionId, String outTradeNo, String outRefundNo, String refundId); @Override WxPayRefundQueryResult refundQuery(WxPayRefundQueryRequest request); @Override WxPayOrderNotifyResult parseOrderNotifyResult(String xmlData); @Override WxPayRefundNotifyResult parseRefundNotifyResult(String xmlData); @Override WxScanPayNotifyResult parseScanPayNotifyResult(String xmlData); @Override WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request); @Override WxPayRedpackQueryResult queryRedpack(String mchBillNo); @Override WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo); @Override WxPayOrderQueryResult queryOrder(WxPayOrderQueryRequest request); @Override WxPayOrderCloseResult closeOrder(String outTradeNo); @Override WxPayOrderCloseResult closeOrder(WxPayOrderCloseRequest request); @Override T createOrder(WxPayUnifiedOrderRequest request); @Override WxPayUnifiedOrderResult unifiedOrder(WxPayUnifiedOrderRequest request); @Override @Deprecated Map<String, String> getPayInfo(WxPayUnifiedOrderRequest request); @Override byte[] createScanPayQrcodeMode1(String productId, File logoFile, Integer sideLength); @Override String createScanPayQrcodeMode1(String productId); @Override byte[] createScanPayQrcodeMode2(String codeUrl, File logoFile, Integer sideLength); @Override void report(WxPayReportRequest request); @Override WxPayBillResult downloadBill(String billDate, String billType, String tarType, String deviceInfo); @Override WxPayBillResult downloadBill(WxPayDownloadBillRequest request); @Override WxPayMicropayResult micropay(WxPayMicropayRequest request); @Override WxPayOrderReverseResult reverseOrder(WxPayOrderReverseRequest request); @Override String shorturl(WxPayShorturlRequest request); @Override String shorturl(String longUrl); @Override String authcode2Openid(WxPayAuthcode2OpenidRequest request); @Override String authcode2Openid(String authCode); @Override String getSandboxSignKey(); @Override WxPayCouponSendResult sendCoupon(WxPayCouponSendRequest request); @Override WxPayCouponStockQueryResult queryCouponStock(WxPayCouponStockQueryRequest request); @Override WxPayCouponInfoQueryResult queryCouponInfo(WxPayCouponInfoQueryRequest request); @Override WxPayApiData getWxApiData(); @Override String queryComment(Date beginDate, Date endDate, Integer offset, Integer limit); }
BaseWxPayServiceImpl implements WxPayService { @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: { String appId = unifiedOrderResult.getAppid(); if (StringUtils.isNotEmpty(unifiedOrderResult.getSubAppId())) { appId = unifiedOrderResult.getSubAppId(); } Map<String, String> configMap = new HashMap<>(8); 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("该交易类型暂不支持"); } } }  @Override EntPayService getEntPayService(); @Override void setEntPayService(EntPayService entPayService); @Override WxPayConfig getConfig(); @Override void setConfig(WxPayConfig config); @Override String getPayBaseUrl(); @Override WxPayRefundResult refund(WxPayRefundRequest request); @Override WxPayRefundQueryResult refundQuery(String transactionId, String outTradeNo, String outRefundNo, String refundId); @Override WxPayRefundQueryResult refundQuery(WxPayRefundQueryRequest request); @Override WxPayOrderNotifyResult parseOrderNotifyResult(String xmlData); @Override WxPayRefundNotifyResult parseRefundNotifyResult(String xmlData); @Override WxScanPayNotifyResult parseScanPayNotifyResult(String xmlData); @Override WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request); @Override WxPayRedpackQueryResult queryRedpack(String mchBillNo); @Override WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo); @Override WxPayOrderQueryResult queryOrder(WxPayOrderQueryRequest request); @Override WxPayOrderCloseResult closeOrder(String outTradeNo); @Override WxPayOrderCloseResult closeOrder(WxPayOrderCloseRequest request); @Override T createOrder(WxPayUnifiedOrderRequest request); @Override WxPayUnifiedOrderResult unifiedOrder(WxPayUnifiedOrderRequest request); @Override @Deprecated Map<String, String> getPayInfo(WxPayUnifiedOrderRequest request); @Override byte[] createScanPayQrcodeMode1(String productId, File logoFile, Integer sideLength); @Override String createScanPayQrcodeMode1(String productId); @Override byte[] createScanPayQrcodeMode2(String codeUrl, File logoFile, Integer sideLength); @Override void report(WxPayReportRequest request); @Override WxPayBillResult downloadBill(String billDate, String billType, String tarType, String deviceInfo); @Override WxPayBillResult downloadBill(WxPayDownloadBillRequest request); @Override WxPayMicropayResult micropay(WxPayMicropayRequest request); @Override WxPayOrderReverseResult reverseOrder(WxPayOrderReverseRequest request); @Override String shorturl(WxPayShorturlRequest request); @Override String shorturl(String longUrl); @Override String authcode2Openid(WxPayAuthcode2OpenidRequest request); @Override String authcode2Openid(String authCode); @Override String getSandboxSignKey(); @Override WxPayCouponSendResult sendCoupon(WxPayCouponSendRequest request); @Override WxPayCouponStockQueryResult queryCouponStock(WxPayCouponStockQueryRequest request); @Override WxPayCouponInfoQueryResult queryCouponInfo(WxPayCouponInfoQueryRequest request); @Override WxPayApiData getWxApiData(); @Override String queryComment(Date beginDate, Date endDate, Integer offset, Integer limit);  }