|
|
@@ -9,8 +9,7 @@ import { ErrorSchema } from '../../utils/errorHandler';
|
|
|
const PaymentCreateSchema = z.object({
|
|
|
orderId: z.number().int().positive().describe('订单ID'),
|
|
|
totalAmount: z.number().int().positive().describe('支付金额(分)'),
|
|
|
- description: z.string().min(1).max(128).describe('支付描述'),
|
|
|
- openid: z.string().optional().describe('用户OpenID')
|
|
|
+ description: z.string().min(1).max(128).describe('支付描述')
|
|
|
});
|
|
|
|
|
|
// 支付创建响应Schema
|
|
|
@@ -106,12 +105,20 @@ const app = new OpenAPIHono<AuthContext>()
|
|
|
// 创建支付服务实例
|
|
|
const paymentService = new PaymentService();
|
|
|
|
|
|
- // 创建支付订单
|
|
|
+ // 检查用户是否有openid(小程序用户必需)
|
|
|
+ if (!user.openid) {
|
|
|
+ return c.json({
|
|
|
+ code: 400,
|
|
|
+ message: '用户未绑定微信小程序,无法进行支付'
|
|
|
+ }, 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建支付订单,从认证用户中获取openid
|
|
|
const paymentResult = await paymentService.createPayment(
|
|
|
paymentData.orderId,
|
|
|
paymentData.totalAmount,
|
|
|
paymentData.description,
|
|
|
- paymentData.openid
|
|
|
+ user.openid
|
|
|
);
|
|
|
|
|
|
return c.json(paymentResult, 200);
|