Parcourir la source

fix: add CORS origin for www.cf-club.com, fix QR code display, add diagnostic filter

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Xiaogang Liao il y a 1 mois
Parent
commit
5e4e213797

+ 31 - 2
cfc-backend/src/main/java/com/etotem/cfc/config/WebConfig.java

@@ -1,6 +1,7 @@
 package com.etotem.cfc.config;
 
-import javax.annotation.Resource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
@@ -11,13 +12,17 @@ import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
+import javax.annotation.Resource;
 import javax.servlet.*;
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 
 @Configuration
 public class WebConfig implements WebMvcConfigurer {
 
+    private static final Logger log = LoggerFactory.getLogger(WebConfig.class);
+
     @Resource
     private JwtInterceptor jwtInterceptor;
 
@@ -33,7 +38,7 @@ public class WebConfig implements WebMvcConfigurer {
     @Override
     public void addCorsMappings(CorsRegistry registry) {
         registry.addMapping("/**")
-                .allowedOriginPatterns("https://cfc.etotem.com.cn", "http://cfc.etotem.com.cn", "https://cf-club.iwintrue.com", "http://cf-club.iwintrue.com", "http://localhost:*", "http://127.0.0.1:*")
+                .allowedOriginPatterns("https://cfc.etotem.com.cn", "http://cfc.etotem.com.cn", "https://cf-club.iwintrue.com", "http://cf-club.iwintrue.com", "https://www.cf-club.com", "http://www.cf-club.com", "https://cfc.cf-club.com", "http://cfc.cf-club.com", "http://localhost:*", "http://127.0.0.1:*")
                 .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
                 .allowedHeaders("*")
                 .allowCredentials(true)
@@ -48,6 +53,7 @@ public class WebConfig implements WebMvcConfigurer {
             @Override
             public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
                     throws IOException, ServletException {
+                HttpServletRequest req = (HttpServletRequest) request;
                 HttpServletResponse resp = (HttpServletResponse) response;
                 resp.setHeader("Access-Control-Allow-Private-Network", "true");
                 chain.doFilter(request, response);
@@ -55,6 +61,29 @@ public class WebConfig implements WebMvcConfigurer {
         };
     }
 
+    /** 诊断过滤器:记录所有请求的来源和状态码 */
+    @Bean
+    @Order(Ordered.HIGHEST_PRECEDENCE + 1)
+    public Filter diagnosticFilter() {
+        return new Filter() {
+            @Override
+            public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
+                    throws IOException, ServletException {
+                HttpServletRequest req = (HttpServletRequest) request;
+                long start = System.currentTimeMillis();
+                chain.doFilter(request, response);
+                int status = ((HttpServletResponse) response).getStatus();
+                long ms = System.currentTimeMillis() - start;
+                if (status == 403 || req.getRequestURI().contains("/api/payment")) {
+                    log.warn("[DIAG] {} {} -> {} ({}ms) origin={} ua={}",
+                            req.getMethod(), req.getRequestURI(), status, ms,
+                            req.getHeader("Origin"),
+                            req.getHeader("User-Agent"));
+                }
+            }
+        };
+    }
+
     @Override
     public void addInterceptors(InterceptorRegistry registry) {
         registry.addInterceptor(jwtInterceptor)

+ 12 - 11
web/product-intro/gut-testing.html

@@ -332,16 +332,16 @@
       <span class="orig">测试价 ¥1,314</span>
     </div>
     <div>
-      <button class="cta-btn" onclick="document.getElementById('orderForm').style.display='flex'">立即购买</button>
+      <button class="cta-btn" onclick="var f=document.getElementById('orderForm');f.style.visibility='visible';f.style.opacity='1'">立即购买</button>
       <a href="../articles/gut-microbiota-testing.html" class="cta-btn secondary">了解检测详情 →</a>
     </div>
   </div>
 </div>
 
 <!-- Order Form Modal -->
-<div id="orderForm" style="display:none;position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.5);z-index:1000;align-items:center;justify-content:center;" onclick="if(event.target===this)this.style.display='none'">
+<div id="orderForm" style="position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.5);z-index:1000;display:flex;align-items:center;justify-content:center;visibility:hidden;opacity:0;transition:opacity 0.2s;" onclick="if(event.target===this){this.style.visibility='hidden';this.style.opacity='0'}">
   <div style="background:#fff;border-radius:16px;padding:2rem;max-width:420px;width:90%;position:relative;">
-    <button style="position:absolute;top:12px;right:12px;background:none;border:none;font-size:24px;cursor:pointer;color:#999" onclick="document.getElementById('orderForm').style.display='none'">×</button>
+    <button style="position:absolute;top:12px;right:12px;background:none;border:none;font-size:24px;cursor:pointer;color:#999" onclick="var f=document.getElementById('orderForm');f.style.visibility='hidden';f.style.opacity='0'">×</button>
     <h3 style="margin-bottom:1.2rem;font-size:1.2rem;">肠道菌群基因检测 · 下单</h3>
     <div style="margin-bottom:1rem">
       <label style="display:block;font-size:0.85rem;color:var(--text-secondary);margin-bottom:0.3rem">联系人</label>
@@ -478,10 +478,12 @@ function fallbackNativePay(orderNo) {
   })
   .then(function(r) { return r.json(); })
   .then(function(data) {
-    if (data.code === 200 && data.data && data.data.codeUrl) {
-      document.getElementById('orderForm').style.display = 'none';
-      showQrCode(data.data.codeUrl, orderNo);
-    } else {
+      if (data.code === 200 && data.data) {
+        if (data.data.codeUrl) {
+          document.getElementById('orderForm').style.visibility = 'hidden';
+          document.getElementById('orderForm').style.opacity = '0';
+          showQrCode(data.data.codeUrl, orderNo);
+        } else {
       // 如果Native支付不可用,尝试H5支付
       tryH5Pay(orderNo);
     }
@@ -551,8 +553,8 @@ function showQrCode(codeUrl, orderNo) {
   div.innerHTML = '<div style="background:#fff;border-radius:16px;padding:2rem;text-align:center;max-width:320px">' +
     '<h3 style="margin-bottom:0.5rem;font-size:1.1rem;">请使用微信扫码支付</h3>' +
     '<p style="font-size:0.85rem;color:#999;margin-bottom:1rem">订单号: ' + orderNo + '</p>' +
-    '<div id="qrcode" style="width:200px;height:200px;margin:0 auto 1rem;background:#f5f5f5;display:flex;align-items:center;justify-content:center;border-radius:8px">' +
-      '<canvas id="qrCanvas" width="200" height="200"></canvas>' +
+    '<div style="width:200px;height:200px;margin:0 auto 1rem;display:flex;align-items:center;justify-content:center;border-radius:8px;overflow:hidden">' +
+      '<img src="https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=' + encodeURIComponent(codeUrl) + '" alt="支付二维码" style="width:200px;height:200px">' +
     '</div>' +
     '<p style="font-size:0.8rem;color:#999">打开微信「扫一扫」完成支付</p>' +
     '<button onclick="this.closest(\'div[style]\').remove()" style="margin-top:1rem;padding:0.5rem 2rem;border:1px solid #e2e8f0;border-radius:8px;background:#fff;cursor:pointer">关闭</button>' +
@@ -568,7 +570,7 @@ function showQrCode(codeUrl, orderNo) {
     })
     .then(function(r) { return r.json(); })
     .then(function(data) {
-      if (data.code === 200 && data.data && data.data.status === 'success') {
+      if (data.code === 200 && data.data === true) {
         clearInterval(pollTimer);
         div.innerHTML = '<div style="background:#fff;border-radius:16px;padding:2rem;text-align:center;max-width:320px">' +
           '<div style="font-size:3rem;margin-bottom:0.5rem">✅</div>' +
@@ -576,7 +578,6 @@ function showQrCode(codeUrl, orderNo) {
           '<p style="font-size:0.85rem;color:#999;margin-top:0.5rem">您的检测订单已提交,检测套件将在24小时内寄出</p>' +
           '<button onclick="this.closest(\'div[style]\').remove()" style="margin-top:1rem;padding:0.5rem 2rem;background:linear-gradient(135deg,#0d9488,#14b8a6);color:#fff;border:none;border-radius:8px;cursor:pointer">完成</button>' +
           '</div>';
-      }
     })
     .catch(function() {});
   }, 3000);