| | |
| | | * 微信发起转账(前缀) |
| | | */ |
| | | public static final String WE_CHAT_PAY_URL_PRE = "https://api.mch.weixin.qq.com/v3/fund-app/mch-transfer/transfer-bills"; |
| | | public static final String WE_CHAT_PAY_QUERY_URL_PRE = "https://api.mch.weixin.qq.com/v3/fund-app/mch-transfer/transfer-bills/out-bill-no/"; |
| | | |
| | | /** |
| | | * 微信商家转账到用户零钱接口地址(后缀) |
| | | */ |
| | | public static final String WE_CHAT_URL_SUF = "/v3/transfer/batches"; |
| | | public static final String WE_CHAT_QUERY_URL_SUF = "/v3/fund-app/mch-transfer/transfer-bills/out-bill-no/"; |
| | | |
| | | /** |
| | | * 微信转账接口调用所返回的成功参数之一 |
| | |
| | | throw new GlobalException("订单信息异常!"); |
| | | } |
| | | Boolean b = withdrawService.confirmWithdraw(openId, userId, order); |
| | | // if (!b) { |
| | | // throw new GlobalException("提现失败!"); |
| | | // } |
| | | if (!b) { |
| | | throw new GlobalException("提现失败!"); |
| | | } |
| | | }else { |
| | | Order order = orderService.lambdaQuery() |
| | | .eq(Order::getId, withdraw.getOrderId()) |
| | |
| | | throw new GlobalException("当前订单提现申请已通过!"); |
| | | } |
| | | // 超时未收款 撤销 重新发起转账 更新packageInfo |
| | | weChatPay(order.getOrderMoney(), data.getOpenId(),list.get(0).getId(),order.getServeName()); |
| | | weChatPay(order.getOrderMoney(), data.getOpenId(),list.get(0).getId(),order.getServeName()); |
| | | } |
| | | map.put("code", "SUCCESS"); |
| | | map.put("message", "成功"); |
| | |
| | | return allTransfersSuccessful; |
| | | } |
| | | |
| | | // public static void main(String[] args) { |
| | | // String s = "1827928ae317443a8ef788e9ed56e8dc"; |
| | | // String s1 = HttpUtil.queryTransBatRequest(WechatConstants.WE_CHAT_PAY_QUERY_URL_PRE + s, |
| | | // "7EEA04429B006E12AAA421C002EC48BBEED5BE94", |
| | | // "1665330417", |
| | | // "D:\\apiclient_key.pem", WechatConstants.WE_CHAT_QUERY_URL_SUF + s); |
| | | // System.err.println(s1); |
| | | // } |
| | | public static void main(String[] args) { |
| | | String s = "1827928ae317443a8ef788e9ed56e8dc"; |
| | | String s1 = HttpUtil.queryTransBatRequest(WechatConstants.WE_CHAT_PAY_QUERY_URL_PRE + s, |
| | | "7EEA04429B006E12AAA421C002EC48BBEED5BE94", |
| | | "1665330417", |
| | | "D:\\apiclient_key.pem", WechatConstants.WE_CHAT_QUERY_URL_SUF + s); |
| | | System.err.println(s1); |
| | | JSONObject jsonObject = JSONObject.parseObject(s1); |
| | | String string = jsonObject.getString("state"); |
| | | System.err.println(string); |
| | | } |
| | | |
| | | } |
| | |
| | | withdraw.setState(Constants.ONE); |
| | | // 商家微信打款至微信零钱 |
| | | boolean update = weChatPay(order.getOrderMoney(), openId,withdraw.getId(),order.getServerName()); |
| | | // if (!update) { |
| | | // throw new GlobalException("交易提现失败,请检查是否绑定微信!"); |
| | | // } |
| | | if (!update) { |
| | | throw new GlobalException("交易提现失败,请检查是否绑定微信!"); |
| | | } |
| | | } else { |
| | | // 待审核 |
| | | withdraw.setState(Constants.ZERO); |
| | |
| | | withdrawDetail.setMoney(transferAmount); |
| | | withdrawDetail.setOutBatchNo(postMap.get("out_bill_no")+""); |
| | | withdrawDetailService.save(withdrawDetail); |
| | | |
| | | |
| | | } else { |
| | | allTransfersSuccessful = false; |
| | | break; |
| | | throw new GlobalException("提现失败,失败原因:"+jsonObject.getString("message")); |
| | | // allTransfersSuccessful = false; |
| | | // break; |
| | | } |
| | | |
| | | } |
| | | |
| | | return allTransfersSuccessful; |
| | | } |
| | | |
| | |
| | | private WithdrawDetailService withdrawDetailService; |
| | | |
| | | |
| | | // /** |
| | | // * 每隔一分钟去处理的定时任务 |
| | | // */ |
| | | // @Scheduled(fixedRate = 10000 * 60) |
| | | // public void taskMinute(){ |
| | | // try { |
| | | // |
| | | // List<WithdrawDetail> list = withdrawDetailService.lambdaQuery().ne(WithdrawDetail::getStatus, "SUCCESS").ne(WithdrawDetail::getStatus, "FAIL").list(); |
| | | // |
| | | // for (WithdrawDetail withdrawDetail : list) { |
| | | // String s = GetTransferBatchByOutNo.checkStatus(withdrawDetail.getOutBatchNo()); |
| | | // if (s.equals("SUCCESS")) { |
| | | // withdrawDetail.setStatus("SUCCESS"); |
| | | // withdrawDetailService.updateById(withdrawDetail); |
| | | // //执行订单提现成功,增加提现成功金额 |
| | | // //查询订单 |
| | | // |
| | | // //增加已提现金额 |
| | | // |
| | | // |
| | | // } else if (s.equals("FAIL")) { |
| | | // withdrawDetail.setStatus("FAIL"); |
| | | // withdrawDetailService.updateById(withdrawDetail); |
| | | // }else { |
| | | // withdrawDetail.setStatus(s); |
| | | // withdrawDetailService.updateById(withdrawDetail); |
| | | // } |
| | | // |
| | | // } |
| | | // |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // } |
| | | |
| | | /** |
| | | * 每隔一小时去处理的定时任务 |
| | | */ |
| | | @Scheduled(fixedRate = 1000 * 3600) |
| | | public void taskMinute(){ |
| | | try { |
| | | |
| | | |
| | | List<WithdrawDetail> list = withdrawDetailService.lambdaQuery().ne(WithdrawDetail::getStatus, "SUCCESS").ne(WithdrawDetail::getStatus, "FAIL").list(); |
| | | |
| | | for (WithdrawDetail withdrawDetail : list) { |
| | | String s = GetTransferBatchByOutNo.checkStatus(withdrawDetail.getOutBatchNo()); |
| | | if (s.equals("SUCCESS")) { |
| | | withdrawDetail.setStatus("SUCCESS"); |
| | | withdrawDetailService.updateById(withdrawDetail); |
| | | //执行订单提现成功,增加提现成功金额 |
| | | //查询订单 |
| | | |
| | | //增加已提现金额 |
| | | |
| | | |
| | | } else if (s.equals("FAIL")) { |
| | | withdrawDetail.setStatus("FAIL"); |
| | | withdrawDetailService.updateById(withdrawDetail); |
| | | }else { |
| | | withdrawDetail.setStatus(s); |
| | | withdrawDetailService.updateById(withdrawDetail); |
| | | } |
| | | |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | } |
| | | return null; |
| | | } |
| | | /** |
| | | * 查询转账情况 |
| | | * |
| | | * @param requestUrl 请求路径 |
| | | * @param requestJson 组合参数 |
| | | * @param wechatPayserialNo 商户证书序列号 |
| | | * @param privatekeypath 商户私钥证书路径 |
| | | */ |
| | | public static String queryTransBatRequest( |
| | | String requestUrl, |
| | | |
| | | String wechatPayserialNo, |
| | | String mchId, |
| | | String privatekeypath, String url) { |
| | | CloseableHttpResponse response; |
| | | HttpEntity entity; |
| | | CloseableHttpClient httpClient = null; |
| | | try { |
| | | HttpGet httpGet = createHttpGet(requestUrl, wechatPayserialNo, mchId, privatekeypath, url); |
| | | httpClient = HttpClients.createDefault(); |
| | | //发起转账请求 |
| | | response = httpClient.execute(httpGet); |
| | | log.info("response:{}", response); |
| | | //获取返回的数据 |
| | | entity = response.getEntity(); |
| | | log.info("-----getHeaders.Request-ID:" + response.getHeaders("Request-ID")); |
| | | return EntityUtils.toString(entity); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | // 关闭流 |
| | | try { |
| | | if (httpClient != null) { |
| | | httpClient.close(); |
| | | } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | /** |