diff --git a/zlt-business/user-center/src/main/java/com/central/user/controller/SysWechatConfigController.java b/zlt-business/user-center/src/main/java/com/central/user/controller/SysWechatConfigController.java index e6c8c2d6..09111ca3 100644 --- a/zlt-business/user-center/src/main/java/com/central/user/controller/SysWechatConfigController.java +++ b/zlt-business/user-center/src/main/java/com/central/user/controller/SysWechatConfigController.java @@ -61,14 +61,15 @@ public class SysWechatConfigController { @Operation(summary = "保存微信配置") @PostMapping public Result saveConfig(@RequestBody WechatConfig config) { - config.setTenantId(TenantContextHolder.getTenant()); + if (config.getId() == null) { + config.setTenantId(TenantContextHolder.getTenant()); + } return Result.succeed(wechatConfigService.saveConfig(config)); } @Operation(summary = "更新微信配置") @PutMapping public Result updateConfig(@RequestBody WechatConfig config) { - config.setTenantId(TenantContextHolder.getTenant()); return Result.succeed(wechatConfigService.updateConfig(config)); } diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/token/TencentAuthenticationToken.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/token/TencentAuthenticationToken.java index 5f36dc61..57d2a661 100644 --- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/token/TencentAuthenticationToken.java +++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/token/TencentAuthenticationToken.java @@ -20,22 +20,22 @@ public class TencentAuthenticationToken extends BaseAuthenticationToken { private final Object principal; private final String encryptedData; private final String iv; - private final String appId; + private final String appCode; - public TencentAuthenticationToken(String code, String encryptedData, String iv, String appId) { + public TencentAuthenticationToken(String code, String encryptedData, String iv, String appCode) { super(GRANT_TYPE); this.principal = code; this.encryptedData = encryptedData; this.iv = iv; - this.appId = appId; + this.appCode = appCode; super.setAuthenticated(true); } - public TencentAuthenticationToken(UserDetails user, Collection authorities, String encryptedData, String iv, String appId) { + public TencentAuthenticationToken(UserDetails user, Collection authorities, String encryptedData, String iv, String appCode) { super(authorities); this.principal = user; this.encryptedData = encryptedData; this.iv = iv; - this.appId = appId; + this.appCode = appCode; } } diff --git a/zlt-commons/zlt-wechat-spring-boot-starter/src/main/java/com/zlt/wechat/config/WechatAutoConfiguration.java b/zlt-commons/zlt-wechat-spring-boot-starter/src/main/java/com/zlt/wechat/config/WechatAutoConfiguration.java index 19797cc0..3e9b453f 100644 --- a/zlt-commons/zlt-wechat-spring-boot-starter/src/main/java/com/zlt/wechat/config/WechatAutoConfiguration.java +++ b/zlt-commons/zlt-wechat-spring-boot-starter/src/main/java/com/zlt/wechat/config/WechatAutoConfiguration.java @@ -19,6 +19,7 @@ import com.wechat.pay.java.service.refund.RefundService; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; @@ -34,6 +35,7 @@ public class WechatAutoConfiguration { @Bean @ConditionalOnMissingBean + @ConditionalOnBean(WechatConfigService.class) public WxMpService wxMpService(WechatConfigService configService) { return new WxMpServiceImpl() { @Override @@ -49,8 +51,16 @@ public class WechatAutoConfiguration { }; } + /** + * 这个配置类在启动时可能会遇到问题,因为: + * WechatAutoConfiguration是一个自动配置类 + * 它依赖于WechatConfigService这个Feign客户端 + * 如果Feign客户端还没有被创建,就会导致注入失败 + * 因此使用@ConditionalOnBean注解确保配置类只在Feign客户端可用时才创建相关Bean + */ @Bean @ConditionalOnMissingBean + @ConditionalOnBean(WechatConfigService.class) public WxMaService wxMaService(WechatConfigService configService) { return new WxMaServiceImpl() { @Override @@ -88,6 +98,7 @@ public class WechatAutoConfiguration { @Bean @ConditionalOnMissingBean + @ConditionalOnBean(WechatConfigService.class) public Config wxPayConfig(WechatConfigService configService, PrivateKeyService privateKeyService) { WechatConfig config = configService.getConfig("PAY", getCurrentTenantId()); String privateKey = privateKeyService.getPrivateKey(getCurrentTenantId(), "PAY"); @@ -113,6 +124,7 @@ public class WechatAutoConfiguration { @Bean @ConditionalOnMissingBean + @ConditionalOnBean(WechatConfigService.class) public NotificationConfig notificationConfig(WechatConfigService configService, PrivateKeyService privateKeyService) { WechatConfig config = configService.getConfig("PAY", getCurrentTenantId()); String privateKey = privateKeyService.getPrivateKey(getCurrentTenantId(), "PAY"); @@ -138,6 +150,7 @@ public class WechatAutoConfiguration { @Bean @ConditionalOnMissingBean + @ConditionalOnBean(WechatConfigService.class) public SettleInfo settleInfo(WechatConfigService configService) { WechatConfig config = configService.getConfig("PAY", getCurrentTenantId()); SettleInfo settleInfo = new SettleInfo(); @@ -147,6 +160,7 @@ public class WechatAutoConfiguration { @Bean @ConditionalOnMissingBean + @ConditionalOnBean(WechatConfigService.class) public Executor profitSharingExecutor(WechatConfigService configService) { WechatConfig config = configService.getConfig("PAY", getCurrentTenantId()); if (!config.getAsyncEnabled()) { diff --git a/zlt-uaa/src/main/java/com/central/oauth/support/tencent/TencentAuthenticationProvider.java b/zlt-uaa/src/main/java/com/central/oauth/support/tencent/TencentAuthenticationProvider.java index 94e048f3..02616404 100644 --- a/zlt-uaa/src/main/java/com/central/oauth/support/tencent/TencentAuthenticationProvider.java +++ b/zlt-uaa/src/main/java/com/central/oauth/support/tencent/TencentAuthenticationProvider.java @@ -72,10 +72,10 @@ public class TencentAuthenticationProvider extends BaseAuthenticationProvider { String code = (String) authToken.getPrincipal(); String encryptedData = authToken.getEncryptedData(); String iv = authToken.getIv(); - String appid = authToken.getAppId(); // 前端需传递 + String appCode = authToken.getAppCode(); // 前端需传递 // 1. 根据appid查找配置 - WechatConfig config = userDetailsServiceFactory.getService(authToken).loadMiniAppConfig(appid); + WechatConfig config = userDetailsServiceFactory.getService(authToken).loadMiniAppConfig(appCode); if (config == null) { throw new CustomOAuth2AuthenticationException("不支持的appid"); } @@ -99,7 +99,7 @@ public class TencentAuthenticationProvider extends BaseAuthenticationProvider { throw new CustomOAuth2AuthenticationException("用户登录信息待处理,请重新登录"); } - return new TencentAuthenticationToken(userDetails, userDetails.getAuthorities(),encryptedData, iv,appid); + return new TencentAuthenticationToken(userDetails, userDetails.getAuthorities(),encryptedData, iv,appCode); } @Override diff --git a/zlt-web/react-web/src/main/frontend/config/proxy.ts b/zlt-web/react-web/src/main/frontend/config/proxy.ts index 61b5280f..28ffaeca 100644 --- a/zlt-web/react-web/src/main/frontend/config/proxy.ts +++ b/zlt-web/react-web/src/main/frontend/config/proxy.ts @@ -9,23 +9,23 @@ export default { dev: { '/api-uaa/': { - target: 'http://119.45.169.13:9900', - // target: 'http://127.0.0.1:9900', + // target: 'http://119.45.169.13:9900', + target: 'http://127.0.0.1:9900', changeOrigin: true, }, '/api-user/': { - target: 'http://119.45.169.13:9900', - // target: 'http://127.0.0.1:9900', + // target: 'http://119.45.169.13:9900', + target: 'http://127.0.0.1:9900', changeOrigin: true, }, '/api-log/': { - target: 'http://119.45.169.13:9900', - // target: 'http://127.0.0.1:9900', + // target: 'http://119.45.169.13:9900', + target: 'http://127.0.0.1:9900', changeOrigin: true, }, '/api-search/': { - target: 'http://119.45.169.13:9900', - // target: 'http://127.0.0.1:9900', + // target: 'http://119.45.169.13:9900', + target: 'http://127.0.0.1:9900', changeOrigin: true, }, '/api-generator/': { @@ -34,18 +34,18 @@ changeOrigin: true, }, '/api-file/': { - target: 'http://119.45.169.13:9900', - // target: 'http://127.0.0.1:9900', + // target: 'http://119.45.169.13:9900', + target: 'http://127.0.0.1:9900', changeOrigin: true, }, '/api-order/': { - target: 'http://119.45.169.13:9900', - // target: 'http://127.0.0.1:9900', + // target: 'http://119.45.169.13:9900', + target: 'http://127.0.0.1:9900', changeOrigin: true, }, '/api-device/': { - target: 'http://119.45.169.13:9900', - // target: 'http://127.0.0.1:9900', + // target: 'http://119.45.169.13:9900', + target: 'http://127.0.0.1:9900', changeOrigin: true, }, }, diff --git a/zlt-web/react-web/src/main/frontend/src/pages/system/MiniApp/components/UpdateForm.tsx b/zlt-web/react-web/src/main/frontend/src/pages/system/MiniApp/components/UpdateForm.tsx index 83d0d063..746899a8 100644 --- a/zlt-web/react-web/src/main/frontend/src/pages/system/MiniApp/components/UpdateForm.tsx +++ b/zlt-web/react-web/src/main/frontend/src/pages/system/MiniApp/components/UpdateForm.tsx @@ -3,13 +3,21 @@ import { ProForm, ProFormText, ProFormSelect, + ProFormSwitch, + ProFormDigit, } from '@ant-design/pro-components'; import React from 'react'; const STATUS_OPTIONS = [ { label: '启用', value: 1 }, { label: '禁用', value: 0 }, -] as const; +]; + +const TYPE_OPTIONS = [ + { label: '公众号', value: 'MP' }, + { label: '小程序', value: 'MINI' }, + { label: '支付', value: 'PAY' }, +]; interface UpdateFormProps { onSubmit: (values: any) => Promise; @@ -21,7 +29,7 @@ interface UpdateFormProps { const UpdateForm: React.FC = (props) => { return ( = (props) => { modalProps={{ destroyOnClose: true }} > - + + + + + + + + + + + + + + = (props) => { label="状态" options={STATUS_OPTIONS} /> + ); diff --git a/zlt-web/react-web/src/main/frontend/src/pages/system/MiniApp/index.tsx b/zlt-web/react-web/src/main/frontend/src/pages/system/MiniApp/index.tsx index f89f4074..1c2d6237 100644 --- a/zlt-web/react-web/src/main/frontend/src/pages/system/MiniApp/index.tsx +++ b/zlt-web/react-web/src/main/frontend/src/pages/system/MiniApp/index.tsx @@ -1,8 +1,5 @@ import { PlusOutlined, - ExportOutlined, - ImportOutlined, - DownloadOutlined, } from '@ant-design/icons'; import type { ActionType, ProColumns } from '@ant-design/pro-components'; import { @@ -11,18 +8,26 @@ import { ProForm, ProFormText, ProFormSelect, + ProFormSwitch, + ProFormDigit, ProTable, QueryFilter, } from '@ant-design/pro-components'; import { Button, message, Space, Tag } from 'antd'; import React, { useRef, useState } from 'react'; -import { getMiniAppList, saveOrUpdateMiniApp, deleteMiniApp } from '@/services/system/api'; +import { getMiniAppList, saveMiniApp, updateMiniApp, deleteMiniApp } from '@/services/system/api'; import UpdateForm from './components/UpdateForm'; -const STATUS_OPTIONS = [ +const STATUS_OPTIONS: { label: string; value: number }[] = [ { label: '启用', value: 1 }, { label: '禁用', value: 0 }, -] as const; +]; + +const TYPE_OPTIONS: { label: string; value: string }[] = [ + { label: '公众号', value: 'MP' }, + { label: '小程序', value: 'MINI' }, + { label: '支付', value: 'PAY' }, +]; const TableList: React.FC = () => { const [searchParams, setSearchParams] = useState>({}); @@ -62,18 +67,23 @@ const TableList: React.FC = () => { width: 48, }, { - title: '小程序名称', - dataIndex: 'name', + title: '配置类型', + dataIndex: 'type', + valueType: 'select', + valueEnum: { + MP: { text: '公众号' }, + MINI: { text: '小程序' }, + PAY: { text: '支付' }, + }, + }, + { + title: '商户ID', + dataIndex: 'merchantId', copyable: true, }, { - title: 'AppCode', - dataIndex: 'appid', - copyable: true, - }, - { - title: 'AppID', - dataIndex: 'appid', + title: '应用ID', + dataIndex: 'appId', copyable: true, }, { @@ -90,6 +100,16 @@ const TableList: React.FC = () => { ), }, + { + title: '分账功能', + dataIndex: 'profitSharingEnabled', + valueType: 'switch', + }, + { + title: '异步处理', + dataIndex: 'asyncEnabled', + valueType: 'switch', + }, { title: '创建时间', dataIndex: 'createTime', @@ -141,23 +161,94 @@ const TableList: React.FC = () => { // 表单字段定义 const renderModalContent = () => ( - + + + + + + + + + + + + + + { options={STATUS_OPTIONS} initialValue={1} /> + ); return ( - + { name="searchKey" label="搜索" valueEnum={{ - name: '小程序名称', - appid: 'AppID', + type: '配置类型', + merchantId: '商户ID', + appId: '应用ID', }} /> @@ -190,15 +287,15 @@ const TableList: React.FC = () => { rowKey="id" - headerTitle="小程序管理" + headerTitle="微信配置管理" actionRef={actionRef} request={async (params, sorter, filter) => { const res = await getMiniAppList({ - page: params.current, - limit: params.pageSize, + page: params.current || 1, + limit: params.pageSize || 10, searchKey: params.searchKey, searchValue: params.searchValue, - }); + }) as any; return { data: res.data || [], @@ -221,13 +318,19 @@ const TableList: React.FC = () => { /> { const success = await handleRequest( - () => saveOrUpdateMiniApp(values), + () => saveMiniApp({ + ...values, + id: currentRow?.id, + appId: values.appId, + appSecret: values.appSecret, + status: values.status, + } as SYSTEM.MiniApp), '正在添加', '添加成功' ); @@ -245,7 +348,7 @@ const TableList: React.FC = () => { { const success = await handleRequest( - () => saveOrUpdateMiniApp({ ...values, id: currentRow?.id }), + () => updateMiniApp({ ...values, id: currentRow?.id }), '正在更新', '更新成功' ); diff --git a/zlt-web/react-web/src/main/frontend/src/services/system/api.ts b/zlt-web/react-web/src/main/frontend/src/services/system/api.ts index c0ff4709..06628d4b 100644 --- a/zlt-web/react-web/src/main/frontend/src/services/system/api.ts +++ b/zlt-web/react-web/src/main/frontend/src/services/system/api.ts @@ -254,21 +254,33 @@ export async function getMiniAppList(params: { searchKey?: string; searchValue?: string; }) { - return request>('/api-user/miniApp/list', { + return request<{ + data: SYSTEM.MiniApp[]; + count: number; + resp_code: number; + resp_msg?: string; + }>('/api-user/wechat/config', { method: 'GET', params, }); } -export async function saveOrUpdateMiniApp(data: SYSTEM.MiniApp) { - return request>('/api-user/miniApp/saveOrUpdate', { +export async function saveMiniApp(data: SYSTEM.MiniApp) { + return request>('/api-user/wechat/config', { method: 'POST', data, }); } +export async function updateMiniApp(data: SYSTEM.MiniApp) { + return request>('/api-user/wechat/config', { + method: 'PUT', + data, + }); +} + export async function deleteMiniApp(id: number) { - return request>(`/api-user/miniApp/delete/${id}`, { + return request>(`/api-user/wechat/config/${id}`, { method: 'DELETE', }); } diff --git a/zlt-web/react-web/src/main/frontend/src/services/system/typings.d.ts b/zlt-web/react-web/src/main/frontend/src/services/system/typings.d.ts index b66c5539..67b2d0c0 100644 --- a/zlt-web/react-web/src/main/frontend/src/services/system/typings.d.ts +++ b/zlt-web/react-web/src/main/frontend/src/services/system/typings.d.ts @@ -104,11 +104,36 @@ declare namespace SYSTEM { interface MiniApp { id: number; - appid: string; - secret: string; - name: string; + tenantId?: string; + type?: string; + merchantId?: string; + appId: string; + appSecret: string; + mchKey?: string; + mchSerialNo?: string; + privateKeyPath?: string; + apiV3Key?: string; + notifyUrl?: string; + token?: string; + aesKey?: string; + paymentSuccessTemplateId?: string; + videoCompleteTemplateId?: string; + videoFailTemplateId?: string; + profitSharingEnabled?: boolean; + asyncEnabled?: boolean; + asyncPoolSize?: number; status: number; - createTime: string; - updateTime: string; + remark?: string; + createTime?: string; + updateTime?: string; + } +} + +declare namespace API { + interface OptionalResult { + data: T; + count: number; + resp_code: number; + resp_msg?: string; } }