예제 #1
0
 /**
  * @override
  */
 public function request($params = array())
 {
     $response = parent::request($params);
     // 对于由于经纪人账户未创建导致的获取经纪人账户余额错误,决定默认返回成功的结果
     if ($response->isSucceeded() && $response['status'] == 'error' && $response['code'] == '503198') {
         $newResponse = new Bll_Service_Client_HttpResponse();
         $newResponse->setTransferInfo($response->getTransferInfo());
         $newResponse->succeed();
         $newResponse->setResponse(array('status' => 'ok', 'data' => array('balance' => 0, 'frozen' => 0, 'personBalance' => 0, 'companyBalance' => 0, 'jp' => array('id' => 0, 'balance' => 0, 'frozen' => 0), 'hz' => array('id' => 0, 'balance' => 0, 'frozen' => 0), 'ajk' => array('id' => 0, 'balance' => 0, 'frozen' => 0))));
         $response = $newResponse;
     }
     return $response;
 }
예제 #2
0
 /**
  * 发起请求
  *
  * @param $params
  *
  * @return Bll_Service_Client_HttpResponse
  *
  * @throws Exception
  */
 public function request($params)
 {
     $curl = $this->getCurl();
     $url = $this->getUrl();
     $method = $this->getMethod();
     if (!in_array($method, array('GET', 'POST'))) {
         throw new Exception('非法的HTTP请求,当前支持:GET、POST');
     }
     $response = $curl->request($url, $method, $params);
     $transferInfo = $this->getCurl()->getTransferInfo();
     $httpResponse = new Bll_Service_Client_HttpResponse();
     $httpResponse->setTransferInfo($transferInfo);
     if ($response === false) {
         $httpResponse->fail();
     } else {
         $response = json_decode($response, true);
         /** JSON 解析失败 则保存请求信息 */
         if (!$response && defined('APP_NAME') && APP_NAME == 'jobs') {
             $time = date('Y-m-d H:i:s');
             $logMsg = array(sprintf('[%s] url:%s method:%s params:%s', $time, $url, $method, http_build_query($params)), sprintf('[%s] header:%s ', $time, json_encode($transferInfo)), sprintf('[%s] response:%s ', $time, $response));
             $this->saveErrorMsg(implode(PHP_EOL, $logMsg));
         }
         $httpResponse->setResponse($response);
         if ($transferInfo['http_code'] == 200) {
             $httpResponse->succeed();
         } else {
             if (defined('APP_NAME') && APP_NAME == 'jobs') {
                 $time = date('Y-m-d H:i:s');
                 $logMsg = array(sprintf('[%s] url:%s method:%s params:%s', $time, $url, $method, http_build_query($params)), sprintf('[%s] header:%s ', $time, json_encode($transferInfo)));
                 $this->saveErrorMsg(implode(PHP_EOL, $logMsg));
             }
             $httpResponse->fail();
         }
     }
     return $httpResponse;
 }