Example #1
0
 /**
  * 发起请求并返回HaoResult
  * @param  string $urlParam 接口方法
  * @param  array  $params   参数字典
  * @param  string $method   请求方式
  * @return HaoResult        返回结果
  */
 public static function request($urlParam, $params = array(), $method = METHOD_GET)
 {
     $content = static::loadContent($urlParam, $params, $method);
     try {
         $tmpResult = json_decode($content, true);
         if (isset($tmpResult['modelType']) && $tmpResult['modelType'] == 'HaoResult') {
             return HaoResult::instanceModel($tmpResult['results'], $tmpResult['errorCode'], $tmpResult['errorStr'], $tmpResult['extraInfo'], $tmpResult['resultCount']);
         }
     } catch (Exception $e) {
         return HaoResult::instanceModel($content, -1, '数据解析失败,请联系管理员。', null);
     }
     return HaoResult::instanceModel($content, -1, '未解析到正确的数据,请联系管理员。', null);
 }
Example #2
0
 /**
  * 根据path取值,如果不是HaoResult类型,就转成HaoResult类型
  * @param  string $path
  * @return HaoResult
  */
 public function findAsResult($path)
 {
     $value = $this->find($path);
     if (!is_subclass_of($value, 'HaoResult')) {
         $value = HaoResult::instanceModel($value, $this->errorCode, $this->errorStr, $this->extraInfo);
     }
     return $value;
 }