public function handle_request_internal() { $operator = -1; $old_isopen = $this->getParameter('isopen'); $new_isopen = Bll_Broker_ShopSwitcherBll::getShopSwitcherByBrokerId(self::$intBrokerID); $this->setAttribute('brokerId', static::$intBrokerID); $verifyCode = $this->getParameter('verify_code'); $request = APf::get_instance()->get_request(); $cookie = $request->get_cookie('sv'); $response = APF::get_instance()->get_response(); $response->remove_cookie('sv'); $this->setAttribute('clientIp', $request->get_client_ip()); if ($request->is_post_method() && !empty($cookie) && !Bll_Security_Verify::checkVerifyCode($cookie, $verifyCode)) { $this->setAttribute('verifyCodeError', '验证码错误'); $old_isopen = ''; } if (isset($old_isopen) && in_array($old_isopen, array(0, 1)) && $old_isopen != '') { if ($new_isopen == $old_isopen) { $operator = -1; } else { $operator = Bll_Broker_ShopSwitcherBll::updateShopSwitcherByBrokerId(self::$intBrokerID, $old_isopen); if ($operator) { $new_isopen = $old_isopen; } } } $this->setAttribute('operator', $operator); $this->setAttribute('isopen', $new_isopen); return 'Broker_ShopSwitcher'; }
public function handle_request() { $params = APF::get_instance()->get_request()->get_parameters(); $x_size = $params['x']; $y_size = $params['y']; $num_size = $params['s']; //添加字符数量 $font_num = isset($params['n']) ? $params['n'] : 4; $x1 = $params['x1']; $y1 = $params['y1']; $x2 = $params['x2']; $y2 = $params['y2']; $verifyCode = strtolower($this->random($font_num, 1)); $keySuffix = md5($_SERVER['HTTP_USER_AGENT'] . $verifyCode); Bll_Security_Verify::saveVerifyCode($keySuffix, $verifyCode); $response = APF::get_instance()->get_response(); $response->set_content_type('image/png'); $response->set_cookie('sv', $keySuffix, 10 * 60, NULL, NULL, FALSE, TRUE); $response->set_cache_control('private'); $response->set_header('Expires', 'Thu Jun 05 2014 11:41:06 GMT'); $response->set_header('hash', $keySuffix); $response->set_header('Pragma', 'no-cache'); $im = imagecreatetruecolor($x_size, $y_size); $white = imagecolorallocate($im, 255, 255, 255); $grey = imagecolorallocate($im, 128, 128, 128); $black = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, $x_size, $y_size, $white); $font = APF::get_instance()->get_config("FontsUrl"); imagettftext($im, $num_size, 2, $x1, $y1, $grey, $font, $verifyCode); imagettftext($im, $num_size, 2, $x2, $y2, $black, $font, $verifyCode); for ($i = 0; $i < 600; $i++) { $randColor = ImageColorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255)); imagesetpixel($im, rand() % $x_size, rand() % $y_size, $randColor); } imagepng($im); imagedestroy($im); return false; }