46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Controller;
|
|
|
|
use App\Amqp\Producer\DemoProducer;
|
|
use Hyperf\Amqp\Producer;
|
|
use Hyperf\Utils\ApplicationContext;
|
|
|
|
class MainController extends AbstractController
|
|
{
|
|
/**
|
|
* index
|
|
* @return array
|
|
*/
|
|
public function index() : array
|
|
{
|
|
$name = $this->request->input('name', 'Hyperf');
|
|
$num = $this->request->input('num', 'test12345');
|
|
$door = $this->request->input('door', '办公室');
|
|
|
|
$data = [
|
|
'code' => 200,
|
|
'data' => [
|
|
'userOutName' => $name,
|
|
'userOutNum' => $num,
|
|
'recordOutTime' => date('Y-m-d H:i:s'),
|
|
'doorOutName' => $door
|
|
]
|
|
];
|
|
$data = json_encode($data);
|
|
// 组装队列消息
|
|
$message = new DemoProducer($data);
|
|
// 通过容器获取队列生产者实例
|
|
$producer = ApplicationContext::getContainer()->get(Producer::class);
|
|
// 生产消息
|
|
$result = $producer->produce($message);
|
|
var_dump($result);
|
|
|
|
return [
|
|
'code' => 200,
|
|
'msg' => "Push success!",
|
|
];
|
|
}
|
|
}
|