From 8fc80be482d9ada1e0bbe904e5066ccf4afc9771 Mon Sep 17 00:00:00 2001 From: Iamasoldier <1272745473@qq.com> Date: Mon, 12 May 2025 10:15:53 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=B0=8F=E7=A8=8B=E5=BA=8F=E9=80=9A?= =?UTF-8?q?=E7=9F=A5)=EF=BC=9A=E5=B0=8F=E7=A8=8B=E5=BA=8F=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E4=BD=BF=E7=94=A8=E5=90=8C=E4=B8=80=E4=B8=AA=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E8=BF=9B=E8=A1=8C=E6=B6=88=E6=81=AF=E5=8F=91=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AutoCutVideoController.java | 21 ++++++---- .../listener/OrderStatusChangeListener.java | 41 ++++--------------- .../impl/WxMiniSubscribeServiceImpl.java | 28 ++++--------- .../order/{utils => util}/ExceptionUtils.java | 12 +++--- .../com/central/order/util/StringUtils.java | 29 +++++++++++++ .../react-web/src/main/frontend/nginx.conf | 29 ++++++++++++- 6 files changed, 91 insertions(+), 69 deletions(-) rename zlt-business/order-center/src/main/java/com/central/order/{utils => util}/ExceptionUtils.java (96%) create mode 100644 zlt-business/order-center/src/main/java/com/central/order/util/StringUtils.java diff --git a/zlt-business/order-center/src/main/java/com/central/order/controller/AutoCutVideoController.java b/zlt-business/order-center/src/main/java/com/central/order/controller/AutoCutVideoController.java index 3f03dd5a..af646c79 100644 --- a/zlt-business/order-center/src/main/java/com/central/order/controller/AutoCutVideoController.java +++ b/zlt-business/order-center/src/main/java/com/central/order/controller/AutoCutVideoController.java @@ -6,13 +6,11 @@ import com.central.common.model.SysUser; import com.central.order.constants.EditTaskStatus; import com.central.order.enums.OrderStatus; import com.central.order.feign.UserCenterService; -import com.central.order.model.EditTask; -import com.central.order.model.Order; -import com.central.order.model.OrderFile; -import com.central.order.model.QrCode; +import com.central.order.model.*; import com.central.order.model.dto.CallbackDTO; import com.central.order.model.params.EditTaskQueryParams; import com.central.order.service.*; +import com.central.order.util.StringUtils; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; @@ -49,6 +47,9 @@ public class AutoCutVideoController { @Autowired private UserCenterService userCenterService; + @Autowired + private ITourismService tourismService; + @Operation(summary = "根据订单号生成视频") @PostMapping("/generate") public Result generateVideo(@RequestParam String orderNo) { @@ -182,14 +183,16 @@ public class AutoCutVideoController { return; } - String taskName = "AI一键成片"; - String result = "您的视频已制作完成,可前往相册页查看和下载。"; + Tourism tourism = tourismService.getTourismById(order.getTourismId()); + String result = "您的视频已制作完成,可前往相册页查看和下载!"; - wxMiniSubscribeService.sendVideoEditCompleteMsg( + wxMiniSubscribeService.sendPaySuccessMsg( user.getOpenId(), - taskName, + tourism.getTourismName(), orderNo, - result + result, + StringUtils.fenToYuan(order.getOrderAmount()), + order.getPayTime().toString() ); log.info("已发送一键成片完成通知: userId={}, openId={}, orderNo={}", userId, user.getOpenId(), orderNo); } catch (Exception e) { diff --git a/zlt-business/order-center/src/main/java/com/central/order/listener/OrderStatusChangeListener.java b/zlt-business/order-center/src/main/java/com/central/order/listener/OrderStatusChangeListener.java index a36e160d..5f972125 100644 --- a/zlt-business/order-center/src/main/java/com/central/order/listener/OrderStatusChangeListener.java +++ b/zlt-business/order-center/src/main/java/com/central/order/listener/OrderStatusChangeListener.java @@ -10,6 +10,7 @@ import com.central.order.event.OrderStatusChangeEvent; import com.central.order.feign.UserCenterService; import com.central.order.model.*; import com.central.order.service.*; +import com.central.order.util.StringUtils; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -160,20 +161,12 @@ public class OrderStatusChangeListener { SysUser sysUser = userCenterService.findUserById(order.getUserId()); // 2. 查询订单排队信息 Integer queue = orderService.getOrderRankingByOrderId(order.getId(),tourism.getId()); - if (sysUser.getUnionId() != null) { - wxTemplateMessageService.sendPaymentSuccessNotice( - sysUser.getUnionId(), - order.getOrderNo(), - tourism.getTourismName(), - queue - ); - } // 发送小程序订阅消息 if (sysUser.getOpenId() != null) { String payTime = order.getPayTime() != null ? order.getPayTime().toString() : ""; String tip = "您的订单已支付成功,您当前排在第"+queue+"位,欢迎体验!"; - String amount = yuanToFen(order.getOrderAmount()); + String amount = StringUtils.fenToYuan(order.getOrderAmount()); String orderName = tourism.getTourismName(); wxMiniSubscribeService.sendPaySuccessMsg( sysUser.getOpenId(), @@ -230,16 +223,16 @@ public class OrderStatusChangeListener { SysUser nextUser = userCenterService.findUserById(nextOrder.getUserId()); Tourism tourism = tourismService.getTourismById(nextOrder.getTourismId()); if (nextUser != null && nextUser.getOpenId() != null && tourism != null) { - String place = tourism.getTourismAddress(); // 活动地点 String activityName = tourism.getTourismName(); // 活动名称 - String remark = "请您准备,马上轮到您啦!"; + String remark = "请您准备,当前排队序列的下一位就轮到您啦!"; String activityNo = nextOrder.getOrderNo(); // 活动编号 - wxMiniSubscribeService.sendActivityStartMsg( + wxMiniSubscribeService.sendPaySuccessMsg( nextUser.getOpenId(), - place, activityName, + activityNo, remark, - activityNo + activityNo, + nextOrder.getPayTime().toString() ); log.info("已通知下一个排队用户: userId={}, openId={}, orderNo={}", nextUser.getId(), nextUser.getOpenId(), activityNo); } @@ -259,24 +252,4 @@ public class OrderStatusChangeListener { && qrCode.getEnableVideoEdit() == 1 && qrCode.getTemplateId() != null; // 确保有模板ID } - - private String yuanToFen(String orderAmountStr) { - if (orderAmountStr != null && !orderAmountStr.isEmpty()) { - StringBuilder result = new StringBuilder(); - int length = orderAmountStr.length(); - if (length >= 3) { - // 字符串长度大于等于 3,正常插入小数点 - result.append(orderAmountStr, 0, length - 2).append(".").append(orderAmountStr.substring(length - 2)); - } else if (length == 2) { - // 字符串长度为 2,前面补 0 - result.append("0.").append(orderAmountStr); - } else { - // 字符串长度为 1,前面补 0 - result.append("0.0").append(orderAmountStr); - } - return result.toString() + "元"; - } else { - return "0.00元"; - } - } } diff --git a/zlt-business/order-center/src/main/java/com/central/order/service/impl/WxMiniSubscribeServiceImpl.java b/zlt-business/order-center/src/main/java/com/central/order/service/impl/WxMiniSubscribeServiceImpl.java index f1ba4462..e7996966 100644 --- a/zlt-business/order-center/src/main/java/com/central/order/service/impl/WxMiniSubscribeServiceImpl.java +++ b/zlt-business/order-center/src/main/java/com/central/order/service/impl/WxMiniSubscribeServiceImpl.java @@ -1,8 +1,9 @@ package com.central.order.service.impl; -import com.alibaba.fastjson.JSONObject; +import com.central.order.service.IWxAccessTokenService; import com.central.order.service.WxMiniSubscribeService; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; @@ -15,10 +16,6 @@ import java.util.Map; @Service public class WxMiniSubscribeServiceImpl implements WxMiniSubscribeService { - @Value("${wx.mini.app-id}") - private String appId; - @Value("${wx.mini.secret}") - private String secret; @Value("${wx.mini.template.pay-success}") private String templateId; @Value("${wx.mini.template.activity-start}") @@ -29,24 +26,17 @@ public class WxMiniSubscribeServiceImpl implements WxMiniSubscribeService { @Resource private RestTemplate restTemplate; - /** - * 获取小程序access_token - */ - private String getAccessToken() { - String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential" - + "&appid=" + appId - + "&secret=" + secret; - String resp = restTemplate.getForObject(url, String.class); - JSONObject json = JSONObject.parseObject(resp); - return json.getString("access_token"); - } + @Autowired + private IWxAccessTokenService wxAccessTokenService; @Override public void sendPaySuccessMsg(String openId, String orderName, String orderNo, String tip, String amount, String orderTime) { try { - String accessToken = getAccessToken(); + String accessToken = wxAccessTokenService.getAccessToken(); String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + accessToken; + + Map data = new HashMap<>(); data.put("thing1", Map.of("value", orderName)); // 订单名称 data.put("character_string2", Map.of("value", orderNo)); // 订单编号 @@ -70,7 +60,7 @@ public class WxMiniSubscribeServiceImpl implements WxMiniSubscribeService { @Override public void sendActivityStartMsg(String openId, String place, String activityName, String remark, String activityNo) { try { - String accessToken = getAccessToken(); + String accessToken = wxAccessTokenService.getAccessToken(); String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + accessToken; Map data = new HashMap<>(); @@ -94,7 +84,7 @@ public class WxMiniSubscribeServiceImpl implements WxMiniSubscribeService { @Override public void sendVideoEditCompleteMsg(String openId, String taskName, String orderNo, String result) { try { - String accessToken = getAccessToken(); + String accessToken = wxAccessTokenService.getAccessToken(); String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + accessToken; Map data = new HashMap<>(); diff --git a/zlt-business/order-center/src/main/java/com/central/order/utils/ExceptionUtils.java b/zlt-business/order-center/src/main/java/com/central/order/util/ExceptionUtils.java similarity index 96% rename from zlt-business/order-center/src/main/java/com/central/order/utils/ExceptionUtils.java rename to zlt-business/order-center/src/main/java/com/central/order/util/ExceptionUtils.java index 1201c361..5811aa03 100644 --- a/zlt-business/order-center/src/main/java/com/central/order/utils/ExceptionUtils.java +++ b/zlt-business/order-center/src/main/java/com/central/order/util/ExceptionUtils.java @@ -1,11 +1,11 @@ -package com.central.order.utils; +package com.central.order.util; import lombok.extern.slf4j.Slf4j; import org.springframework.util.StringUtils; @Slf4j public class ExceptionUtils { - + /** * 获取异常的根本原因 */ @@ -13,7 +13,7 @@ public class ExceptionUtils { Throwable rootCause = getRootCause(throwable); return rootCause.getMessage(); } - + /** * 获取异常的根本原因对象 */ @@ -24,7 +24,7 @@ public class ExceptionUtils { } return cause; } - + /** * 格式化异常信息 */ @@ -37,7 +37,7 @@ public class ExceptionUtils { // 限制长度 return message.length() > 200 ? message.substring(0, 200) : message; } - + /** * 判断是否为业务异常 */ @@ -48,4 +48,4 @@ public class ExceptionUtils { || message.contains("SIGN_ERROR") || message.contains("INVALID_REQUEST"); } -} \ No newline at end of file +} diff --git a/zlt-business/order-center/src/main/java/com/central/order/util/StringUtils.java b/zlt-business/order-center/src/main/java/com/central/order/util/StringUtils.java new file mode 100644 index 00000000..e30b7a57 --- /dev/null +++ b/zlt-business/order-center/src/main/java/com/central/order/util/StringUtils.java @@ -0,0 +1,29 @@ +package com.central.order.util; + +/** + * 字符串处理 + * @date + * @author lsl + */ +public class StringUtils { + + public static String fenToYuan(String orderAmountStr) { + if (orderAmountStr != null && !orderAmountStr.isEmpty()) { + StringBuilder result = new StringBuilder(); + int length = orderAmountStr.length(); + if (length >= 3) { + // 字符串长度大于等于 3,正常插入小数点 + result.append(orderAmountStr, 0, length - 2).append(".").append(orderAmountStr.substring(length - 2)); + } else if (length == 2) { + // 字符串长度为 2,前面补 0 + result.append("0.").append(orderAmountStr); + } else { + // 字符串长度为 1,前面补 0 + result.append("0.0").append(orderAmountStr); + } + return result.toString() + "元"; + } else { + return "0.00元"; + } + } +} diff --git a/zlt-web/react-web/src/main/frontend/nginx.conf b/zlt-web/react-web/src/main/frontend/nginx.conf index 89a1d35b..b090c091 100644 --- a/zlt-web/react-web/src/main/frontend/nginx.conf +++ b/zlt-web/react-web/src/main/frontend/nginx.conf @@ -19,7 +19,10 @@ server { # 添加必要的跨域和缓存控制头 add_header Access-Control-Allow-Origin *; - add_header Cache-Control "no-cache, no-store, must-revalidate"; + # 调整缓存策略,例如对于静态资源可以缓存 + location ~* \.(css|js|svg|png|jpg|jpeg)$ { + expires 365d; + } # 添加安全相关头 add_header X-Frame-Options SAMEORIGIN; @@ -37,6 +40,14 @@ server { # 确保 Authorization 头可以传递 proxy_set_header Authorization $http_authorization; proxy_pass_header Authorization; + + # 处理 OPTIONS 请求 + if ($request_method = 'OPTIONS') { + add_header Access-Control-Allow-Origin *; + add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS'; + add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization'; + return 204; + } } # 用户服务代理 @@ -49,6 +60,14 @@ server { # 确保 Authorization 头可以传递 proxy_set_header Authorization $http_authorization; proxy_pass_header Authorization; + + # 处理 OPTIONS 请求 + if ($request_method = 'OPTIONS') { + add_header Access-Control-Allow-Origin *; + add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS'; + add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization'; + return 204; + } } # 其他 API 服务代理(如果需要) @@ -75,5 +94,13 @@ server { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + + # 处理 OPTIONS 请求 + if ($request_method = 'OPTIONS') { + add_header Access-Control-Allow-Origin *; + add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS'; + add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization'; + return 204; + } } } \ No newline at end of file