info(" [*] Waiting for {$queue}. To exit press CTRL+C"); Mq::worker($exchange,$queue,function ($message){ /**生成消息内容 */ $msgTitle = '修改建议'; $username = $message->editor->nickName; $palitext = PaliSentence::where('book',$message->book) ->where('paragraph',$message->paragraph) ->where('word_begin',$message->word_start) ->where('word_end',$message->word_end) ->value('text'); $prtext = mb_substr($message->content,0,140,"UTF-8"); $sent_num = "{$message->book}-{$message->paragraph}-{$message->word_start}-{$message->word_end}"; $link = env('APP_URL')."/pcd/article/para/{$message->book}-{$message->paragraph}"; $link .= "?book={$message->book}&par={$message->paragraph}&channel={$message->channel->id}"; $msgContent = "{$username} 就文句`{$palitext}`提出了修改建议:\n"; $msgContent .= ">内容摘要:{$prtext},\n"; $msgContent .= ">句子编号:{$sent_num}\n"; $msgContent .= "欢迎大家[点击链接]({$link})查看并讨论。"; $webhooks = WebHook::where('res_id',$message->channel->id) ->where('status','active') ->get(); $result=0; foreach ($webhooks as $key => $hook) { $event = json_decode($hook->event); if(!in_array('pr',$event)){ continue; } $command = ''; $whSend = new WebHookSend; switch ($hook->receiver) { case 'dingtalk': $ok = $whSend->dingtalk($hook->url,$msgTitle,$msgContent); break; case 'wechat': $ok = $whSend->wechat($hook->url,null,$msgContent); break; default: $ok=2; break; } $this->info("{$command} ok={$ok}"); $result+=$ok; if($ok===0){ WebHook::where('id',$hook->id)->increment('success'); }else{ WebHook::where('id',$hook->id)->increment('fail'); } } return $result; }); return 0; } }