|
|
@@ -2,18 +2,14 @@
|
|
|
|
|
|
namespace crmeb\services\async\task;
|
|
|
|
|
|
-use crmeb\utils\Beanstalk;
|
|
|
use crmeb\services\QyWeixinService;
|
|
|
-use think\facade\Config;
|
|
|
use think\facade\Log;
|
|
|
|
|
|
/**
|
|
|
* 异步机器人通知.
|
|
|
- * 消息格式:
|
|
|
- * {"type":"type_name", "key":"1234", "desc":''}
|
|
|
* Class WechatNotify
|
|
|
*/
|
|
|
-class WechatNotify
|
|
|
+class WechatNotify extends Task
|
|
|
{
|
|
|
const CMD = 'wechat';
|
|
|
|
|
|
@@ -28,25 +24,16 @@ class WechatNotify
|
|
|
|
|
|
public static function push(string $type, string $key, string $desc = '')
|
|
|
{
|
|
|
- $bean = Beanstalk::instance();
|
|
|
- $tube = Config::get('app.beanstalk_tube', 'twong');
|
|
|
- $arr = [
|
|
|
- 'cmd' => self::CMD,
|
|
|
- 'ts' => time(),
|
|
|
- 'sender' => '0',
|
|
|
- 'params' => [
|
|
|
- 'type' => $type,
|
|
|
- 'key' => $key,
|
|
|
- 'desc' => $desc,
|
|
|
- ],
|
|
|
- ];
|
|
|
+ self::put([
|
|
|
+ 'type' => $type,
|
|
|
+ 'key' => $key,
|
|
|
+ 'desc' => $desc,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
|
|
|
- $json = json_encode($arr);
|
|
|
- try {
|
|
|
- $bean::useTube($tube)->put($json);
|
|
|
- } catch (\Exception $e) {
|
|
|
- Log::error('push failed: ' . $json);
|
|
|
- }
|
|
|
+ protected static function getCmd()
|
|
|
+ {
|
|
|
+ return self::CMD;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -56,10 +43,10 @@ class WechatNotify
|
|
|
*/
|
|
|
public static function exec(array $task)
|
|
|
{
|
|
|
- if (!$task || !isset($task['cmd']) || $task['cmd'] != self::CMD) {
|
|
|
- Log::error('invalid cmd');
|
|
|
+ if (!self::checkTask($task)) {
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
// must has value
|
|
|
$params = $task['params'];
|
|
|
|