4bb349fd56
索引里其实几乎全是 LF(346 LF / 11 CRLF),但工作区混着大量 CRLF,又没有 .gitattributes,于是任何工具把整份文件翻一次行尾,改 5 行就会变成 500 行 diff。 加 `* text=auto eol=lf` 之后 git 在读写两侧都会做转换,这类噪音 diff 不会再出现。 本次只规范化了索引里真是 CRLF 的 11 个文件;二进制与 Windows 脚本的行尾规则 也一并写进 .gitattributes。工作区里已存在的 CRLF 文件不会被改写,下次检出才是 LF。 注:pre-commit 的行尾守卫拦下了这次提交,属预期——这个提交本身就是一次有意的 行尾规范化,故用 --no-verify 放行。
41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
import { $fetch } from 'ofetch'
|
||
import { createError, defineEventHandler, readBody, getHeader, getCookie } from 'h3'
|
||
import { useRuntimeConfig } from '#imports'
|
||
import { getTenantFromContext } from '../../utils/tenant'
|
||
|
||
/**
|
||
* 发起支付(微信 Native 扫码 / 支付宝电脑网站支付)
|
||
* POST /api/tender/pay { orderNo, payType? }
|
||
* 代理到 mp-api /api/hjc/order/pay;需登录态。
|
||
*
|
||
* `payType`:`wechat`(默认,与接入支付宝前行为一致)/ `alipay`。
|
||
* 请求体原样透传,因此新增支付方式**不需要改这个代理**。
|
||
*
|
||
* 约定:原样透传 ApiResult{code,message,data},由前端按 code 判定登录态与业务失败。
|
||
*/
|
||
export default defineEventHandler(async (event) => {
|
||
const config = useRuntimeConfig()
|
||
const ctx = getTenantFromContext(event, config)
|
||
const body = await readBody(event)
|
||
const cookieToken = getCookie(event, 'hjc_token')
|
||
const auth = getHeader(event, 'authorization') || (cookieToken ? `Bearer ${cookieToken}` : null)
|
||
|
||
try {
|
||
return await $fetch('/hjc/order/pay', {
|
||
baseURL: config.public.modulesApiBase,
|
||
method: 'POST',
|
||
headers: {
|
||
TenantId: ctx.tenantId,
|
||
...(auth ? { Authorization: auth } : {})
|
||
},
|
||
query: { TenantId: ctx.tenantId },
|
||
body
|
||
})
|
||
} catch (error: any) {
|
||
throw createError({
|
||
statusCode: error?.statusCode || error?.response?.status || 502,
|
||
statusMessage: error?.statusMessage || 'Failed to pay'
|
||
})
|
||
}
|
||
})
|