/** * @param array $find * @param callable $cb */ public function newToken($cb, $add = []) { $this->captcha->insertOne(['_id' => $id = new \MongoId(), 'rnd' => $rnd = \PHPDaemon\Utils\Crypt::randomString(8), 'text' => $text = \WakePHP\Utils\CaptchaDraw::getRandomText(), 'ctime' => time()] + $add, function ($lastError) use($id, $rnd, $cb, $text) { if (!$lastError['ok']) { call_user_func($cb, false); return; } $token = base64_encode($id . "" . $rnd); $this->appInstance->JobManager->enqueue(function ($result) use($token, $text, $cb) { if (!$result) { call_user_func($cb, false); return; } Daemon::log(Debug::dump([[$result]])); call_user_func($cb, $token); }, 'GenerateCaptchaImage', [$token, $text]); }); }