/** * 评论回调 * * @param Request $request * @return Response */ public function comment(Request $request) { // 验证签名 if (!$this->ds->checkSignature($request::all())) { return $this->output('Check signature faild.', true); } // 拉取最近一条日志 $lastLogId = Comment::getLastLogId(); $list = $this->ds->getLogList($lastLogId, 50); if (empty($list['response'])) { return $this->output('Empty response.', true); } // 遍历日志 foreach ($list['response'] as $log) { // 识别指令 $signs = Comment::ACTION['CREATE'] === $log['action'] ? Comment::recognizeCommands($log['meta']['message']) : []; // 记录日志 $id = Comment::import($log, $signs); // 通知 if (!empty($signs)) { // 回复评论 /* Comment::replyPost( '嗨,稍等一下哦~', $log['meta']['thread_id'], $log['meta']['post_id'], $log['meta']['author_email'] ); */ // 发送邮件 $log = $log + ['id' => $id]; $this->sendMail($log); } } $this->output('Success.', true); }
/** * 回复评论 * * @param string $message * @param string $threadId * @param string $postId * @param string $authorEmail * @return bool */ public static function replyPost($message, $threadId, $postId, $authorEmail = null) { $config = Config::get('duoshuo'); if ($config['user_email'] !== $authorEmail) { $service = new DuoshuoService($config['short_name'], $config['secret']); return $service->createPost($message, $threadId, $postId, $config['user_name'], $config['user_email'], $config['user_url']); } else { return true; } }