0

我正在尝试使用微型 URL API 缩短某些 URL,因为我正在尝试限制在 SMS 中发送的字符数。通常,我这样做:

$sms_url = file_get_contents('http://tinyurl . com/api-create.php?url=http://127.0.0.1:8000/billing/export/view/1/0');

它在我的 Listener 中不起作用,所以我在控制器中进行了测试,它起作用了。我将其更改为在侦听器中使用 GuzzleHttp:

$sms_url = Http::get('http://tinyurl . com/api-create.php?url=http://127.0.0.1:8000/billing/export/view/'.$fixed_data->account_number_id.'/'.$fixed_data->subaccount_number_id);

我在侦听器文件上方调用了以下内容:

use Illuminate\Support\Facades\Http;

我运行我的代码,但它不工作。没有错误。只是空白。我的问题可能是什么?

更新:

我的日志文件中的错误:

[2020-08-09 17:02:32] local.ERROR: SQLSTATE[HY000]: General error: 1364 Field 'sms_url' doesn't have a default value (SQL: insert into `pdf` (`account_number_id`, `created_at`, `created_by`, `name`, `path`, `subaccount_number_id`, `updated_by`) values (4, 2020-08-09 17:02:32, 1229, MDAwNDAyMDIwMDgwOUFWdXQ3, storage/uploads/pdf/MDAwNDAyMDIwMDgwOUFWdXQ3.pdf, 0, 1229)) {"exception":"[object] (Illuminate\\Database\\QueryException(code: HY000): SQLSTATE[HY000]: General error: 1364 Field 'sms_url' doesn't have a default value (SQL: insert into `pdf` (`account_number_id`, `created_at`, `created_by`, `name`, `path`, `subaccount_number_id`, `updated_by`) values (4, 2020-08-09 17:02:32, 1229, MDAwNDAyMDIwMDgwOUFWdXQ3, storage/uploads/pdf/MDAwNDAyMDIwMDgwOUFWdXQ3.pdf, 0, 1229)) at /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Database/Connection.php:671)
[stacktrace]
#0 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Database/Connection.php(631): Illuminate\\Database\\Connection->runQueryCallback('insert into `pd...', Array, Object(Closure))
#1 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Database/Connection.php(465): Illuminate\\Database\\Connection->run('insert into `pd...', Array, Object(Closure))
#2 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Database/Connection.php(417): Illuminate\\Database\\Connection->statement('insert into `pd...', Array)
#3 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2785): Illuminate\\Database\\Connection->insert('insert into `pd...', Array)
#4 /Applications/Work/celeb/app/Listeners/ExportAllListener.php(112): Illuminate\\Database\\Query\\Builder->insert(Array)
#5 [internal function]: App\\Listeners\\ExportAllListener->handle(Object(App\\Events\\ExportAllEvent))
#6 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Events/CallQueuedListener.php(93): call_user_func_array(Array, Array)
#7 [internal function]: Illuminate\\Events\\CallQueuedListener->handle(Object(Illuminate\\Foundation\\Application))
#8 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): call_user_func_array(Array, Array)
#9 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Container/Util.php(37): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#10 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(95): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure))
#11 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(39): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#12 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Container/Container.php(596): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#13 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(94): Illuminate\\Container\\Container->call(Array)
#14 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\\Bus\\Dispatcher->Illuminate\\Bus\\{closure}(Object(Illuminate\\Events\\CallQueuedListener))
#15 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Events\\CallQueuedListener))
#16 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(98): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#17 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(83): Illuminate\\Bus\\Dispatcher->dispatchNow(Object(Illuminate\\Events\\CallQueuedListener), false)
#18 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\\Queue\\CallQueuedHandler->Illuminate\\Queue\\{closure}(Object(Illuminate\\Events\\CallQueuedListener))
#19 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Events\\CallQueuedListener))
#20 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(85): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#21 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(59): Illuminate\\Queue\\CallQueuedHandler->dispatchThroughMiddleware(Object(Illuminate\\Queue\\Jobs\\DatabaseJob), Object(Illuminate\\Events\\CallQueuedListener))
#22 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(98): Illuminate\\Queue\\CallQueuedHandler->call(Object(Illuminate\\Queue\\Jobs\\DatabaseJob), Array)
#23 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(356): Illuminate\\Queue\\Jobs\\Job->fire()
#24 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(306): Illuminate\\Queue\\Worker->process('database', Object(Illuminate\\Queue\\Jobs\\DatabaseJob), Object(Illuminate\\Queue\\WorkerOptions))
#25 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(132): Illuminate\\Queue\\Worker->runJob(Object(Illuminate\\Queue\\Jobs\\DatabaseJob), 'database', Object(Illuminate\\Queue\\WorkerOptions))
#26 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(112): Illuminate\\Queue\\Worker->daemon('database', 'default', Object(Illuminate\\Queue\\WorkerOptions))
#27 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(96): Illuminate\\Queue\\Console\\WorkCommand->runWorker('database', 'default')
#28 [internal function]: Illuminate\\Queue\\Console\\WorkCommand->handle()
#29 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): call_user_func_array(Array, Array)
#30 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Container/Util.php(37): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#31 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(95): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure))
#32 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(39): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#33 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Container/Container.php(596): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#34 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Console/Command.php(134): Illuminate\\Container\\Container->call(Array)
#35 /Applications/Work/celeb/vendor/symfony/console/Command/Command.php(258): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#36 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#37 /Applications/Work/celeb/vendor/symfony/console/Application.php(911): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#38 /Applications/Work/celeb/vendor/symfony/console/Application.php(264): Symfony\\Component\\Console\\Application->doRunCommand(Object(Illuminate\\Queue\\Console\\WorkCommand), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#39 /Applications/Work/celeb/vendor/symfony/console/Application.php(140): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#40 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Console/Application.php(93): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#41 /Applications/Work/celeb/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#42 /Applications/Work/celeb/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#43 {main}

根据我的理解,发生错误是因为它$sms_url是空白的。file_get_contents()和没有具体错误Http::get()

4

1 回答 1

0

file_get_contents()在侦听器中完美运行。我在我的实时服务器中添加并看到它工作。古驰也是。我添加了 Http Facade 并使用了Http::post()

于 2020-08-11T18:32:45.083 回答