Пример #1
0
 /**
  * 查询转运四方在国外的仓库信息
  * @return array
  * @throws 
  */
 public function getWareHouse()
 {
     $baseUrl = parent::getEnvUrl() . Config::get('endpoints.get_ware_house');
     $request = parent::createBaseRequest(parent::getApiKey(), 'POST', $baseUrl);
     $requestSet = new RequestSet();
     $requestSet->Token = parent::getApiKey();
     $requestSet->Data = null;
     $stream = Stream::factory(json_encode($requestSet));
     $request->setBody($stream);
     try {
         $response = parent::getClient()->send($request);
     } catch (ClientException $e) {
         throw parent::convertException($e);
     }
     $body = $response->json();
     $wareHouses = array();
     $res = json_decode(stripcslashes($body['Data']));
     // 这里Data是字符串 需要先反转义
     foreach ($res as $wareHouse) {
         $wareHouses[] = WareHouse::create(ArrayUtil::object_to_array($wareHouse));
     }
     return $wareHouses;
 }
 public function testGetWareHousesFromNet()
 {
     $wareHouses = self::$transRush->wareHouseService->getWareHouse();
     $wareHouse = \TransRush\Components\WareHouse\WareHouse::create(\TransRush\Util\ArrayUtil::object_to_array($wareHouses[0]));
     $this->assertEquals("USLAX", $wareHouse->WareHouseCode);
 }