com.github.binarywang.wxpay.exception.WxPayException Java Examples

The following examples show how to use com.github.binarywang.wxpay.exception.WxPayException. 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: YxMiniPayService.java    From yshopmall with Apache License 2.0 7 votes vote down vote up
/**
 * 退款
 * @param orderId
 * @param totalFee
 * @throws WxPayException
 */
public void refundOrder(String orderId, Integer totalFee) throws WxPayException {
    String apiUrl = redisHandler.getVal(ShopKeyUtils.getApiUrl());
    if (StrUtil.isBlank(apiUrl)) throw new ErrorRequestException("请配置api地址");

    WxPayService wxPayService = WxPayConfiguration.getWxAppPayService();
    WxPayRefundRequest wxPayRefundRequest = new WxPayRefundRequest();

    wxPayRefundRequest.setTotalFee(totalFee);//订单总金额
    wxPayRefundRequest.setOutTradeNo(orderId);
    wxPayRefundRequest.setOutRefundNo(orderId);
    wxPayRefundRequest.setRefundFee(totalFee);//退款金额
    wxPayRefundRequest.setNotifyUrl(apiUrl + "/api/notify/refund");

    wxPayService.refund(wxPayRefundRequest);
}
 
Example #2
Source File: BaseWxPayServiceImplTest.java    From weixin-java-tools with Apache License 2.0 6 votes vote down vote up
/**
 * Test method for {@link WxPayService#unifiedOrder(WxPayUnifiedOrderRequest)}.
 */
@Test
public void testUnifiedOrder() throws WxPayException {
  WxPayUnifiedOrderRequest request = WxPayUnifiedOrderRequest.newBuilder()
    .body("我去")
    .totalFee(1)
    .spbillCreateIp("11.1.11.1")
    .notifyUrl("111111")
    .tradeType(TradeType.JSAPI)
    .openid(((XmlWxPayConfig) this.payService.getConfig()).getOpenid())
    .outTradeNo("1111112")
    .build();
  request.setSignType(SignType.HMAC_SHA256);
  WxPayUnifiedOrderResult result = this.payService.unifiedOrder(request);
  this.logger.info(result.toString());
  this.logger.warn(this.payService.getWxApiData().toString());
}
 
Example #3
Source File: BaseWxPayServiceImpl.java    From weixin-java-tools with Apache License 2.0 6 votes vote down vote up
@Override
public String queryComment(Date beginDate, Date endDate, Integer offset, Integer limit) throws WxPayException {
  WxPayQueryCommentRequest request = new WxPayQueryCommentRequest();
  request.setBeginTime(QUERY_COMMENT_DATE_FORMAT.format(beginDate));
  request.setEndTime(QUERY_COMMENT_DATE_FORMAT.format(endDate));
  request.setOffset(offset);
  request.setLimit(limit);
  request.setSignType(SignType.HMAC_SHA256);

  request.checkAndSign(this.getConfig());

  String url = this.getPayBaseUrl() + "/billcommentsp/batchquerycomment";

  String responseContent = this.post(url, request.toXML(), true);
  if (responseContent.startsWith("<")) {
    throw WxPayException.from(BaseWxPayResult.fromXML(responseContent, WxPayCommonResult.class));
  }

  return responseContent;
}
 
Example #4
Source File: WxPayServiceJoddHttpImpl.java    From weixin-java-tools with Apache License 2.0 6 votes vote down vote up
private String getResponseString(HttpResponse response) throws WxPayException {
  try {
    this.log.debug("【微信服务器响应头信息】:\n{}", response.toString(false));
  } catch (NullPointerException e) {
    throw new WxPayException("response.toString() 居然抛出空指针异常了", e);
  }

  String responseString = response.bodyText();

  if (StringUtils.isBlank(responseString)) {
    throw new WxPayException("响应信息为空");
  }

  if (StringUtils.isBlank(response.charset())) {
    responseString = new String(responseString.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
  }

  return responseString;
}
 
Example #5
Source File: WxPayServiceApacheHttpImpl.java    From weixin-java-tools with Apache License 2.0 6 votes vote down vote up
@Override
public String post(String url, String requestStr, boolean useKey) throws WxPayException {
  try {
    HttpClientBuilder httpClientBuilder = this.createHttpClientBuilder(useKey);
    HttpPost httpPost = this.createHttpPost(url, requestStr);
    try (CloseableHttpClient httpClient = httpClientBuilder.build()) {
      try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
        String responseString = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
        this.log.info("\n【请求地址】:{}\n【请求数据】:{}\n【响应数据】:{}", url, requestStr, responseString);
        wxApiData.set(new WxPayApiData(url, requestStr, responseString, null));
        return responseString;
      }
    } finally {
      httpPost.releaseConnection();
    }
  } catch (Exception e) {
    this.log.error("\n【请求地址】:{}\n【请求数据】:{}\n【异常信息】:{}", url, requestStr, e.getMessage());
    wxApiData.set(new WxPayApiData(url, requestStr, null, e.getMessage()));
    throw new WxPayException(e.getMessage(), e);
  }
}
 
Example #6
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 #7
Source File: YxPayService.java    From yshopmall with Apache License 2.0 6 votes vote down vote up
/**
 * 退款
 * @param orderId
 * @param totalFee
 * @throws WxPayException
 */
public void refundOrder(String orderId, Integer totalFee) throws WxPayException {
    String apiUrl = redisHandler.getVal(ShopKeyUtils.getApiUrl());
    if (StrUtil.isBlank(apiUrl)) throw new ErrorRequestException("请配置api地址");

    WxPayService wxPayService = WxPayConfiguration.getPayService();
    WxPayRefundRequest wxPayRefundRequest = new WxPayRefundRequest();

    wxPayRefundRequest.setTotalFee(totalFee);//订单总金额
    wxPayRefundRequest.setOutTradeNo(orderId);
    wxPayRefundRequest.setOutRefundNo(orderId);
    wxPayRefundRequest.setRefundFee(totalFee);//退款金额
    wxPayRefundRequest.setNotifyUrl(apiUrl + "/api/notify/refund");

    wxPayService.refund(wxPayRefundRequest);
}
 
Example #8
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 #9
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 #10
Source File: StockUserChargeServiceImpl.java    From charging_pile_cloud with MIT License 6 votes vote down vote up
@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 #11
Source File: WxPayServiceApacheHttpImpl.java    From weixin-java-tools with Apache License 2.0 6 votes vote down vote up
private HttpClientBuilder createHttpClientBuilder(boolean useKey) throws WxPayException {
  HttpClientBuilder httpClientBuilder = HttpClients.custom();
  if (useKey) {
    this.initSSLContext(httpClientBuilder);
  }

  if (StringUtils.isNotBlank(this.getConfig().getHttpProxyHost())
    && this.getConfig().getHttpProxyPort() > 0) {
    // 使用代理服务器 需要用户认证的代理服务器
    CredentialsProvider provider = new BasicCredentialsProvider();
    provider.setCredentials(
      new AuthScope(this.getConfig().getHttpProxyHost(), this.getConfig().getHttpProxyPort()),
      new UsernamePasswordCredentials(this.getConfig().getHttpProxyUsername(), this.getConfig().getHttpProxyPassword()));
    httpClientBuilder.setDefaultCredentialsProvider(provider);
  }
  return httpClientBuilder;
}
 
Example #12
Source File: BaseWxPayServiceImpl.java    From weixin-java-tools with Apache License 2.0 6 votes vote down vote up
@Override
public WxPayBillResult downloadBill(WxPayDownloadBillRequest request) throws WxPayException {
  request.checkAndSign(this.getConfig());

  String url = this.getPayBaseUrl() + "/pay/downloadbill";

  String responseContent;
  if (TarType.GZIP.equals(request.getTarType())) {
    responseContent = this.handleGzipBill(url, request.toXML());
  } else {
    responseContent = this.post(url, request.toXML(), false);
    if (responseContent.startsWith("<")) {
      throw WxPayException.from(BaseWxPayResult.fromXML(responseContent, WxPayCommonResult.class));
    }
  }

  return this.handleBill(request.getBillType(), responseContent);
}
 
Example #13
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 #14
Source File: WxPayServiceApacheHttpImpl.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
private void initSSLContext(HttpClientBuilder httpClientBuilder) throws WxPayException {
  SSLContext sslContext = this.getConfig().getSslContext();
  if (null == sslContext) {
    sslContext = this.getConfig().initSSLContext();
  }

  SSLConnectionSocketFactory connectionSocketFactory = new SSLConnectionSocketFactory(sslContext,
    new String[]{"TLSv1"}, null, new DefaultHostnameVerifier());
  httpClientBuilder.setSSLSocketFactory(connectionSocketFactory);
}
 
Example #15
Source File: BaseWxPayServiceImpl.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
@Override
public WxPayOrderCloseResult closeOrder(String outTradeNo) throws WxPayException {
  if (StringUtils.isBlank(outTradeNo)) {
    throw new WxPayException("out_trade_no不能为空");
  }

  WxPayOrderCloseRequest request = new WxPayOrderCloseRequest();
  request.setOutTradeNo(StringUtils.trimToNull(outTradeNo));

  return this.closeOrder(request);
}
 
Example #16
Source File: YxPayService.java    From yshopmall with Apache License 2.0 5 votes vote down vote up
/**
 * 企业打款
 * @param openid
 * @param no
 * @param userName
 * @param amount
 * @throws WxPayException
 */
public void entPay(String openid,String no,String userName,Integer amount) throws WxPayException{
    WxPayService wxPayService = WxPayConfiguration.getPayService();
    EntPayRequest entPayRequest = new EntPayRequest();

    entPayRequest.setOpenid(openid);
    entPayRequest.setPartnerTradeNo(no);
    entPayRequest.setCheckName("FORCE_CHECK");
    entPayRequest.setReUserName(userName);
    entPayRequest.setAmount(amount);
    entPayRequest.setDescription("提现");
    entPayRequest.setSpbillCreateIp("127.0.0.1");
    wxPayService.getEntPayService().entPay(entPayRequest);

}
 
Example #17
Source File: AppWxPayController.java    From charging_pile_cloud with MIT License 5 votes vote down vote up
/**
 * 用户小程序充值
 */
@RequestMapping(value = "wxAppPay", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> wxPay(StockUserParamsVO paramsVO, StockUserCharge charge) throws WxPayException {
    if(paramsVO.getStockUserId() == null||charge.getFee()==null){
        return ResponseUtil.getNotNormalMap(ResponseMsg.ERROR_PARAM);
    }
    StockUser stockUser = stockUserService.getById(paramsVO.getStockUserId());
    if(stockUser == null){
        return ResponseUtil.getNotNormalMap(ResponseMsg.NOUSER);
    }
    Object result= stockUserChargeService.createUserCharge(stockUser,charge);

    return ResponseUtil.getSuccessMap(result);
}
 
Example #18
Source File: WxPayRefundQueryRequest.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
@Override
protected void checkConstraints() throws WxPayException {
  if ((StringUtils.isBlank(transactionId) && StringUtils.isBlank(outTradeNo)
    && StringUtils.isBlank(outRefundNo) && StringUtils.isBlank(refundId)) ||
    (StringUtils.isNotBlank(transactionId) && StringUtils.isNotBlank(outTradeNo)
      && StringUtils.isNotBlank(outRefundNo) && StringUtils.isNotBlank(refundId))) {
    throw new WxPayException("transaction_id,out_trade_no,out_refund_no,refund_id 必须四选一");
  }

}
 
Example #19
Source File: BaseWxPayServiceImpl.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
@Override
public WxPayMicropayResult micropay(WxPayMicropayRequest request) throws WxPayException {
  request.checkAndSign(this.getConfig());

  String url = this.getPayBaseUrl() + "/pay/micropay";
  String responseContent = this.post(url, request.toXML(), false);
  WxPayMicropayResult result = BaseWxPayResult.fromXML(responseContent, WxPayMicropayResult.class);
  result.checkResult(this, request.getSignType(), true);
  return result;
}
 
Example #20
Source File: BaseWxPayServiceImpl.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
@Override
public WxPayCouponStockQueryResult queryCouponStock(WxPayCouponStockQueryRequest request) throws WxPayException {
  request.checkAndSign(this.getConfig());

  String url = this.getPayBaseUrl() + "/mmpaymkttransfers/query_coupon_stock";
  String responseContent = this.post(url, request.toXML(), false);
  WxPayCouponStockQueryResult result = BaseWxPayResult.fromXML(responseContent, WxPayCouponStockQueryResult.class);
  result.checkResult(this, request.getSignType(), true);
  return result;
}
 
Example #21
Source File: WxPayServiceJoddHttpImpl.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
@Override
public String post(String url, String requestStr, boolean useKey) throws WxPayException {
  try {
    HttpRequest request = this.buildHttpRequest(url, requestStr, useKey);
    String responseString = this.getResponseString(request.send());

    this.log.info("\n【请求地址】:{}\n【请求数据】:{}\n【响应数据】:{}", url, requestStr, responseString);
    wxApiData.set(new WxPayApiData(url, requestStr, responseString, null));
    return responseString;
  } catch (Exception e) {
    this.log.error("\n【请求地址】:{}\n【请求数据】:{}\n【异常信息】:{}", url, requestStr, e.getMessage());
    wxApiData.set(new WxPayApiData(url, requestStr, null, e.getMessage()));
    throw new WxPayException(e.getMessage(), e);
  }
}
 
Example #22
Source File: BaseWxPayServiceImpl.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
@Override
public WxPayRefundResult refund(WxPayRefundRequest request) throws WxPayException {
  request.checkAndSign(this.getConfig());

  String url = this.getPayBaseUrl() + "/secapi/pay/refund";
  String responseContent = this.post(url, request.toXML(), true);
  WxPayRefundResult result = BaseWxPayResult.fromXML(responseContent, WxPayRefundResult.class);
  result.composeRefundCoupons();
  result.checkResult(this, request.getSignType(), true);
  return result;
}
 
Example #23
Source File: WxPayRefundRequest.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
@Override
protected void checkConstraints() throws WxPayException {
  if (StringUtils.isNotBlank(this.getRefundAccount())) {
    if (!ArrayUtils.contains(REFUND_ACCOUNT, this.getRefundAccount())) {
      throw new WxPayException(
        String.format("refund_account目前必须为%s其中之一,实际值:%s", Arrays.toString(REFUND_ACCOUNT), this.getRefundAccount()));
    }
  }

  if (StringUtils.isBlank(this.getOutTradeNo()) && StringUtils.isBlank(this.getTransactionId())) {
    throw new WxPayException("transaction_id 和 out_trade_no 不能同时为空,必须提供一个");
  }
}
 
Example #24
Source File: EntPayServiceImpl.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
private File buildPublicKeyFile() throws WxPayException {
  try {
    String publicKeyStr = this.getPublicKey();
    Path tmpFile = Files.createTempFile("payToBank", ".pem");
    Files.write(tmpFile, publicKeyStr.getBytes());
    return tmpFile.toFile();
  } catch (Exception e) {
    throw new WxPayException("生成加密公钥文件时发生异常", e);
  }
}
 
Example #25
Source File: EntPayServiceImpl.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
@Override
public EntPayBankQueryResult queryPayBank(String partnerTradeNo) throws WxPayException {
  EntPayBankQueryRequest request = new EntPayBankQueryRequest();
  request.setPartnerTradeNo(partnerTradeNo);
  request.checkAndSign(this.payService.getConfig());

  String url = this.payService.getPayBaseUrl() + "/mmpaysptrans/query_bank";
  String responseContent = this.payService.post(url, request.toXML(), true);
  EntPayBankQueryResult result = BaseWxPayResult.fromXML(responseContent, EntPayBankQueryResult.class);
  result.checkResult(this.payService, request.getSignType(), true);
  return result;
}
 
Example #26
Source File: WxPayRefundRequest.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
@Override
public void checkAndSign(WxPayConfig config) throws WxPayException {
  if (StringUtils.isBlank(this.getOpUserId())) {
    this.setOpUserId(config.getMchId());
  }

  super.checkAndSign(config);
}
 
Example #27
Source File: EntPayServiceImpl.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
@Override
public EntPayResult entPay(EntPayRequest request) throws WxPayException {
  request.checkAndSign(this.payService.getConfig());
  String url = this.payService.getPayBaseUrl() + "/mmpaymkttransfers/promotion/transfers";

  String responseContent = this.payService.post(url, request.toXML(), true);
  EntPayResult result = BaseWxPayResult.fromXML(responseContent, EntPayResult.class);
  result.checkResult(this.payService, request.getSignType(), true);
  return result;
}
 
Example #28
Source File: EntPayServiceImpl.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
@Override
public EntPayBankResult payBank(EntPayBankRequest request) throws WxPayException {
  File publicKeyFile = this.buildPublicKeyFile();
  request.setEncBankNo(this.encryptRSA(publicKeyFile, request.getEncBankNo()));
  request.setEncTrueName(this.encryptRSA(publicKeyFile, request.getEncTrueName()));
  publicKeyFile.deleteOnExit();

  request.checkAndSign(this.payService.getConfig());

  String url = this.payService.getPayBaseUrl() + "/mmpaysptrans/pay_bank";
  String responseContent = this.payService.post(url, request.toXML(), true);
  EntPayBankResult result = BaseWxPayResult.fromXML(responseContent, EntPayBankResult.class);
  result.checkResult(this.payService, request.getSignType(), true);
  return result;
}
 
Example #29
Source File: WxPayUnifiedOrderRequest.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
@Override
public void checkAndSign(WxPayConfig config) throws WxPayException {
  if (StringUtils.isBlank(this.getNotifyUrl())) {
    this.setNotifyUrl(config.getNotifyUrl());
  }

  if (StringUtils.isBlank(this.getTradeType())) {
    this.setTradeType(config.getTradeType());
  }

  super.checkAndSign(config);
}
 
Example #30
Source File: EntPayServiceImpl.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
@Override
public String getPublicKey() throws WxPayException {
  WxPayDefaultRequest request = new WxPayDefaultRequest();
  request.setMchId(this.payService.getConfig().getMchId());
  request.setNonceStr(String.valueOf(System.currentTimeMillis()));
  request.setSign(SignUtils.createSign(request, null, this.payService.getConfig().getMchKey(),
    true));

  String url = "https://fraud.mch.weixin.qq.com/risk/getpublickey";
  String responseContent = this.payService.post(url, request.toXML(), true);
  GetPublicKeyResult result = BaseWxPayResult.fromXML(responseContent, GetPublicKeyResult.class);
  result.checkResult(this.payService, request.getSignType(), true);
  return result.getPubKey();
}