| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- // 最终测试
- async function testFinal() {
- console.log('=== 最终测试修复后的支付成功触发API ===\n');
- const apiUrl = 'http://localhost:8080/api/v1/payments/payment/trigger-success';
- // 获取新的token
- const loginResponse = await fetch('http://localhost:8080/api/v1/auth/login', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify({
- username: 'admin',
- password: 'admin123'
- })
- });
- if (!loginResponse.ok) {
- console.error('登录失败');
- return;
- }
- const loginData = await loginResponse.json();
- const token = loginData.token;
- console.log(`API地址: ${apiUrl}`);
- console.log(`测试订单ID: 25`);
- console.log(`Token: ${token.substring(0, 50)}...\n`);
- try {
- const response = await fetch(apiUrl, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': `Bearer ${token}`
- },
- body: JSON.stringify({
- orderId: 25
- })
- });
- console.log(`状态码: ${response.status}`);
- console.log(`状态文本: ${response.statusText}`);
- if (response.ok) {
- const result = await response.json();
- console.log('\n✅ API调用成功!');
- console.log('响应内容:', JSON.stringify(result, null, 2));
- // 等待一会儿让后台处理
- console.log('\n等待5秒让后台处理打印任务...');
- await new Promise(resolve => setTimeout(resolve, 5000));
- // 检查数据库
- console.log('\n检查数据库中的打印任务...');
- const { exec } = require('child_process');
- const util = require('util');
- const execPromise = util.promisify(exec);
- try {
- const { stdout } = await execPromise(
- 'psql -h 127.0.0.1 -U postgres -d postgres -c "SELECT id, tenant_id, task_id, order_id, print_status, scheduled_at, created_at FROM feie_print_task_mt WHERE order_id = 25 ORDER BY created_at DESC"'
- );
- console.log('查询结果:');
- console.log(stdout);
- if (stdout.includes('(0 rows)')) {
- console.log('\n❌ 数据库中仍然没有找到订单ID 25的打印任务');
- // 检查服务器日志
- console.log('\n检查最新的打印任务...');
- const { stdout: latestTasks } = await execPromise(
- 'psql -h 127.0.0.1 -U postgres -d postgres -c "SELECT id, tenant_id, task_id, order_id, print_status, scheduled_at, created_at FROM feie_print_task_mt ORDER BY created_at DESC LIMIT 5"'
- );
- console.log('最新的5个打印任务:');
- console.log(latestTasks);
- } else {
- console.log('\n🎉 成功!打印任务已创建!');
- // 检查任务详情
- console.log('\n检查任务详情...');
- const { stdout: taskDetails } = await execPromise(
- 'psql -h 127.0.0.1 -U postgres -d postgres -c "SELECT task_id, printer_sn, print_type, print_status, retry_count, max_retries, scheduled_at, error_message FROM feie_print_task_mt WHERE order_id = 25 ORDER BY created_at DESC LIMIT 1"'
- );
- console.log('任务详情:');
- console.log(taskDetails);
- }
- } catch (dbError) {
- console.error('查询数据库失败:', dbError.message);
- }
- } else {
- const errorText = await response.text();
- console.log('\n❌ API调用失败');
- console.log('错误响应:', errorText);
- }
- } catch (error) {
- console.error('请求失败:', error.message);
- console.error('错误堆栈:', error.stack);
- }
- }
- // 运行测试
- testFinal().catch(error => {
- console.error('测试脚本执行失败:', error);
- process.exit(1);
- });
|