|
@@ -351,7 +351,20 @@ router.post('/wechat/openid', async (ctx: Context) => {
|
|
|
// 创建微信 JSAPI 支付订单(公众号内支付)
|
|
// 创建微信 JSAPI 支付订单(公众号内支付)
|
|
|
router.post('/wechat/jsapi', authMiddleware, async (ctx: Context) => {
|
|
router.post('/wechat/jsapi', authMiddleware, async (ctx: Context) => {
|
|
|
const userId = safeParseInt(ctx.state.user.userId);
|
|
const userId = safeParseInt(ctx.state.user.userId);
|
|
|
- const { planId, productType, quantity, period = 'monthly', openid } = ctx.request.body as {
|
|
|
|
|
|
|
+ const rawBody = ctx.request.body as any;
|
|
|
|
|
+
|
|
|
|
|
+ // ===== DEBUG: 完整请求日志 =====
|
|
|
|
|
+ console.log('[JSAPI-DEBUG] ========== 收到JSAPI支付请求 ==========');
|
|
|
|
|
+ console.log('[JSAPI-DEBUG] userId:', userId);
|
|
|
|
|
+ console.log('[JSAPI-DEBUG] body keys:', Object.keys(rawBody));
|
|
|
|
|
+ console.log('[JSAPI-DEBUG] body:', JSON.stringify(rawBody, null, 2));
|
|
|
|
|
+ console.log('[JSAPI-DEBUG] headers:', JSON.stringify({
|
|
|
|
|
+ 'content-type': ctx.request.headers['content-type'],
|
|
|
|
|
+ 'user-agent': ctx.request.headers['user-agent'],
|
|
|
|
|
+ 'authorization': ctx.request.headers['authorization'] ? '***' : 'none',
|
|
|
|
|
+ }));
|
|
|
|
|
+
|
|
|
|
|
+ const { planId, productType, quantity, period = 'monthly', openid } = rawBody as {
|
|
|
planId?: number;
|
|
planId?: number;
|
|
|
productType?: string;
|
|
productType?: string;
|
|
|
quantity?: number;
|
|
quantity?: number;
|
|
@@ -359,7 +372,10 @@ router.post('/wechat/jsapi', authMiddleware, async (ctx: Context) => {
|
|
|
openid: string;
|
|
openid: string;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ console.log('[JSAPI-DEBUG] 解析后参数:', JSON.stringify({ planId, productType, quantity, period, openid: openid ? openid.substring(0, 8) + '...' : 'null' }));
|
|
|
|
|
+
|
|
|
if (!openid) {
|
|
if (!openid) {
|
|
|
|
|
+ console.log('[JSAPI-DEBUG] ❌ 缺少openid');
|
|
|
throw new BadRequestError('缺少用户标识(openid),请在微信中打开');
|
|
throw new BadRequestError('缺少用户标识(openid),请在微信中打开');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -380,6 +396,9 @@ router.post('/wechat/jsapi', authMiddleware, async (ctx: Context) => {
|
|
|
|
|
|
|
|
const payParams = await PaymentService.generateWechatJsapiPayment(orderNo, amount, subject, openid);
|
|
const payParams = await PaymentService.generateWechatJsapiPayment(orderNo, amount, subject, openid);
|
|
|
|
|
|
|
|
|
|
+ console.log('[JSAPI-DEBUG] ✅ Token包支付创建成功, payParams keys:', Object.keys(payParams || {}));
|
|
|
|
|
+ console.log('[JSAPI-DEBUG] 返回前端数据:', JSON.stringify({ orderNo, amount, payParams: { ...payParams, paySign: payParams?.paySign?.substring(0, 20) + '...' } }));
|
|
|
|
|
+
|
|
|
ctx.body = {
|
|
ctx.body = {
|
|
|
code: 0, message: '订单创建成功',
|
|
code: 0, message: '订单创建成功',
|
|
|
data: { orderNo, amount, planName: subject, payParams }
|
|
data: { orderNo, amount, planName: subject, payParams }
|
|
@@ -425,6 +444,9 @@ router.post('/wechat/jsapi', authMiddleware, async (ctx: Context) => {
|
|
|
openid
|
|
openid
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
|
|
+ console.log('[JSAPI-DEBUG] ✅ 套餐支付创建成功, payParams keys:', Object.keys(payParams || {}));
|
|
|
|
|
+ console.log('[JSAPI-DEBUG] 返回前端数据:', JSON.stringify({ orderNo, amount, planName: plan.name, payParams: { ...payParams, paySign: payParams?.paySign?.substring(0, 20) + '...' } }));
|
|
|
|
|
+
|
|
|
ctx.body = {
|
|
ctx.body = {
|
|
|
code: 0,
|
|
code: 0,
|
|
|
message: '订单创建成功',
|
|
message: '订单创建成功',
|