From 2a37cec9055dc8177b01e3f0b734238d23424394 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Thu, 28 Nov 2013 02:30:13 +0000 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=B8=89=E6=B1=9F=E6=BA=90?= =?UTF-8?q?=E5=AD=90=E5=B9=B3=E5=8F=B0=E4=B8=AD=E7=9A=84curl=E5=92=8Caccou?= =?UTF-8?q?ntcontroller=E4=B8=AD=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/controllers/AccountController.php | 94 +++++-------------- application/module/Helpers/Curl.php | 31 +++++- 2 files changed, 52 insertions(+), 73 deletions(-) diff --git a/application/default/controllers/AccountController.php b/application/default/controllers/AccountController.php index 40dd9b20..96959bfd 100755 --- a/application/default/controllers/AccountController.php +++ b/application/default/controllers/AccountController.php @@ -1,4 +1,8 @@ view->href = $tohref; } - $captcha = $this->loadCaptcha(); - - $submit = $this->_getParam("submit"); - if(!empty($submit)) + //登录表单提交 + + if(!$submit) { - $username = trim($this->_request->getParam('username')); - $password = trim($this->_request->getParam('password')); - $captchaword = trim($this->_request->getParam('captcha')); - - if(empty($username)) - { - $this->setCaptcha($captcha); - $this->view->error = "请输入用户名"; - return true; - } - - if(empty($password)) - { - $this->setCaptcha($captcha); - $this->view->error = "请输入密码"; - return true; - } - - if(empty($captchaword)) - { - $this->setCaptcha($captchaword); - $this->view->error = "请输入验证码"; - return true; - } - - if(!isset($_SESSION['captcha'])) - { - $_SESSION['captcha'] = md5(time()); - } - - if ($captchaword != $_SESSION['captcha']) { - $this->setCaptcha($captcha); - $this->view->error = "验证码错误"; - return true; - } - - if (!$this->login($username,$password)) - { - $this->setCaptcha($captcha); - $this->view->error = "用户名或密码错误"; - $this->view->userid = $username; - return true; - } - else - { - if(!empty($tohref)) - { - view::Post($this,"登录成功,正在跳转",$tohref); - return true; - } - - if($options['module']=="default" && $options['controller'] == "account" && $options['action'] == "login") - { - view::Post($this,"登录成功,正在跳转",'/'); - return true; - }else{ - view::Post($this,"登录成功,正在跳转",$_SERVER['REQUEST_URI']); - return true; - } - } - }else{ - $this->setCaptcha($captcha); + return false; } + $param = array( + 'username' => '', + 'password' => '' + ); + + $curl = new Curl(); + $curl->port = 80; + $curl->initOptions(array('verifyssl'=>false)); + $curl->H = array( + 'X-Requested-With: XMLHttpRequest' + ); + $data = $curl->request($main_url,$param,"POST"); + + $cache_data = json_decode($data['response'],true); + + view::Dump($cache_data,false); + return true; } function loadCaptcha() diff --git a/application/module/Helpers/Curl.php b/application/module/Helpers/Curl.php index bc819575..f801e43d 100644 --- a/application/module/Helpers/Curl.php +++ b/application/module/Helpers/Curl.php @@ -4,19 +4,25 @@ namespace Helpers; class Curl { private $options; - + public $port = 80; + public $H; + public function __construct($options = array()) { - $this->options = array_merge(array( + + } + + public function initOptions($options = array()) + { + $this->options = array_merge(array( 'debug' => false, - 'http_port' => '80', + 'http_port' => $this->port, 'user_agent' => 'Westdc DataService', 'timeout' => 20, 'curlopts' => null, 'verifyssl' => true, ), $options); - } - + } /** * Send a request to the server, receive a response * @@ -69,6 +75,11 @@ class Curl } else { $headers[] = 'Content-Length: 0'; } + + if(!empty($this->H) && is_array($this->H) && count($this->H) > 0) + { + $headers = array_merge($headers,$this->H); + } $this->debug('send '.$httpMethod.' request: '.$url); @@ -81,6 +92,16 @@ class Curl CURLOPT_HTTPHEADER => $headers, CURLOPT_SSL_VERIFYPEER => $options['verifyssl'], ); + + if($this->port === 443) + { + /*$curlOptions += array( + CURLOPT_SSLVERSION => 3, + CURLOPT_SSLCERT => "../application/module/Open/apache.pem", + CURLOPT_SSLKEY => "../application/module/Open/apache.key", + CURLOPT_CAINFO => "../application/module/Open/apache.pem" + );*/ + } if (ini_get('open_basedir') == '' && ini_get('safe_mode') != 'On') { $curlOptions[CURLOPT_FOLLOWLOCATION] = true;