Пример #1
0
 public function handle_request()
 {
     $this->_apf = APF::get_instance();
     $this->_request = $this->_apf->get_request();
     $this->_params = $this->_request->get_parameters();
     $request_body = file_get_contents('php://input');
     if ($request_body) {
         $res = json_decode($request_body, true);
         if (is_array($res)) {
             foreach ($res as $k => $v) {
                 $_REQUEST[$k] = $v;
             }
         }
     }
     $this->_params = array_merge($this->_params, $_REQUEST);
     $router_matches = $this->_request->get_router_matches();
     try {
         // 验证参数
         if (isset($this->paramRules)) {
             $validator = new Util_Validator($this->_params, $this->paramRules);
             if ($validator->fails()) {
                 throw new Exception_General_InvalidParameters(json_encode($validator->messages()));
             }
         }
         // 通过缓存去获取数据
         if (self::$_totalCacheOnOff && $this->_isCache && $this->setCacheKey()) {
             // 获取数据
             $mem = APF_Cache_Factory::get_instance()->get_memcache();
             if ($this->_params['rmCache']) {
                 // 是否清除缓存
                 $mem->delete($this->_cacheKey);
                 // 删除缓存
             }
             $ret = $mem->get($this->_cacheKey);
             if (!$ret) {
                 $ret = $this->handle_request_internal();
                 if ($ret['status'] == Const_APIStatus::RETURN_CODE_OK) {
                     $mem->set($this->_cacheKey, $ret, $this->_isCacheZip, $this->_cacheTime);
                 }
             }
         } else {
             $ret = $this->handle_request_internal();
         }
         // 生成用户友好的错误消息
         if ($ret['status'] == Const_APIStatus::RETURN_CODE_ERROR) {
             $apiError = new Api_Error($ret['message'], $ret['errcode']);
             if ($this->isDebugMode()) {
                 $apiError->enableDebugMode();
             }
             $ret = $apiError->toArray();
         }
     } catch (Exception $e) {
         $apiError = new Api_Error($e);
         if ($this->isDebugMode()) {
             $apiError->enableDebugMode();
         }
         $ret = $apiError->toArray();
     }
     $this->output($ret);
 }
Пример #2
0
 /**
  * 抢客户维护模式
  *
  * @return bool
  */
 public static function isMaintenanceMode()
 {
     $enable = false;
     $maintenance = array('enable' => (bool) APF::get_instance()->get_config('maintenance_enable', 'customer_rush', false), 'startTime' => APF::get_instance()->get_config('maintenance_start_time', 'customer_rush'), 'endTime' => APF::get_instance()->get_config('maintenance_end_time', 'customer_rush'));
     $rules = array('enable' => 'required', 'startTime' => 'optional|date_format:Y-m-d H:i:s', 'endTime' => 'optional|date_format:Y-m-d H:i:s');
     $validator = new Util_Validator($maintenance, $rules);
     if ($validator->passes()) {
         $current = time();
         $enable = $maintenance['enable'] && $current > strtotime($maintenance['startTime']) && $current < strtotime($maintenance['endTime']);
     }
     return $enable;
 }
Пример #3
0
 /**
  * @param array $params
  * @return Bll_Service_Client_HttpResponse
  * @throws Bll_Service_Exception
  */
 public function request($params = array())
 {
     // 准备参数
     if (empty($params)) {
         $params = $this->getParams();
     }
     $params = $this->prepareParams($params);
     // 验证参数
     $validator = new Util_Validator($params, $this->rules);
     if ($validator->fails()) {
         throw new Bll_Service_Exception('参数不合法:' . print_r($validator->errors(), true));
     }
     // 实例化客户端
     $httpClient = new Bll_Service_Client_Http($this->getOptions());
     // TODO request log
     // 发起请求
     $response = $httpClient->request($params);
     if ($response->isSucceeded()) {
         // TODO success log
     } else {
         // TODO error log
     }
     return $response;
 }
Пример #4
0
 public function assertEmail($email)
 {
     $this->assertNotEmpty($email, '邮箱不能为空');
     $this->assertTrue(Util_Validator::ValidateEmail($email), "邮箱格式不正确");
 }
Пример #5
0
 public static function ParseString($keywords, $default = '')
 {
     if (!$keywords) {
         return $default;
     }
     $field = '';
     if (Util_Validator::checkIdCard($keywords)) {
         // 身份证
         $field = 'id_card';
     } elseif (Util_Validator::ValidateMobile($keywords)) {
         $field = 'phone';
     } elseif (Util_Validator::ValidateEmail($keywords)) {
         $field = 'email';
     } elseif (is_numeric($keywords)) {
         $field = 'id';
     } else {
         $field = $default;
     }
     return $field;
 }