easyswoole 官方api關於圖形驗證碼的demo 是這樣的
$config = new Conf();
$code = new \EasySwoole\VerifyCode\VerifyCode($config);
$this->response()->withHeader('Content-Type','image/png');
$this->response()->write($code->DrawCode()->getImageByte());
}
這是生成驗證碼並顯示到前臺,獲取圖片內容的方式是
$code->DrawCode()->getImageCode(); 但是生成的圖片內容和獲取的內容 結果不一樣。試了很多次都不是一樣的。
於是參照網上有個例子改成這樣就可以了:
$config = new Conf(); $code = new \EasySwoole\VerifyCode\VerifyCode($config); $random = Random::character(4, '1234567890abcdefghijklmnopqrstuvwxyz'); $obj = $code->DrawCode($random); $pic = $obj->getImageByte(); Session::getInstance()->set('code',$random); $this->response()->withHeader('Content-Type','image/png'); $this->response()->write($pic);
很是疑惑 我不傳驗證碼自動生成的話 也應該獲取當時生成的驗證碼,不知道爲什麼?有大神知道可以評論留言告知。