fix: 微信配置
All checks were successful
构建并部署前端到测试环境 / build-and-deploy (push) Successful in 5m39s

This commit is contained in:
sexygoat
2026-05-22 16:07:47 +08:00
parent b364fb4aec
commit 878d93a865
10 changed files with 994 additions and 633 deletions

View File

@@ -1,5 +1,5 @@
/**
* 微信支付配置管理 API
* 支付配置管理 API
*/
import { BaseService } from '../BaseService'
@@ -12,6 +12,8 @@ import type {
UpdateWechatConfigRequest
} from '@/types/api/wechatConfig'
const PAYMENT_CONFIG_BASE_URL = '/api/admin/wechat-configs'
export class WechatConfigService extends BaseService {
/**
* 获取支付配置列表
@@ -19,21 +21,21 @@ export class WechatConfigService extends BaseService {
static getWechatConfigs(
params?: WechatConfigQueryParams
): Promise<BaseResponse<WechatConfigListResponse>> {
return this.get<BaseResponse<WechatConfigListResponse>>('/api/admin/wechat-configs', params)
return this.get<BaseResponse<WechatConfigListResponse>>(PAYMENT_CONFIG_BASE_URL, params)
}
/**
* 获取支付配置详情
*/
static getWechatConfigById(id: number): Promise<BaseResponse<WechatConfig>> {
return this.get<BaseResponse<WechatConfig>>(`/api/admin/wechat-configs/${id}`)
return this.get<BaseResponse<WechatConfig>>(`${PAYMENT_CONFIG_BASE_URL}/${id}`)
}
/**
* 创建支付配置
*/
static createWechatConfig(data: CreateWechatConfigRequest): Promise<BaseResponse<WechatConfig>> {
return this.post<BaseResponse<WechatConfig>>('/api/admin/wechat-configs', data)
return this.post<BaseResponse<WechatConfig>>(PAYMENT_CONFIG_BASE_URL, data)
}
/**
@@ -43,34 +45,34 @@ export class WechatConfigService extends BaseService {
id: number,
data: UpdateWechatConfigRequest
): Promise<BaseResponse<WechatConfig>> {
return this.put<BaseResponse<WechatConfig>>(`/api/admin/wechat-configs/${id}`, data)
return this.put<BaseResponse<WechatConfig>>(`${PAYMENT_CONFIG_BASE_URL}/${id}`, data)
}
/**
* 删除支付配置
*/
static deleteWechatConfig(id: number): Promise<BaseResponse<void>> {
return this.delete<BaseResponse<void>>(`/api/admin/wechat-configs/${id}`)
return this.delete<BaseResponse<void>>(`${PAYMENT_CONFIG_BASE_URL}/${id}`)
}
/**
* 激活支付配置
*/
static activateWechatConfig(id: number): Promise<BaseResponse<WechatConfig>> {
return this.post<BaseResponse<WechatConfig>>(`/api/admin/wechat-configs/${id}/activate`)
return this.post<BaseResponse<WechatConfig>>(`${PAYMENT_CONFIG_BASE_URL}/${id}/activate`)
}
/**
* 停用支付配置
*/
static deactivateWechatConfig(id: number): Promise<BaseResponse<WechatConfig>> {
return this.post<BaseResponse<WechatConfig>>(`/api/admin/wechat-configs/${id}/deactivate`)
return this.post<BaseResponse<WechatConfig>>(`${PAYMENT_CONFIG_BASE_URL}/${id}/deactivate`)
}
/**
* 获取当前生效的支付配置
*/
static getActiveWechatConfig(): Promise<BaseResponse<WechatConfig>> {
return this.get<BaseResponse<WechatConfig>>('/api/admin/wechat-configs/active')
return this.get<BaseResponse<WechatConfig>>(`${PAYMENT_CONFIG_BASE_URL}/active`)
}
}

View File

@@ -5,26 +5,30 @@
// 支付渠道类型
export type PaymentProviderType = 'wechat' | 'wechat_v2' | 'fuiou'
// 微信配置
export interface WechatConfig {
interface PaymentConfigBase {
id: number
name: string
description: string
provider_type: PaymentProviderType
is_active: boolean
created_at: string
updated_at: string
}
// 小程序配置
interface MiniappConfigFields {
miniapp_app_id: string
miniapp_app_secret: string
}
// 公众号配置
interface OfficialAccountConfigFields {
oa_app_id: string
oa_app_secret: string
oa_token: string
oa_aes_key: string
oa_oauth_redirect_url: string
}
// 微信配置
interface WechatPayConfigFields {
wx_mch_id: string
wx_api_v2_key: string
wx_api_v3_key: string
@@ -32,8 +36,19 @@ export interface WechatConfig {
wx_serial_no: string
wx_cert_content: string
wx_key_content: string
}
// 富友支付配置
interface AlipayConfigFields {
ali_app_id: string
ali_private_key: string
ali_public_key: string
ali_notify_url: string
ali_return_url: string
ali_pay_expire_minutes: number
ali_production: boolean
}
interface FuiouConfigFields {
fy_api_url: string
fy_ins_cd: string
fy_mchnt_cd: string
@@ -41,11 +56,25 @@ export interface WechatConfig {
fy_notify_url: string
fy_private_key: string
fy_public_key: string
created_at: string
updated_at: string
}
type PaymentConfigWritableFields = Partial<
MiniappConfigFields &
OfficialAccountConfigFields &
WechatPayConfigFields &
AlipayConfigFields &
FuiouConfigFields
>
// 支付配置
export interface WechatConfig
extends PaymentConfigBase,
MiniappConfigFields,
OfficialAccountConfigFields,
WechatPayConfigFields,
AlipayConfigFields,
FuiouConfigFields {}
// 查询参数
export interface WechatConfigQueryParams {
page?: number
@@ -58,78 +87,21 @@ export interface WechatConfigQueryParams {
export interface WechatConfigListResponse {
items: WechatConfig[]
page: number
page_size: number
size: number
total: number
page_size?: number
}
// 创建微信支付配置请求
export interface CreateWechatConfigRequest {
export interface CreateWechatConfigRequest extends PaymentConfigWritableFields {
name: string
provider_type: PaymentProviderType
description?: string
// 小程序配置
miniapp_app_id?: string
miniapp_app_secret?: string
// 公众号配置
oa_app_id?: string
oa_app_secret?: string
oa_token?: string
oa_aes_key?: string
oa_oauth_redirect_url?: string
// 微信配置
wx_mch_id?: string
wx_api_v2_key?: string
wx_api_v3_key?: string
wx_notify_url?: string
wx_serial_no?: string
wx_cert_content?: string
wx_key_content?: string
// 富友支付配置
fy_api_url?: string
fy_ins_cd?: string
fy_mchnt_cd?: string
fy_term_id?: string
fy_notify_url?: string
fy_private_key?: string
fy_public_key?: string
}
// 更新微信支付配置请求
export interface UpdateWechatConfigRequest {
export interface UpdateWechatConfigRequest extends PaymentConfigWritableFields {
name?: string
description?: string
provider_type?: PaymentProviderType
// 小程序配置
miniapp_app_id?: string
miniapp_app_secret?: string
// 公众号配置
oa_app_id?: string
oa_app_secret?: string
oa_token?: string
oa_aes_key?: string
oa_oauth_redirect_url?: string
// 微信配置
wx_mch_id?: string
wx_api_v2_key?: string
wx_api_v3_key?: string
wx_notify_url?: string
wx_serial_no?: string
wx_cert_content?: string
wx_key_content?: string
// 富友支付配置
fy_api_url?: string
fy_ins_cd?: string
fy_mchnt_cd?: string
fy_term_id?: string
fy_notify_url?: string
fy_private_key?: string
fy_public_key?: string
}

View File

@@ -0,0 +1,64 @@
import type { PaymentProviderType, WechatConfig } from '@/types/api'
const PAYMENT_PROVIDER_LABELS: Record<PaymentProviderType, string> = {
wechat: '微信直连',
wechat_v2: '微信直连V2',
fuiou: '富友支付'
}
export const getPaymentProviderText = (type: PaymentProviderType): string => {
return PAYMENT_PROVIDER_LABELS[type] || type
}
export const getPaymentMerchantId = (
config: Pick<WechatConfig, 'provider_type' | 'wx_mch_id' | 'fy_mchnt_cd'>
): string => {
if (config.provider_type === 'wechat' || config.provider_type === 'wechat_v2') {
return config.wx_mch_id || '-'
}
if (config.provider_type === 'fuiou') {
return config.fy_mchnt_cd || '-'
}
return '-'
}
export const getPaymentNotifyUrl = (
config: Pick<WechatConfig, 'provider_type' | 'wx_notify_url' | 'fy_notify_url' | 'ali_notify_url'>
): string => {
if (config.provider_type === 'wechat' || config.provider_type === 'wechat_v2') {
return config.wx_notify_url || '-'
}
if (config.provider_type === 'fuiou') {
return config.fy_notify_url || '-'
}
return config.ali_notify_url || '-'
}
export const getPaymentConfigStatus = (value: string | undefined | null): string => {
if (!value) return '未配置'
if (value === 'configured' || value === '[已配置]' || value === '已配置') {
return '已配置'
}
if (value === '[未配置]' || value === '未配置') {
return '未配置'
}
return value
}
export const isMaskedPaymentConfigValue = (value: string | undefined | null): boolean => {
if (!value) return false
return (
value === '***' ||
value.includes('已配置') ||
value.includes('未配置') ||
/\*{2,}/.test(value)
)
}

View File

@@ -8,7 +8,7 @@
<ElTag v-else type="info" effect="plain" size="small">未配置</ElTag>
</div>
<div v-if="activeConfig" class="header-right">
<span class="creator-info">创建 {{ formatDateTime(activeConfig.created_at) }}</span>
<span class="creator-info">更新 {{ formatDateTime(activeConfig.updated_at) }}</span>
</div>
</div>
</template>
@@ -61,6 +61,30 @@
<div class="info-value">{{ activeConfig.is_active ? '已激活' : '未激活' }}</div>
</div>
</div>
<div class="info-card">
<div
class="info-icon"
style="background: linear-gradient(135deg, #fa709a 0%, #fee140 100%)"
>
<i class="el-icon">🔔</i>
</div>
<div class="info-content">
<div class="info-label">支付回调地址</div>
<div class="info-value">{{ getNotifyUrl(activeConfig) }}</div>
</div>
</div>
<div class="info-card">
<div
class="info-icon"
style="background: linear-gradient(135deg, #30cfd0 0%, #330867 100%)"
>
<i class="el-icon">🔐</i>
</div>
<div class="info-content">
<div class="info-label">凭证状态</div>
<div class="info-value">{{ getCredentialStatus(activeConfig) }}</div>
</div>
</div>
</div>
<div v-else class="empty-content">
<i class="el-icon-info" style="font-size: 48px; color: var(--el-text-color-placeholder)"></i>
@@ -72,8 +96,14 @@
<script setup lang="ts">
import { WechatConfigService } from '@/api/modules'
import { ElTag } from 'element-plus'
import type { WechatConfig, PaymentProviderType } from '@/types/api'
import type { WechatConfig } from '@/types/api'
import { formatDateTime } from '@/utils/business/format'
import {
getPaymentConfigStatus,
getPaymentMerchantId,
getPaymentNotifyUrl,
getPaymentProviderText
} from '@/utils/business/paymentConfig'
import { usePermission } from '@/composables/usePermission'
defineOptions({ name: 'ActiveWechatConfigWidget' })
@@ -83,23 +113,43 @@
// 当前生效的支付配置
const activeConfig = ref<WechatConfig | null>(null)
// 获取支付渠道类型文本
const getProviderTypeText = (type: PaymentProviderType): string => {
const typeMap: Record<PaymentProviderType, string> = {
wechat: '微信直连',
fuiou: '富友支付'
}
return typeMap[type] || type
const getProviderTypeText = (type: WechatConfig['provider_type']): string => {
return getPaymentProviderText(type)
}
// 获取商户号
const getMerchantId = (config: WechatConfig): string => {
if (config.provider_type === 'wechat') {
return config.wx_mch_id || '-'
return getPaymentMerchantId(config)
}
const getNotifyUrl = (config: WechatConfig): string => {
return getPaymentNotifyUrl(config)
}
const getCredentialStatus = (config: WechatConfig): string => {
if (config.provider_type === 'wechat' || config.provider_type === 'wechat_v2') {
const certStatus = getPaymentConfigStatus(config.wx_cert_content)
const keyStatus = getPaymentConfigStatus(config.wx_key_content)
if (certStatus === '已配置' && keyStatus === '已配置') {
return '证书/密钥已配置'
}
if (certStatus === '未配置' && keyStatus === '未配置') {
return '未配置'
}
return '部分配置'
}
if (config.provider_type === 'fuiou') {
return config.fy_mchnt_cd || '-'
const privateKeyStatus = getPaymentConfigStatus(config.fy_private_key)
const publicKeyStatus = getPaymentConfigStatus(config.fy_public_key)
if (privateKeyStatus === '已配置' && publicKeyStatus === '已配置') {
return '富友密钥已配置'
}
if (privateKeyStatus === '未配置' && publicKeyStatus === '未配置') {
return '未配置'
}
return '部分配置'
}
return '-'
}

View File

@@ -27,14 +27,14 @@
<script setup lang="ts">
import { ref, onMounted, computed } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { ElCard, ElButton, ElIcon, ElMessage } from 'element-plus'
import { ElCard, ElButton, ElIcon } from 'element-plus'
import { ArrowLeft, Loading } from '@element-plus/icons-vue'
import DetailPage from '@/components/common/DetailPage.vue'
import type { DetailSection } from '@/components/common/DetailPage.vue'
import { WechatConfigService } from '@/api/modules'
import type { WechatConfig, PaymentProviderType } from '@/types/api'
import type { WechatConfig } from '@/types/api'
import { formatDateTime } from '@/utils/business/format'
import { RoutesAlias } from '@/router/routesAlias'
import { getPaymentConfigStatus, getPaymentProviderText } from '@/utils/business/paymentConfig'
defineOptions({ name: 'WechatConfigDetail' })
@@ -46,21 +46,9 @@
const configId = computed(() => Number(route.params.id))
const pageTitle = computed(() => `支付配置详情 #${configId.value}`)
// 获取支付渠道类型文本
const getProviderTypeText = (type: PaymentProviderType): string => {
const typeMap: Record<PaymentProviderType, string> = {
wechat: '微信直连',
wechat_v2: '微信直连V2',
fuiou: '富友支付'
}
return typeMap[type] || type
}
// 获取配置状态文本
const getConfigStatus = (value: string | undefined | null): string => {
if (!value) return '未配置'
return value === 'configured' ? '已配置' : value
const formatText = (value: string | number | undefined | null): string => {
if (value === undefined || value === null || value === '') return '-'
return String(value)
}
// 基础详情配置
@@ -71,7 +59,7 @@
{ label: '配置名称', prop: 'name' },
{
label: '支付渠道类型',
formatter: (_, data) => getProviderTypeText(data.provider_type)
formatter: (_, data) => getPaymentProviderText(data.provider_type)
},
{
label: '激活状态',
@@ -103,12 +91,12 @@
{
label: '小程序AppID',
prop: 'miniapp_app_id',
formatter: (value) => value || '-'
formatter: (value) => formatText(value)
},
{
label: '小程序AppSecret',
prop: 'miniapp_app_secret',
formatter: (value) => value || '-'
formatter: (value) => formatText(value)
}
]
}
@@ -120,32 +108,74 @@
{
label: '公众号AppID',
prop: 'oa_app_id',
formatter: (value) => value || '-'
formatter: (value) => formatText(value)
},
{
label: '公众号AppSecret',
prop: 'oa_app_secret',
formatter: (value) => value || '-'
formatter: (value) => formatText(value)
},
{
label: '公众号Token',
prop: 'oa_token',
formatter: (value) => value || '-'
formatter: (value) => formatText(value)
},
{
label: '公众号AES Key',
prop: 'oa_aes_key',
formatter: (value) => value || '-'
formatter: (value) => formatText(value)
},
{
label: 'OAuth回调地址',
prop: 'oa_oauth_redirect_url',
formatter: (value) => value || '-',
formatter: (value) => formatText(value),
fullWidth: true
}
]
}
const alipaySection: DetailSection = {
title: '支付宝配置',
fields: [
{
label: '支付宝AppID',
prop: 'ali_app_id',
formatter: (value) => formatText(value)
},
{
label: '支付过期分钟数',
prop: 'ali_pay_expire_minutes',
formatter: (value) => formatText(value)
},
{
label: '生产环境',
formatter: (_, data) => (data.ali_production ? '是' : '否')
},
{
label: '异步通知地址',
prop: 'ali_notify_url',
formatter: (value) => formatText(value),
fullWidth: true
},
{
label: '同步跳转地址',
prop: 'ali_return_url',
formatter: (value) => formatText(value),
fullWidth: true
},
{
label: '应用私钥',
prop: 'ali_private_key',
formatter: (value) => getPaymentConfigStatus(value)
},
{
label: '支付宝公钥',
prop: 'ali_public_key',
formatter: (value) => getPaymentConfigStatus(value)
}
]
}
// 微信配置
const wechatPaySection: DetailSection = {
title: '微信配置',
@@ -153,38 +183,38 @@
{
label: '微信商户号',
prop: 'wx_mch_id',
formatter: (value) => value || '-'
formatter: (value) => formatText(value)
},
{
label: '证书序列号',
prop: 'wx_serial_no',
formatter: (value) => value || '-'
formatter: (value) => formatText(value)
},
{
label: 'APIv2密钥',
prop: 'wx_api_v2_key',
formatter: (value) => value || '-'
formatter: (value) => formatText(value)
},
{
label: 'APIv3密钥',
prop: 'wx_api_v3_key',
formatter: (value) => value || '-'
formatter: (value) => formatText(value)
},
{
label: '支付回调地址',
prop: 'wx_notify_url',
formatter: (value) => value || '-',
formatter: (value) => formatText(value),
fullWidth: true
},
{
label: '支付证书',
prop: 'wx_cert_content',
formatter: (value) => getConfigStatus(value)
formatter: (value) => getPaymentConfigStatus(value)
},
{
label: '支付密钥',
prop: 'wx_key_content',
formatter: (value) => getConfigStatus(value)
formatter: (value) => getPaymentConfigStatus(value)
}
]
}
@@ -196,38 +226,38 @@
{
label: '富友API地址',
prop: 'fy_api_url',
formatter: (value) => value || '-',
formatter: (value) => formatText(value),
fullWidth: true
},
{
label: '富友机构号',
prop: 'fy_ins_cd',
formatter: (value) => value || '-'
formatter: (value) => formatText(value)
},
{
label: '富友商户号',
prop: 'fy_mchnt_cd',
formatter: (value) => value || '-'
formatter: (value) => formatText(value)
},
{
label: '富友终端号',
prop: 'fy_term_id',
formatter: (value) => value || '-'
formatter: (value) => formatText(value)
},
{
label: '支付回调地址',
prop: 'fy_notify_url',
formatter: (value) => value || '-'
formatter: (value) => formatText(value)
},
{
label: '富友私钥',
prop: 'fy_private_key',
formatter: (value) => getConfigStatus(value)
formatter: (value) => getPaymentConfigStatus(value)
},
{
label: '富友公钥',
prop: 'fy_public_key',
formatter: (value) => getConfigStatus(value)
formatter: (value) => getPaymentConfigStatus(value)
}
]
}
@@ -236,10 +266,13 @@
const detailSections = computed<DetailSection[]>(() => {
if (!detailData.value) return [baseSection]
const sections = [baseSection]
const sections = [baseSection, miniappSection, oaSection, alipaySection]
if (detailData.value.provider_type === 'wechat') {
sections.push(miniappSection, oaSection, wechatPaySection)
if (
detailData.value.provider_type === 'wechat' ||
detailData.value.provider_type === 'wechat_v2'
) {
sections.push(wechatPaySection)
} else if (detailData.value.provider_type === 'fuiou') {
sections.push(fuiouSection)
}

File diff suppressed because it is too large Load Diff