diff --git a/app/controller/FeishuController.php b/app/controller/FeishuController.php index d2bb32f..b7d7b79 100644 --- a/app/controller/FeishuController.php +++ b/app/controller/FeishuController.php @@ -72,8 +72,14 @@ class FeishuController public function auth(Request $request) { $param = $request->all(); + $userId = $request->user['id']; + $config = User::where('id',$userId)->value('sign'); + if(Util::isEmpty($config)){ + return Util::fail(null,trans('sign_not_null')); + } + // 获取凭证 - $certificate = config($this->config); + $certificate = config('feishu.'.$config); // 飞书服务 $class = new \app\service\FeishuService($certificate['appId'], $certificate['appSecret'], $certificate['state']); @@ -91,10 +97,11 @@ class FeishuController } Log::info('feishu user_info', ['res' => $rst]); - $state = explode(",", $param['state']); + $state = explode("_", $param['state']); //$userId = $request->user['id']; - $userId = $state[2]; + $userId = $state[1]; $user = FeishuUser::where('id', $userId)->first(); + $user = FeishuUser::create(); //保存用户open_id $user->user_id = $userId; @@ -138,7 +145,8 @@ class FeishuController // string(7) "success" // } - return json($rst); +// return json($rst); + return Util::success($rst['data'], trans('success')); } else { //需要登录并且未提供token if (!Util::isEmpty($request->user['id'])) { @@ -161,11 +169,11 @@ class FeishuController * @param $href 详情链接 * @return \support\Response */ - public function send($receiveId,$title,$content,$href) + public static function send($config='xinyouhe',$receiveId='ou_e33bb3017ada6c4781398a68e55a4696',$title='ceshi',$content='测试',$href='http://219.157.255.213:8085/pages/index/mine') { - Log::info('feishu send', ['receiveId' => $receiveId, 'title' => $title, 'content' => $content, 'href' => $href]); // 获取凭证 - $certificate = config($this->config); + $certificate = config('feishu.'.$config); + Log::info('feishu send', [$certificate,'config'=>$config,'receiveId' => $receiveId, 'title' => $title, 'content' => $content, 'href' => $href]); // 飞书服务 $class = new \app\service\FeishuService($certificate['appId'], $certificate['appSecret'], $certificate['state']); @@ -196,7 +204,7 @@ class FeishuController }"; // 卡片 类型 -/* $content = "{ + /*$content = "{ \"config\":{ \"wide_screen_mode\":true }, @@ -225,7 +233,8 @@ class FeishuController } } }";*/ - $msgType = 'interactive'; +// $msgType = 'interactive'; + $msgType = 'post'; //卡片消息:interactive,富文本消息:post $receiveIdtype = 'open_id'; $result = $class->sendMessages($receiveId, $content, $msgType, $receiveIdtype); diff --git a/app/process/Task.php b/app/process/Task.php index 6ee46c1..a8e1432 100644 --- a/app/process/Task.php +++ b/app/process/Task.php @@ -6,6 +6,7 @@ use app\controller\FeishuController; use app\model\Customer; use app\model\FeishuUser; use app\model\User; +use support\Log; use Webman\App; use Workerman\Crontab\Crontab; @@ -15,8 +16,10 @@ class Task public function onWorkerStart() { // 每半小时执行一次 - new Crontab('1/* * * * * *', function () { + new Crontab('*/1 * * * * *', function(){ echo date('Y-m-d H:i:s') . "\n"; + Log::info('send follow start',[time()]); +// FeishuController::send('xinyouhe','ou_e33bb3017ada6c4781398a68e55a4696', '跟进提醒', '您有新的跟进提醒', ''); $customer = Customer::where(['follow_next', '<=', time() + 3600]) ->where(['follow_next', '>', time()]) ->where(['warn', '<', 1]) @@ -34,9 +37,13 @@ class Task $url = $host .$port. '/pages/customer/detile?id='.$customer->id; $item->warn = 1; $item->update(); - FeishuController::class->send($feishuUser->open_id, '跟进提醒', '您有新的跟进提醒', $url); + $user = User::first()->where('id', $item->user_id); + Log::info('send',['open_id'=>$item['open_id'],'url'=>$url]); +// FeishuController::send('xinyouhe','ou_e33bb3017ada6c4781398a68e55a4696', '跟进提醒', '您有新的跟进提醒', $url); + FeishuController::send($user->sign,$feishuUser->open_id, '跟进提醒', '您有新的跟进提醒', $url); } } + Log::info('send follow start',[time()]); }); }