🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# Composer 支持自动加载通过Composer安装的各种插件 ### 安装示例 ~~~ composer require php-amqplib ~~~ ### 代码示例 ~~~ <?php namespace Task; use Ctrl\Controller; use PhpAmqpLib\Connection\AMQPStreamConnection; use PhpAmqpLib\Message\AMQPMessage; Class Task extends Controller { public function WechatSendMqBatch($data) { $queue_name=empty($data['queue_name']) ? 'queue.fanout.message.wechatTemplate':$data['queue_name']; $contents=$data['content']; $connection = new AMQPStreamConnection( '127.0.0.1', 5672, 'user','user'); $channel = $connection->channel(); $channel->queue_declare($queue_name, false, true, false, false); foreach ($contents as $content) { if (is_array($content)) { $content = json_encode($content); } $msg = new AMQPMessage($content); $channel->basic_publish($msg, $queue_name, ""); } //关闭连接 $channel->close(); $connection->close(); } } ?> ~~~