test_aliyun_parsing.php 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. require __DIR__.'/vendor/autoload.php';
  3. $app = require_once __DIR__.'/bootstrap/app.php';
  4. $kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
  5. $kernel->bootstrap();
  6. // Simulate the response structure from the log
  7. $body = [
  8. 'Data' => '{"angle":0,"content":[{"word":"测试文本","prob":99}],"height":1052,"width":1052}',
  9. 'message' => null,
  10. 'requestId' => 'test'
  11. ];
  12. echo "Testing Aliyun response parsing...\n";
  13. echo "Body Data field type: " . gettype($body['Data']) . "\n";
  14. echo "Body Data is string: " . (is_string($body['Data']) ? 'yes' : 'no') . "\n";
  15. $data = is_string($body['Data']) ? json_decode($body['Data'], true) : $body['Data'];
  16. echo "Decoded data keys: " . implode(', ', array_keys($data ?? [])) . "\n";
  17. echo "Has content: " . (isset($data['content']) ? 'yes' : 'no') . "\n";
  18. echo "Content count: " . (isset($data['content']) ? count($data['content']) : 0) . "\n";
  19. if (isset($data['content']) && is_array($data['content'])) {
  20. foreach ($data['content'] as $item) {
  21. if (isset($item['word'])) {
  22. echo "Found word: {$item['word']}\n";
  23. }
  24. }
  25. }