import { $fetch } from 'ofetch' import { createError, defineEventHandler, getHeader, getCookie } from 'h3' import { useRuntimeConfig } from '#imports' import { getTenantFromContext } from '../../../utils/tenant' /** * 修改密码-发送短信验证码(**需登录态**) * POST /api/tender/password/sms(无 body) * 代理到 mp-api /api/hjc/auth/password/sms。 * * 收件号由后端从登录态里取核心实例上的手机号(账号绑定手机号),**前端不能指定号码**—— * 否则任何人都能给任意手机号发短信。 */ export default defineEventHandler(async (event) => { const config = useRuntimeConfig() const ctx = getTenantFromContext(event, config) const cookieToken = getCookie(event, 'hjc_token') const auth = getHeader(event, 'authorization') || (cookieToken ? `Bearer ${cookieToken}` : null) try { return await $fetch('/hjc/auth/password/sms', { baseURL: config.public.modulesApiBase, method: 'POST', headers: { TenantId: ctx.tenantId, ...(auth ? { Authorization: auth } : {}) }, query: { TenantId: ctx.tenantId } }) } catch (error: any) { throw createError({ statusCode: error?.statusCode || error?.response?.status || 502, statusMessage: error?.data?.message || error?.statusMessage || '验证码发送失败' }) } })