命令行改版
This commit is contained in:
parent
499425df7e
commit
15cf21e512
|
|
@ -18,17 +18,23 @@ php start.php stop
|
|||
echo "启动 webman 服务(后台模式)..."
|
||||
php start.php start -d
|
||||
|
||||
|
||||
cd /rh/p_ysk/scripts || {
|
||||
echo "错误:无法切换到目录 /rh/p_ysk/scripts"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 启动各类 webman 进程(后台运行)
|
||||
echo "启动 applysmstemp 进程..."
|
||||
nohup php webman applysmstemp &
|
||||
nohup php applysmstemp.php &
|
||||
|
||||
echo "启动 birthdaygiftsms 进程..."
|
||||
nohup php webman birthdaygiftsms &
|
||||
nohup php birthdaygiftsms.php &
|
||||
|
||||
echo "启动 rabborderprint 进程..."
|
||||
nohup php webman rabborderprint &
|
||||
nohup php rabborderprint.php &
|
||||
|
||||
echo "启动 rabbproductupdate 进程..."
|
||||
nohup php webman rabbproductupdate &
|
||||
nohup php rabbproductupdate.php &
|
||||
|
||||
echo "所有命令执行完成"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
require_once __DIR__ . '/../support/bootstrap.php';
|
||||
|
||||
|
||||
use PhpAmqpLib\Connection\AMQPStreamConnection;
|
||||
use support\Log;
|
||||
use Webman\RedisQueue\Redis;
|
||||
|
||||
// 申请新短信模版/营销短信发送
|
||||
$host = config('cons.mq.host');
|
||||
$port = config('cons.mq.port');
|
||||
$user = config('cons.mq.user');
|
||||
$password = config('cons.mq.password');
|
||||
$queue = config('cons.mq.queue_t') . '-apply.sms.temp';
|
||||
|
||||
// 防止空闲时间断线必须设置心跳
|
||||
$connection = new AMQPStreamConnection($host, $port, $user, $password,
|
||||
'/',
|
||||
false,
|
||||
'AMQPLAIN',
|
||||
null,
|
||||
'en_US',
|
||||
60,
|
||||
60,
|
||||
null,
|
||||
false,
|
||||
30
|
||||
);
|
||||
$rabbit_channel = $connection->channel();
|
||||
$rabbit_channel->queue_declare($queue, false, true, false, false, false, [
|
||||
// 'x-message-ttl' => ['I', 180000]
|
||||
]);
|
||||
|
||||
$callback = function ($msg) use ($queue){
|
||||
$data = $msg->body;
|
||||
Log::info('MQ收到消息[申请新短信模版/营销短信发送/微信模版消息]--->' . $data . "\n");
|
||||
$arr = explode(',', $data);
|
||||
if(isset($arr[2])) {
|
||||
$type = $arr[2];
|
||||
if($type == 'applySmsTemp') {
|
||||
// 发给队列 短信模版审核
|
||||
$a = Redis::send('apply.sms.temp', $data);
|
||||
Log::info('消息队列投递结果----》' . $a);
|
||||
}elseif ($type == 'sendMarkSms') {
|
||||
// 发给队列 营销短信发送
|
||||
Redis::send('send.mark.sms', $data);
|
||||
}elseif ($type == 'sendWechatTemp') {
|
||||
// 发给队列 发送微信模版消息
|
||||
Redis::send('send.wechat.temp', $data);
|
||||
}
|
||||
}else {
|
||||
Log::info('MQ收到消息[申请新短信模版/营销短信发送/微信模版消息]格式错误');
|
||||
}
|
||||
$msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
|
||||
};
|
||||
$rabbit_channel->basic_consume($queue, '', false, false, false, false, $callback);
|
||||
while ($rabbit_channel->is_consuming()) {
|
||||
$rabbit_channel->wait();
|
||||
}
|
||||
$rabbit_channel->close();
|
||||
$connection->close();
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
require_once __DIR__ . '/../support/bootstrap.php';
|
||||
|
||||
use app\common\model\RabbitMqConfig;
|
||||
use PhpAmqpLib\Connection\AMQPStreamConnection;
|
||||
use support\Log;
|
||||
use Webman\RedisQueue\Redis;
|
||||
|
||||
// 生日有礼
|
||||
|
||||
$host = config('cons.mq.host');
|
||||
$port = config('cons.mq.port');
|
||||
$user = config('cons.mq.user');
|
||||
$password = config('cons.mq.password');
|
||||
$queue = config('cons.mq.queue_t') . '-birthday.gift.sms';
|
||||
|
||||
// 防止空闲时间断线必须设置心跳
|
||||
$connection = new AMQPStreamConnection($host, $port, $user, $password,
|
||||
'/',
|
||||
false,
|
||||
'AMQPLAIN',
|
||||
null,
|
||||
'en_US',
|
||||
60,
|
||||
60,
|
||||
null,
|
||||
false,
|
||||
30
|
||||
);
|
||||
$rabbit_channel = $connection->channel();
|
||||
$rabbit_channel->queue_declare($queue, false, true, false, false, false, [
|
||||
// 'x-message-ttl' => ['I', 180000]
|
||||
]);
|
||||
|
||||
$callback = function ($msg) use ($queue){
|
||||
$date_time = date('Y-m-d H:i:s');
|
||||
$data = $msg->body;
|
||||
Log::info('MQ收到消息[生日有礼]--->' . $data . '--->' . $date_time . "\n");
|
||||
// 发给队列
|
||||
Redis::send('birthday.gift.sms', $data);
|
||||
$msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
|
||||
};
|
||||
$rabbit_channel->basic_consume($queue, '', false, false, false, false, $callback);
|
||||
while ($rabbit_channel->is_consuming()) {
|
||||
$rabbit_channel->wait();
|
||||
}
|
||||
$rabbit_channel->close();
|
||||
$connection->close();
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
require_once __DIR__ . '/../support/bootstrap.php';
|
||||
|
||||
|
||||
|
||||
$host = config('cons.mq.host');
|
||||
$port = config('cons.mq.port');
|
||||
$user = config('cons.mq.user');
|
||||
$password = config('cons.mq.password');
|
||||
$queue = config('cons.mq.queue_t') . '-order.print.queue';
|
||||
|
||||
// 防止空闲时间断线必须设置心跳
|
||||
$connection = new AMQPStreamConnection($host, $port, $user, $password,
|
||||
'/',
|
||||
false,
|
||||
'AMQPLAIN',
|
||||
null,
|
||||
'en_US',
|
||||
60,
|
||||
60,
|
||||
null,
|
||||
false,
|
||||
30
|
||||
);
|
||||
$rabbit_channel = $connection->channel();
|
||||
$rabbit_channel->queue_declare($queue, false, true, false, false, false, [
|
||||
'x-message-ttl' => ['I', 180000]
|
||||
]);
|
||||
|
||||
$callback = function ($msg) use ($queue){
|
||||
$date_time = date('Y-m-d H:i:s');
|
||||
$data = $msg->body;
|
||||
Log::info('MQ收到消息[订单打印]--->' . $data . '--->' . $date_time . "\n");
|
||||
// 如果是数字。则打印订单
|
||||
$is_log = false;
|
||||
$curl_error = '';
|
||||
print_r($data . "\r\n");
|
||||
$order_id_t = strpos($data, '_');
|
||||
print_r($order_id_t . "嘿嘿\r\n");
|
||||
if($order_id_t !== false) {
|
||||
print_r($order_id_t . "\r\n");
|
||||
$order_id = substr($data, 0, $order_id_t);
|
||||
}else {
|
||||
print_r( "无下划线\r\n");
|
||||
$order_id = $data;
|
||||
}
|
||||
print_r($order_id . "\r\n");
|
||||
$order = Db::table('tb_order_info')->where(['id' => $order_id])->find();
|
||||
if($order) {
|
||||
$rand = 'cashier_order' . Random::build();
|
||||
$send_id = 'cashier_'. $order['shop_id'];
|
||||
// 收银机打印订单
|
||||
$snd_data = [
|
||||
'msg' => '收银机订单打印',
|
||||
'type' => 'cashier',
|
||||
'operate_type' => 'order_print',
|
||||
'data_type' => 'order',
|
||||
'status' => 1,
|
||||
'method' => 'sendToUid',
|
||||
'send_num' => 0,
|
||||
'send_id' => $send_id,
|
||||
'msg_id' => $rand,
|
||||
'data' => $data
|
||||
];
|
||||
$snd_data_json = json_encode($snd_data);
|
||||
// 内部给收银机推送打订单
|
||||
$url = 'http://127.0.0.1:8686/?method=sendToUid&account='. $send_id .'¶ms=' . $snd_data_json; // 替换为你的服务地址和端口
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
$output = curl_exec($ch);
|
||||
if (curl_errno($ch)) {
|
||||
$is_log = true;
|
||||
$curl_error = 'Curl error: ' . curl_error($ch);
|
||||
}
|
||||
curl_close($ch);
|
||||
Log::info('内部通讯结果(订单打印)--->' . $output . '通讯ID--->cashier_' .$order['shop_id']. '---' . date('Y-m-d H:i:s') . "\n");
|
||||
}else {
|
||||
$curl_error = 'order Data is empty';
|
||||
$is_log = true;
|
||||
}
|
||||
if($is_log) {
|
||||
Db::table('tb_mq_log')->insert([
|
||||
'queue' => $queue,
|
||||
'msg' => $data,
|
||||
'type' => 'orderPrint',
|
||||
'plat' => 'Cashier',
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
'fail_time' => date('Y-m-d H:i:s'),
|
||||
'err_info' => $curl_error,
|
||||
]);
|
||||
}
|
||||
$msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
|
||||
};
|
||||
$rabbit_channel->basic_consume($queue, '', false, false, false, false, $callback);
|
||||
while ($rabbit_channel->is_consuming()) {
|
||||
$rabbit_channel->wait();
|
||||
}
|
||||
$rabbit_channel->close();
|
||||
$connection->close();
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
require_once __DIR__ . '/../support/bootstrap.php';
|
||||
|
||||
use app\common\model\RabbitMqConfig;
|
||||
use ba\Random;
|
||||
use PhpAmqpLib\Connection\AMQPStreamConnection;
|
||||
use support\think\Db;
|
||||
use support\Log;
|
||||
|
||||
|
||||
$host = config('cons.mq.host');
|
||||
$port = config('cons.mq.port');
|
||||
$user = config('cons.mq.user');
|
||||
$password = config('cons.mq.password');
|
||||
$queue = config('cons.mq.queue_t') . '-product.info.change.queue';
|
||||
// 防止空闲时间断线必须设置心跳
|
||||
$connection = new AMQPStreamConnection($host, $port, $user, $password,
|
||||
'/',
|
||||
false,
|
||||
'AMQPLAIN',
|
||||
null,
|
||||
'en_US',
|
||||
60,
|
||||
60,
|
||||
null,
|
||||
false,
|
||||
30
|
||||
);
|
||||
$rabbit_channel = $connection->channel();
|
||||
$rabbit_channel->queue_declare($queue, false, true, false, false, false, [
|
||||
// 'x-message-ttl' => ['I', 180000]
|
||||
]);
|
||||
|
||||
$callback = function ($msg) use ($queue){
|
||||
$date_time = date('Y-m-d H:i:s');
|
||||
$data = $msg->body;
|
||||
Log::info('MQ收到消息[商品更新]--->' . $data . '--->' . $date_time . "\n");
|
||||
// 如果是数字。则打印订单
|
||||
$is_log = false;
|
||||
$curl_error = '';
|
||||
if(is_numeric($data)) {
|
||||
$rand = 'product_update' . Random::build();
|
||||
$send_id = 'product_update'. $data;
|
||||
$method = 'sendToGroup';
|
||||
$snd_data = [
|
||||
'msg' => '商品更新',
|
||||
'type' => 'product',
|
||||
'operate_type' => 'product_update',
|
||||
'data_type' => 'product_update',
|
||||
'status' => 1,
|
||||
'method' => $method,
|
||||
'send_num' => 0,
|
||||
'send_id' => $send_id,
|
||||
'msg_id' => $rand,
|
||||
'data' => $data
|
||||
];
|
||||
$snd_data_json = json_encode($snd_data);
|
||||
$url = 'http://127.0.0.1:8686/?method=' . $method . '&account='. $send_id .'¶ms=' . $snd_data_json; // 替换为你的服务地址和端口
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
$output = curl_exec($ch);
|
||||
if (curl_errno($ch)) {
|
||||
$is_log = true;
|
||||
$curl_error = 'Curl error: ' . curl_error($ch);
|
||||
}
|
||||
curl_close($ch);
|
||||
Log::info('内部通讯结果(商品更新)--->' . $output . '通讯ID--->shop_id-->' .$send_id. '---' . date('Y-m-d H:i:s') . "\n");
|
||||
if($is_log) {
|
||||
Db::table('tb_mq_log')->insert([
|
||||
'queue' => $queue,
|
||||
'msg' => $data,
|
||||
'type' => 'product_update',
|
||||
'plat' => 'product',
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
'fail_time' => date('Y-m-d H:i:s'),
|
||||
'err_info' => $curl_error,
|
||||
]);
|
||||
}
|
||||
}
|
||||
$msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
|
||||
};
|
||||
$rabbit_channel->basic_consume($queue, '', false, false, false, false, $callback);
|
||||
while ($rabbit_channel->is_consuming()) {
|
||||
$rabbit_channel->wait();
|
||||
}
|
||||
$rabbit_channel->close();
|
||||
$connection->close();
|
||||
48
sd.php
48
sd.php
|
|
@ -1,48 +0,0 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Bunny\Channel;
|
||||
use Bunny\Message;
|
||||
use Workerman\Worker;
|
||||
use Workerman\RabbitMQ\Client;
|
||||
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
$worker = new Worker();
|
||||
$worker->eventLoop = \Workerman\Events\Swoole::class;
|
||||
|
||||
$worker->onWorkerStart = function() {
|
||||
// Create RabbitMQ Client
|
||||
$client = Client::factory([
|
||||
'host' => '127.0.0.1',
|
||||
'port' => 5672,
|
||||
'user' => 'guest',
|
||||
'password' => 'guest',
|
||||
'vhost' => '/',
|
||||
'heartbeat' => 60,
|
||||
'heartbeat_callback' => function () {
|
||||
echo " [-] coroutine-consumer-heartbeat\n";
|
||||
},
|
||||
'interval' => [100, 300]
|
||||
])->connect();
|
||||
$channel = $client->channel();
|
||||
$channel->queueDeclare('hello-coroutine');
|
||||
// Consumer
|
||||
$channel->consume(function (Message $message, Channel $channel, \Bunny\AbstractClient $client) {
|
||||
echo " [>] Received ", $message->content, "\n";
|
||||
},
|
||||
'hello-coroutine',
|
||||
'',
|
||||
false,
|
||||
true
|
||||
);
|
||||
$client->run();
|
||||
echo ' [*] Waiting for messages. To exit press CTRL+C', "\n";
|
||||
// Producer
|
||||
\Workerman\Timer::add($interval = 5 , function () use ($channel) {
|
||||
$channel->publish($message = 'Hello World By Self Timer. ' . time(), [], '', 'hello-coroutine');
|
||||
echo " [<] Sent $message\n";
|
||||
});
|
||||
echo " [!] Producer timer created, interval: $interval s.\n";
|
||||
};
|
||||
Worker::runAll();
|
||||
|
|
@ -6,10 +6,10 @@
|
|||
|
||||
// 定义需要终止的进程关键词(与启动命令对应)
|
||||
$processKeywords = [
|
||||
'webman applysmstemp',
|
||||
'webman birthdaygiftsms',
|
||||
'webman rabborderprint',
|
||||
'webman rabbproductupdate'
|
||||
'applysmstemp.php',
|
||||
'birthdaygiftsms.php',
|
||||
'rabborderprint.php',
|
||||
'rabbproductupdate.php'
|
||||
];
|
||||
|
||||
echo "开始终止 Webman 进程...\n";
|
||||
|
|
|
|||
Loading…
Reference in New Issue