Esempio n. 1
0
	public function start() {
		if(empty($this->token)) {
			exit('Access Denied');
		}
		if(!WeUtility::checkSign($this->token)) {;
			exit('Access Denied');
		}
		if(strtolower($_SERVER['REQUEST_METHOD']) == 'get') {
			exit($_GET['echostr']);
		}
		if(strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
			$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
			$this->message = WeUtility::parse($postStr);
			if (empty($this->message)) {
				WeUtility::logging('waring', 'Request Failed');
				exit('Request Failed');
			}
			WeUtility::logging('trace', $this->message);
			$this->before();
			$this->response = $this->matcher();
			$this->response['content'] = $this->process();
			if(empty($this->response['content']) || ($this->response['content']['type'] == 'text' && empty($this->response['content']['content'])) || ($this->response['content']['type'] == 'news' && empty($this->response['content']['items']))) {
				$this->response['module'] = 'default';
				$this->response['content'] = $this->process();
			}
			$this->after();
			WeUtility::logging('response', $this->response);
			exit(WeUtility::response($this->response['content']));
		}
		WeUtility::logging('waring', 'Request Failed');
		exit('Request Failed');
	}
Esempio n. 2
0
 public function start()
 {
     global $_W;
     if (empty($this->token)) {
         exit('Access Denied');
     }
     if (!WeUtility::checkSign($this->token)) {
         exit('Access Denied');
     }
     if (strtolower($_SERVER['REQUEST_METHOD']) == 'get') {
         ob_clean();
         ob_start();
         exit($_GET['echostr']);
     }
     if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
         $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
         $this->message = WeUtility::parse($postStr);
         if (empty($this->message)) {
             WeUtility::logging('waring', 'Request Failed');
             exit('Request Failed');
         }
         $sessionid = md5($this->message['from'] . $this->message['to'] . $_W['weid']);
         session_id($sessionid);
         WeSession::$weid = $_W['weid'];
         WeSession::$from = $this->message['from'];
         WeSession::$expire = 3600;
         WeSession::start();
         WeUtility::logging('trace', $this->message);
         $pars = $this->matcher();
         $pars[] = array('module' => 'default', 'rule' => '-1');
         foreach ($pars as $par) {
             if (empty($par['module'])) {
                 continue;
             }
             $this->params = $par;
             $this->response = $this->process();
             if (is_array($this->response) && ($this->response['type'] == 'text' && !empty($this->response['content']) || $this->response['type'] == 'news' && !empty($this->response['items']) || !in_array($this->type, array('text', 'news')))) {
                 if (!empty($par['keyword'])) {
                     $this->keyword = $par['keyword'];
                 }
                 break;
             }
         }
         WeUtility::logging('params', $this->params);
         WeUtility::logging('response', $this->response);
         $resp = WeUtility::response($this->response);
         $mapping = array('[from]' => $this->message['from'], '[to]' => $this->message['to'], '[rule]' => $this->params['rule']);
         echo str_replace(array_keys($mapping), array_values($mapping), $resp);
         $subscribes = array();
         foreach ($_W['account']['modules'] as $m) {
             if (in_array($m['name'], $this->modules) && is_array($m['subscribes']) && !empty($m['subscribes'])) {
                 $subscribes[] = $m;
             }
         }
         if (!empty($subscribes)) {
             $this->subscribe($subscribes);
         }
         exit;
     }
     WeUtility::logging('waring', 'Request Failed');
     exit('Request Failed');
 }