- 目标文件:vendor\yiisoft\yii2\captcha\CaptchaAction.php
- 在$this->getVerifyCode()方法调用时,传入参数true
/**
* Runs the action.
*/
public function run()
{
if (Yii::$app->request->getQueryParam(self::REFRESH_GET_VAR) !== null) {
// AJAX request for regenerating code
$code = $this->getVerifyCode(true);
Yii::$app->response->format = Response::FORMAT_JSON;
return [
'hash1' => $this->generateValidationHash($code),
'hash2' => $this->generateValidationHash(strtolower($code)),
// we add a random 'v' parameter so that FireFox can refresh the image
// when src attribute of image tag is changed
'url' => Url::to([$this->id, 'v' => uniqid()]),
];
} else {
$this->setHttpHeaders();
Yii::$app->response->format = Response::FORMAT_RAW;
#修改此处,在$this->getVerifyCode()方法调用时,传入参数true
return $this->renderImage($this->getVerifyCode(true));
}
}