From 62676cf59b0834c5760b5a6a52e1e166e88667c7 Mon Sep 17 00:00:00 2001
From: Yuan <1450637472@qq.com>
Date: Fri, 31 Oct 2025 09:08:46 +0800
Subject: [PATCH] =?UTF-8?q?init:=E5=AE=81=E5=A4=8F=E6=AD=A6=E8=AD=A6?=
=?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=BB=BA=E8=A1=8C=E8=B4=A6=E5=8D=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 4 +
.../hgddmz/controller/GetDateController.java | 445 +++++++++++++++++-
.../com/saye/hgddmz/entity/UserOrder.java | 39 ++
.../com/saye/hgddmz/util/HttpClientUtil.java | 83 ++++
4 files changed, 568 insertions(+), 3 deletions(-)
create mode 100644 src/main/java/com/saye/hgddmz/entity/UserOrder.java
create mode 100644 src/main/java/com/saye/hgddmz/util/HttpClientUtil.java
diff --git a/pom.xml b/pom.xml
index e7f81ec..fd6fc3b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -77,6 +77,10 @@
org.apache.httpcomponents
httpasyncclient
+
+ org.apache.httpcomponents
+ httpclient
+
org.apache.poi
diff --git a/src/main/java/com/saye/hgddmz/controller/GetDateController.java b/src/main/java/com/saye/hgddmz/controller/GetDateController.java
index 8514b01..44dd5a0 100644
--- a/src/main/java/com/saye/hgddmz/controller/GetDateController.java
+++ b/src/main/java/com/saye/hgddmz/controller/GetDateController.java
@@ -6,18 +6,28 @@ import cn.hutool.http.HttpUtil;
import com.saye.hgddmz.commons.date.DateDUtil;
import com.saye.hgddmz.commons.string.StringDUtil;
import com.saye.hgddmz.entity.BankbillHistory;
+import com.saye.hgddmz.entity.UserOrder;
import com.saye.hgddmz.util.DownloadFtpUtil;
+import com.saye.hgddmz.util.HttpClientUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.Cell;
+import org.springframework.core.io.InputStreamResource;
+import org.springframework.http.*;
import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.*;
import java.io.File;
import java.io.FileInputStream;
+import java.io.InputStream;
+import java.text.DecimalFormat;
import java.util.*;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
/**
@@ -36,6 +46,10 @@ public class GetDateController {
private static String appid = "wx45acd2b4907cb8f4";
private static String secret = "895b90585c4698485c07e113711eac85";
private static String key = "Nxwj20250903Jojubanking12091209x";
+
+ // 微信消息推送相关常量
+ private static String WX_APP_ID = "wx45acd2b4907cb8f4";
+ private static String WX_SECRET = "895b90585c4698485c07e113711eac85";
/**
* 安全获取单元格字符串值
@@ -1111,4 +1125,429 @@ public class GetDateController {
// }
// System.out.println();
// }
+
+ /**
+ * 发送对账结果微信消息推送
+ * @param tradeDate 对账时间
+ * @param operationResult 操作结果
+ * @param reconcileResult 对账结果
+ * @param operatorName 操作人
+ * @param openid 用户openid
+ * @return 推送结果
+ */
+ public int SendNotifyYJJ(String tradeDate, String operationResult, String reconcileResult, String operatorName, String openid) {
+ try {
+ //第一步 获取token
+ String accessUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&" +
+ "&appid=" + WX_APP_ID + "&secret=" + WX_SECRET;
+ String accessTokenStr = HttpClientUtil.doGet(accessUrl, null);
+ log.info("step 1 get accesstoken:" + accessTokenStr);
+
+ if (accessTokenStr == null || accessTokenStr.isEmpty()) {
+ log.error("获取微信access_token失败,响应为空");
+ return -1;
+ }
+
+ JSONObject jsonObject = JSON.parseObject(accessTokenStr);
+ if (jsonObject == null) {
+ log.error("解析微信access_token响应失败,无法解析JSON");
+ return -1;
+ }
+
+ Object accessTokenObj = jsonObject.get("access_token");
+ if (accessTokenObj == null) {
+ log.error("微信access_token响应中没有access_token字段,响应内容: {}", accessTokenStr);
+ return -1;
+ }
+
+ String accessToken = accessTokenObj.toString();
+
+ String sendUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken;
+ JSONObject sendPara = new JSONObject();
+ JSONObject dataPara = new JSONObject();
+
+ // 对账时间
+ JSONObject time2 = new JSONObject();
+ time2.put("value", tradeDate);
+ time2.put("color", "#173177");
+
+ // 操作结果
+ JSONObject const3 = new JSONObject();
+ const3.put("value", operationResult);
+ const3.put("color", "#173177");
+
+ // 对账结果
+ JSONObject const4 = new JSONObject();
+ const4.put("value", reconcileResult);
+ const4.put("color", "#173177");
+
+ // 操作人和时间
+ JSONObject character_string5 = new JSONObject();
+ character_string5.put("value", operatorName + " " + DateDUtil.DateToStr(DateDUtil.yyyy_MM_dd_HH_mm_ss, new Date()));
+ character_string5.put("color", "#173177");
+
+ dataPara.put("time2", time2);
+ dataPara.put("const3", const3);
+ dataPara.put("const4", const4);
+ dataPara.put("character_string5", character_string5);
+
+ sendPara.put("touser", openid);
+ sendPara.put("template_id", "sbzMHunU1zmB_Hg4LRAs7BSmYPw6CtxFuBHMXllxZB0");
+ sendPara.put("url", "https://nxwj.btlsoln.com/nxwj-gzh/#/reconciliation");
+ sendPara.put("data", dataPara);
+ String sendRes = HttpClientUtil.doPost(sendUrl, sendPara);
+ log.info("step 2 send notify:" + sendRes);
+
+ if (sendRes == null || sendRes.isEmpty()) {
+ log.error("发送微信消息失败,响应为空");
+ return -1;
+ }
+
+ JSONObject jsonSend = JSON.parseObject(sendRes);
+ if (jsonSend != null && jsonSend.containsKey("errcode")) {
+ Integer errcode = jsonSend.getInteger("errcode");
+ String errmsg = jsonSend.getString("errmsg");
+
+ if (errcode != null && errcode == 0) {
+ log.info("微信消息发送成功");
+ return 0;
+ } else {
+ // 根据不同错误码提供具体的错误信息
+ switch (errcode) {
+ case 43004:
+ log.error("微信消息发送失败:用户未关注公众号,无法接收模板消息。errcode: {}, errmsg: {}", errcode, errmsg);
+ return -2; // 特殊返回码表示用户未关注
+ case 40001:
+ log.error("微信消息发送失败:access_token无效。errcode: {}, errmsg: {}", errcode, errmsg);
+ return -3;
+ case 40003:
+ log.error("微信消息发送失败:openid无效。errcode: {}, errmsg: {}", errcode, errmsg);
+ return -4;
+ case 41030:
+ log.error("微信消息发送失败:页面不存在或者小程序没有关联公众号。errcode: {}, errmsg: {}", errcode, errmsg);
+ return -5;
+ default:
+ log.error("微信消息发送失败,errcode: {}, errmsg: {}", errcode, errmsg);
+ return -1;
+ }
+ }
+ }
+
+ return 0;
+ } catch (Exception e) {
+ log.error("发送微信消息异常", e);
+ return -1;
+ }
+ }
+
+ /**
+ * 测试对账结果微信消息推送接口
+ * @param map 包含对账信息和openid的参数
+ * @return 推送结果
+ */
+ @PostMapping("/sendNotifyYJJ")
+ @ResponseBody
+ public HashMap