private function doBatchRun($useHttps = true)
{
$batchQueue = $this->batchQueue[$useHttps ? 0 : 1];
if (empty($batchQueue)) {
return;
}
$num = count($batchQueue);
$params = array();
foreach ($batchQueue as $item) {
$params[] = $item['i'];
}
$json = json_encode($params);
$serialOnly = $this->batchMode === self::BATCH_MODE_SERIAL_ONLY;
$params = array('method' => $json, 'serial_only' => $serialOnly);
if ($useHttps) {
$params['access_token'] = $this->getAccessToken();
$domain = self::$BD_OPENAPI_DEFAULT_DOMAINS['rest'];
} else {
$params['client_id'] = $this->getClientId();
$domain = self::$BD_OPENAPI_DEFAULT_DOMAINS['public'];
}
$result = BaiduUtils::request($domain . '/batch/run', $params, 'POST');
if ($result === false) {
throw new BaiduException('failed to call batch/run api: ' . BaiduUtils::errmsg(), BaiduUtils::errno());
}
$result = $this->converJson2Array($result);
if (is_array($result) && isset($result['error_code'])) {
throw new BaiduException('failed to call batch/run api: ' . $result['error_msg'], $result['error_code']);
}
for ($i = 0; $i < $num; $i++) {
$item = $batchQueue[$i];
$itemResult = $result[$i];
if (is_array($itemResult) && isset($itemResult['error_code'])) {
throw new BaiduException('failed to call ' . $item['i']['path'] . ' api: ' . $itemResult['error_msg'], $itemResult['error_code']);
}
$item['r'] = $itemResult;
}
}