ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/WechatConstants.java
@@ -64,11 +64,13 @@ * 微信发起转账(前缀) */ 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/"; /** * 微信转账接口调用所返回的成功参数之一 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/WithdrawController.java
@@ -138,9 +138,9 @@ 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()) ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/WxChatPayCallBack.java
@@ -200,13 +200,16 @@ 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); } } ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/WithdrawServiceImpl.java
@@ -253,9 +253,9 @@ 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); @@ -422,15 +422,12 @@ 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; } ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/task/TaskUtil.java
@@ -22,40 +22,42 @@ 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(); } } } ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/vx/HttpUtil.java
@@ -67,6 +67,47 @@ } 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; } /**