Browse Source
- 移除 CmsMainController 中的 getSiteInfo 方法 - 新增 ShopMainController 控制器用于获取商城信息 - 重构 CmsWebsiteController 中的 getSiteInfo 方法,使用 Redis 缓存 - 更新 CmsWebsiteService 接口和实现类,返回 ShopVo 对象- 删除 TestController 和 WechatCertTestController - 更新 SecurityConfig 中的放行接口列表main
12 changed files with 456 additions and 418 deletions
@ -1,35 +0,0 @@ |
|||
package com.gxwebsoft.common.core.controller; |
|||
|
|||
import com.gxwebsoft.common.core.web.ApiResult; |
|||
import com.gxwebsoft.common.core.web.BaseController; |
|||
import io.swagger.v3.oas.annotations.Operation; |
|||
import io.swagger.v3.oas.annotations.tags.Tag; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import java.time.LocalDateTime; |
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 测试控制器 |
|||
* 用于测试LocalDateTime序列化 |
|||
* |
|||
* @author WebSoft |
|||
* @since 2025-01-12 |
|||
*/ |
|||
@Tag(name = "测试接口") |
|||
@RestController |
|||
@RequestMapping("/api/test") |
|||
public class TestController extends BaseController { |
|||
|
|||
@Operation(summary = "测试LocalDateTime序列化") |
|||
@GetMapping("/datetime") |
|||
public ApiResult<Map<String, Object>> testDateTime() { |
|||
Map<String, Object> result = new HashMap<>(); |
|||
result.put("currentTime", LocalDateTime.now()); |
|||
result.put("message", "LocalDateTime序列化测试"); |
|||
return success(result); |
|||
} |
|||
} |
@ -1,211 +0,0 @@ |
|||
package com.gxwebsoft.common.core.controller; |
|||
|
|||
import com.gxwebsoft.common.core.utils.WechatCertAutoConfig; |
|||
import com.gxwebsoft.common.core.web.ApiResult; |
|||
import com.gxwebsoft.common.core.web.BaseController; |
|||
import com.wechat.pay.java.core.Config; |
|||
import io.swagger.v3.oas.annotations.tags.Tag; |
|||
import io.swagger.v3.oas.annotations.Operation; |
|||
import io.swagger.v3.oas.annotations.Parameter; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 微信支付证书自动配置测试控制器 |
|||
* |
|||
* @author 科技小王子 |
|||
* @since 2024-07-26 |
|||
*/ |
|||
@Slf4j |
|||
@RestController |
|||
@RequestMapping("/api/wechat-cert-test") |
|||
@Tag(name = "微信支付证书自动配置测试") |
|||
public class WechatCertTestController extends BaseController { |
|||
|
|||
@Autowired |
|||
private WechatCertAutoConfig wechatCertAutoConfig; |
|||
|
|||
@Operation(summary = "测试默认开发环境证书配置") |
|||
@PostMapping("/test-default") |
|||
public ApiResult<Map<String, Object>> testDefaultConfig() { |
|||
Map<String, Object> result = new HashMap<>(); |
|||
|
|||
try { |
|||
log.info("开始测试默认开发环境证书配置..."); |
|||
|
|||
// 创建自动证书配置
|
|||
Config config = wechatCertAutoConfig.createDefaultDevConfig(); |
|||
|
|||
// 测试配置
|
|||
boolean testResult = wechatCertAutoConfig.testConfig(config); |
|||
|
|||
result.put("success", true); |
|||
result.put("configCreated", config != null); |
|||
result.put("testPassed", testResult); |
|||
result.put("message", "默认证书配置测试完成"); |
|||
result.put("instructions", wechatCertAutoConfig.getUsageInstructions()); |
|||
|
|||
log.info("✅ 默认证书配置测试成功"); |
|||
return success("测试成功", result); |
|||
|
|||
} catch (Exception e) { |
|||
log.error("❌ 默认证书配置测试失败: {}", e.getMessage(), e); |
|||
|
|||
result.put("success", false); |
|||
result.put("error", e.getMessage()); |
|||
result.put("message", "证书配置测试失败"); |
|||
result.put("troubleshooting", getTroubleshootingInfo()); |
|||
|
|||
return fail("测试失败: " + e.getMessage(), result); |
|||
} |
|||
} |
|||
|
|||
@Operation(summary = "测试自定义证书配置") |
|||
@PostMapping("/test-custom") |
|||
public ApiResult<Map<String, Object>> testCustomConfig( |
|||
@Parameter(description = "商户号") @RequestParam String merchantId, |
|||
@Parameter(description = "私钥文件路径") @RequestParam String privateKeyPath, |
|||
@Parameter(description = "证书序列号") @RequestParam String merchantSerialNumber, |
|||
@Parameter(description = "APIv3密钥") @RequestParam String apiV3Key) { |
|||
|
|||
Map<String, Object> result = new HashMap<>(); |
|||
|
|||
try { |
|||
log.info("开始测试自定义证书配置..."); |
|||
log.info("商户号: {}", merchantId); |
|||
log.info("私钥路径: {}", privateKeyPath); |
|||
|
|||
// 创建自动证书配置
|
|||
Config config = wechatCertAutoConfig.createAutoConfig( |
|||
merchantId, privateKeyPath, merchantSerialNumber, apiV3Key); |
|||
|
|||
// 测试配置
|
|||
boolean testResult = wechatCertAutoConfig.testConfig(config); |
|||
|
|||
result.put("success", true); |
|||
result.put("configCreated", config != null); |
|||
result.put("testPassed", testResult); |
|||
result.put("message", "自定义证书配置测试完成"); |
|||
result.put("merchantId", merchantId); |
|||
result.put("privateKeyPath", privateKeyPath); |
|||
|
|||
log.info("✅ 自定义证书配置测试成功"); |
|||
return success("测试成功", result); |
|||
|
|||
} catch (Exception e) { |
|||
log.error("❌ 自定义证书配置测试失败: {}", e.getMessage(), e); |
|||
|
|||
result.put("success", false); |
|||
result.put("error", e.getMessage()); |
|||
result.put("message", "证书配置测试失败"); |
|||
result.put("troubleshooting", getTroubleshootingInfo()); |
|||
|
|||
return fail("测试失败: " + e.getMessage(), result); |
|||
} |
|||
} |
|||
|
|||
@Operation(summary = "获取使用说明") |
|||
@GetMapping("/instructions") |
|||
public ApiResult<String> getInstructions() { |
|||
String instructions = wechatCertAutoConfig.getUsageInstructions(); |
|||
return success("获取使用说明成功", instructions); |
|||
} |
|||
|
|||
@Operation(summary = "获取故障排除信息") |
|||
@GetMapping("/troubleshooting") |
|||
public ApiResult<Map<String, Object>> getTroubleshooting() { |
|||
Map<String, Object> troubleshooting = getTroubleshootingInfo(); |
|||
return success("获取故障排除信息成功", troubleshooting); |
|||
} |
|||
|
|||
/** |
|||
* 获取故障排除信息 |
|||
*/ |
|||
private Map<String, Object> getTroubleshootingInfo() { |
|||
Map<String, Object> info = new HashMap<>(); |
|||
|
|||
info.put("commonIssues", Map.of( |
|||
"404错误", "商户平台未开启API安全功能或未申请使用微信支付公钥", |
|||
"证书序列号错误", "请检查商户平台中的证书序列号是否正确", |
|||
"APIv3密钥错误", "请确认APIv3密钥是否正确设置", |
|||
"私钥文件不存在", "请检查私钥文件路径是否正确", |
|||
"网络连接问题", "请检查网络连接是否正常" |
|||
)); |
|||
|
|||
info.put("solutions", Map.of( |
|||
"开启API安全", "登录微信商户平台 -> 账户中心 -> API安全 -> 申请使用微信支付公钥", |
|||
"获取证书序列号", "在API安全页面查看或重新下载证书", |
|||
"设置APIv3密钥", "在API安全页面设置APIv3密钥", |
|||
"检查私钥文件", "确保apiclient_key.pem文件存在且路径正确" |
|||
)); |
|||
|
|||
info.put("advantages", Map.of( |
|||
"自动下载", "RSAAutoCertificateConfig会自动下载平台证书", |
|||
"自动更新", "证书过期时会自动更新", |
|||
"简化管理", "无需手动管理wechatpay_cert.pem文件", |
|||
"官方推荐", "微信支付官方推荐的证书管理方式" |
|||
)); |
|||
|
|||
info.put("documentation", "https://pay.weixin.qq.com/doc/v3/merchant/4012153196"); |
|||
|
|||
return info; |
|||
} |
|||
|
|||
@Operation(summary = "检查商户平台配置状态") |
|||
@PostMapping("/check-merchant-config") |
|||
public ApiResult<Map<String, Object>> checkMerchantConfig( |
|||
@RequestParam String merchantId, |
|||
@RequestParam String privateKeyPath, |
|||
@RequestParam String merchantSerialNumber, |
|||
@RequestParam String apiV3Key) { |
|||
|
|||
Map<String, Object> result = new HashMap<>(); |
|||
|
|||
try { |
|||
log.info("开始检查商户平台配置状态..."); |
|||
log.info("商户号: {}", merchantId); |
|||
|
|||
// 尝试创建自动证书配置
|
|||
Config config = wechatCertAutoConfig.createAutoConfig( |
|||
merchantId, privateKeyPath, merchantSerialNumber, apiV3Key); |
|||
|
|||
result.put("success", true); |
|||
result.put("configCreated", true); |
|||
result.put("message", "商户平台配置正常,自动证书配置创建成功"); |
|||
result.put("merchantId", merchantId); |
|||
result.put("recommendation", "配置正常,可以正常使用微信支付功能"); |
|||
|
|||
log.info("✅ 商户平台配置检查成功"); |
|||
return success("配置检查成功", result); |
|||
|
|||
} catch (Exception e) { |
|||
log.error("❌ 商户平台配置检查失败: {}", e.getMessage(), e); |
|||
|
|||
result.put("success", false); |
|||
result.put("configCreated", false); |
|||
result.put("error", e.getMessage()); |
|||
result.put("merchantId", merchantId); |
|||
|
|||
// 分析错误类型并提供解决方案
|
|||
if (e.getMessage().contains("404") || e.getMessage().contains("RESOURCE_NOT_EXISTS")) { |
|||
result.put("errorType", "商户平台配置问题"); |
|||
result.put("solution", "请在微信支付商户平台完成以下配置:\n" + |
|||
"1. 登录商户平台:https://pay.weixin.qq.com/\n" + |
|||
"2. 进入:产品中心 → 开发配置 → API安全\n" + |
|||
"3. 申请API证书\n" + |
|||
"4. 申请使用微信支付公钥\n" + |
|||
"5. 确保API证书和微信支付公钥状态为\"已生效\""); |
|||
result.put("documentUrl", "https://pay.weixin.qq.com/doc/v3/merchant/4012153196"); |
|||
} else { |
|||
result.put("errorType", "其他配置问题"); |
|||
result.put("solution", "请检查商户号、证书序列号、API密钥等配置是否正确"); |
|||
} |
|||
|
|||
return success("配置检查完成(发现问题)", result); |
|||
} |
|||
} |
|||
} |
@ -1,39 +0,0 @@ |
|||
package com.gxwebsoft.common.task; |
|||
|
|||
import com.gxwebsoft.common.core.utils.RequestUtil; |
|||
import com.gxwebsoft.common.core.web.BaseController; |
|||
import com.gxwebsoft.common.system.entity.User; |
|||
import com.gxwebsoft.common.system.service.UserRoleService; |
|||
import com.gxwebsoft.common.system.service.UserService; |
|||
import io.swagger.v3.oas.annotations.tags.Tag; |
|||
import org.springframework.scheduling.annotation.Scheduled; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import javax.annotation.Resource; |
|||
|
|||
/** |
|||
* 定时任务 |
|||
* |
|||
* @author 科技小王子 |
|||
* @since 2022-12-15 19:11:07 |
|||
*/ |
|||
@Tag(name = "定时任务") |
|||
@RestController |
|||
@RequestMapping("/api/love/scheduling") |
|||
public class AddUserTaskController extends BaseController { |
|||
@Resource |
|||
private RequestUtil requestUtil; |
|||
@Resource |
|||
private UserRoleService userRoleService; |
|||
|
|||
/** |
|||
* 模拟注册用户 |
|||
* @Scheduled(fixedDelay = 1000, initialDelay = 1000) |
|||
*/ |
|||
@Scheduled(fixedDelay = 1000, initialDelay = 1000) |
|||
public void addUserProfile() { |
|||
// final User userId = requestUtil.getCoreUserInfoByUserId(27344);
|
|||
} |
|||
|
|||
} |
@ -0,0 +1,54 @@ |
|||
package com.gxwebsoft.shop.controller; |
|||
|
|||
import cn.hutool.core.util.ObjectUtil; |
|||
import com.gxwebsoft.cms.service.CmsWebsiteService; |
|||
import com.gxwebsoft.cms.vo.CmsVO; |
|||
import com.gxwebsoft.common.core.web.ApiResult; |
|||
import com.gxwebsoft.common.core.web.BaseController; |
|||
import com.gxwebsoft.shop.vo.ShopVo; |
|||
import io.swagger.v3.oas.annotations.Operation; |
|||
import io.swagger.v3.oas.annotations.tags.Tag; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import javax.annotation.Resource; |
|||
|
|||
/** |
|||
* 商城主入口 |
|||
* |
|||
* @author 科技小王子 |
|||
* @since 2024-09-10 20:36:14 |
|||
*/ |
|||
@Slf4j |
|||
@Tag(name = "商城") |
|||
@RestController |
|||
@RequestMapping("/api/shop") |
|||
public class ShopMainController extends BaseController { |
|||
@Resource |
|||
private CmsWebsiteService cmsWebsiteService; |
|||
|
|||
@Operation(summary = "商城基本信息", description = "获取商城的基本信息,包括配置、导航、设置和过期状态等") |
|||
@GetMapping("/getShopInfo") |
|||
public ApiResult<ShopVo> getSiteInfo() { |
|||
Integer tenantId = getTenantId(); |
|||
|
|||
if (ObjectUtil.isEmpty(tenantId)) { |
|||
return fail("租户ID不能为空", null); |
|||
} |
|||
|
|||
try { |
|||
ShopVo vo = cmsWebsiteService.getSiteInfo(tenantId); |
|||
return success(vo); |
|||
} catch (IllegalArgumentException e) { |
|||
return fail(e.getMessage(), null); |
|||
} catch (RuntimeException e) { |
|||
return fail(e.getMessage(), null); |
|||
} catch (Exception e) { |
|||
log.error("获取商城信息失败", e); |
|||
return fail("获取商城信息失败", null); |
|||
} |
|||
} |
|||
|
|||
} |
@ -0,0 +1,55 @@ |
|||
package com.gxwebsoft.shop.vo; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 导航信息视图对象 |
|||
* 专门用于前端展示,只包含前端需要的字段 |
|||
* |
|||
* @author WebSoft |
|||
* @since 2025-01-12 |
|||
*/ |
|||
@Data |
|||
@Schema(description = "导航信息视图对象") |
|||
public class MenuVo implements Serializable { |
|||
|
|||
@Schema(description = "导航ID") |
|||
private Integer navigationId; |
|||
|
|||
@Schema(description = "导航名称") |
|||
private String navigationName; |
|||
|
|||
@Schema(description = "导航链接") |
|||
private String navigationUrl; |
|||
|
|||
@Schema(description = "导航图标") |
|||
private String navigationIcon; |
|||
|
|||
@Schema(description = "导航颜色") |
|||
private String navigationColor; |
|||
|
|||
@Schema(description = "父级ID") |
|||
private Integer parentId; |
|||
|
|||
@Schema(description = "排序") |
|||
private Integer sort; |
|||
|
|||
@Schema(description = "是否隐藏 0显示 1隐藏") |
|||
private Integer hide; |
|||
|
|||
@Schema(description = "位置 0顶部 1底部") |
|||
private Integer top; |
|||
|
|||
@Schema(description = "打开方式 0当前窗口 1新窗口") |
|||
private Integer target; |
|||
|
|||
@Schema(description = "导航类型") |
|||
private String navigationType; |
|||
|
|||
@Schema(description = "子导航") |
|||
private List<MenuVo> children; |
|||
} |
@ -0,0 +1,92 @@ |
|||
package com.gxwebsoft.shop.vo; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 应用信息 |
|||
* 专门用于前端展示,只包含前端需要的字段 |
|||
* |
|||
* @author WebSoft |
|||
* @since 2025-01-12 |
|||
*/ |
|||
@Data |
|||
@Schema(description = "应用信息视图对象") |
|||
public class ShopVo implements Serializable { |
|||
|
|||
@Schema(description = "应用ID") |
|||
private Integer appId; |
|||
|
|||
@Schema(description = "应用名称") |
|||
private String appName; |
|||
|
|||
@Schema(description = "应用介绍") |
|||
private String description; |
|||
|
|||
@Schema(description = "网站关键词") |
|||
private String keywords; |
|||
|
|||
@Schema(description = "应用编号") |
|||
private String appCode; |
|||
|
|||
@Schema(description = "小程序二维码") |
|||
private String mpQrCode; |
|||
|
|||
@Schema(description = "标题") |
|||
private String title; |
|||
|
|||
@Schema(description = "LOGO") |
|||
private String logo; |
|||
|
|||
@Schema(description = "图标") |
|||
private String icon; |
|||
|
|||
@Schema(description = "域名") |
|||
private String domain; |
|||
|
|||
@Schema(description = "运行状态 0未开通 1正常 2维护中 3违规关停") |
|||
private Integer running; |
|||
|
|||
@Schema(description = "应用版本 10免费版 20授权版 30永久授权") |
|||
private Integer version; |
|||
|
|||
@Schema(description = "服务到期时间") |
|||
private String expirationTime; |
|||
|
|||
@Schema(description = "创建时间") |
|||
private String createTime; |
|||
|
|||
@Schema(description = "是否到期 -1已过期 1未过期") |
|||
private Integer expired; |
|||
|
|||
@Schema(description = "剩余天数") |
|||
private Long expiredDays; |
|||
|
|||
@Schema(description = "即将过期 0否 1是") |
|||
private Integer soon; |
|||
|
|||
@Schema(description = "状态图标") |
|||
private String statusIcon; |
|||
|
|||
@Schema(description = "状态文本") |
|||
private String statusText; |
|||
|
|||
@Schema(description = "网站配置") |
|||
private Object config; |
|||
|
|||
@Schema(description = "服务器时间信息") |
|||
private HashMap<String, Object> serverTime; |
|||
|
|||
@Schema(description = "顶部导航") |
|||
private List<MenuVo> topNavs; |
|||
|
|||
@Schema(description = "底部导航") |
|||
private List<MenuVo> bottomNavs; |
|||
|
|||
@Schema(description = "网站设置") |
|||
private Object setting; |
|||
} |
Loading…
Reference in new issue