更新队列和推送
This commit is contained in:
parent
e791b3b96e
commit
6679fe8a49
@ -7,7 +7,9 @@ use app\admin\logic\tools\GeneratorLogic;
|
||||
use app\common\service\pay\PayService;
|
||||
use app\common\service\wechat\WeChatOaService;
|
||||
use Webman\Config;
|
||||
use Webman\RedisQueue\Redis;
|
||||
use Yansongda\Pay\Pay;
|
||||
use Webman\Push\Api;
|
||||
|
||||
class IndexController extends BaseApiController
|
||||
{
|
||||
@ -15,24 +17,14 @@ class IndexController extends BaseApiController
|
||||
|
||||
public function index()
|
||||
{
|
||||
Pay::config(Config::get('payment'));
|
||||
$order = [
|
||||
'description' => '测试 - yansongda - 1',
|
||||
'out_trade_no' => time().'',
|
||||
'payer' => [
|
||||
'auth_code' => 'xxxxxxxxxxx'
|
||||
],
|
||||
'amount' => [
|
||||
'total' => 1,
|
||||
],
|
||||
'scene_info' => [
|
||||
'store_info'=>[
|
||||
'id' => '5678'
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
$result = Pay::wechat()->pos($order);
|
||||
$queue = 'send-mail';
|
||||
// 数据,可以直接传数组,无需序列化
|
||||
$data = ['to' => 'tom@gmail.com', 'content' => 'hello'];
|
||||
// 投递消息
|
||||
Redis::send($queue, $data);
|
||||
// 投递延迟消息,消息会在60秒后处理
|
||||
Redis::send($queue, $data, 60);
|
||||
|
||||
return json(['msg' =>create_password(123456, '11d3')]);
|
||||
}
|
||||
|
||||
|
52
app/queue/redis/MyMailSend.php
Normal file
52
app/queue/redis/MyMailSend.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace app\queue\redis;
|
||||
|
||||
use Webman\RedisQueue\Consumer;
|
||||
use Webman\Push\Api;
|
||||
|
||||
class MyMailSend implements Consumer
|
||||
{
|
||||
// 要消费的队列名
|
||||
public $queue = 'send-mail';
|
||||
|
||||
// 连接名,对应 plugin/webman/redis-queue/redis.php 里的连接`
|
||||
public $connection = 'default';
|
||||
|
||||
// 消费
|
||||
public function consume($data)
|
||||
{
|
||||
$api = new Api(
|
||||
'http://127.0.0.1:3232',
|
||||
config('plugin.webman.push.app.app_key'),
|
||||
config('plugin.webman.push.app.app_secret')
|
||||
);
|
||||
// 给订阅 user-1 的所有客户端推送 message 事件的消息
|
||||
$api->trigger('user-1', 'message', [
|
||||
'from_uid' => 2,
|
||||
'content' => '你好,这个是消息内容'
|
||||
]);
|
||||
// 无需反序列化
|
||||
var_export($data); // 输出 ['to' => 'tom@gmail.com', 'content' => 'hello']
|
||||
}
|
||||
// 消费失败回调
|
||||
/*
|
||||
$package = [
|
||||
'id' => 1357277951, // 消息ID
|
||||
'time' => 1709170510, // 消息时间
|
||||
'delay' => 0, // 延迟时间
|
||||
'attempts' => 2, // 消费次数
|
||||
'queue' => 'send-mail', // 队列名
|
||||
'data' => ['to' => 'tom@gmail.com', 'content' => 'hello'], // 消息内容
|
||||
'max_attempts' => 5, // 最大重试次数
|
||||
'error' => '错误信息' // 错误信息
|
||||
]
|
||||
*/
|
||||
public function onConsumeFailure(\Throwable $e, $package)
|
||||
{
|
||||
echo "consume failure\n";
|
||||
echo $e->getMessage() . "\n";
|
||||
// 无需反序列化
|
||||
var_export($package);
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
<?php
|
||||
return [
|
||||
'enable' => true,
|
||||
'websocket' => 'websocket://0.0.0.0:3131',
|
||||
'api' => 'http://0.0.0.0:3232',
|
||||
'websocket' => getenv('PUSH_WEBSOCKET_URL'),
|
||||
'api' => getenv("PUSH_URL"),
|
||||
'app_key' => '2ce3ce22329517213caa7dad261f5695',
|
||||
'app_secret' => 'e77d30638dfc7776e2d41121797bf2b2',
|
||||
'channel_hook' => 'http://127.0.0.1:8787/plugin/webman/push/hook',
|
||||
'channel_hook' => 'http://127.0.0.1:8546/plugin/webman/push/hook',
|
||||
'auth' => '/plugin/webman/push/auth'
|
||||
];
|
@ -1,12 +1,12 @@
|
||||
<?php
|
||||
return [
|
||||
'default' => [
|
||||
'host' => 'redis://127.0.0.1:6379',
|
||||
'host' => 'redis://'.getenv('REDIS_HOST').':6379',
|
||||
'options' => [
|
||||
'auth' => null, // 密码,字符串类型,可选参数
|
||||
'auth' => getenv('REDIS_PASSWORD'), // 密码,字符串类型,可选参数
|
||||
'db' => 0, // 数据库
|
||||
'prefix' => '', // key 前缀
|
||||
'max_attempts' => 5, // 消费失败后,重试次数
|
||||
'prefix' => 'queue:', // key 前缀
|
||||
'max_attempts' => 3, // 消费失败后,重试次数
|
||||
'retry_seconds' => 5, // 重试间隔,单位秒
|
||||
]
|
||||
],
|
||||
|
Loading…
x
Reference in New Issue
Block a user