$params = input('post.');
$ids = implode(',', $params['ids']);
$l1 = dingyi(config('baidu.html'),0);
$l2 = config('baidu.sl');
$html = Db::name('news')->limit($l1,$l2)->select();
if (!empty($html)) {
$html_sz = $l1 + 1;
} else {
$html_sz = 0;
}
foreach ($html as $key => $html) {
$arr[$key] = $html['id'];
}
$urls = array();
for ($i = 0; $i < count($arr); $i++) {
$urls[$i] = config('baidu.http') . '://' . $_SERVER['HTTP_HOST'] . '/xq/' . $arr[$i] . '.html';
}
$api = config('baidu.key');
$ch = curl_init();
$options = array(CURLOPT_URL => $api, CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => implode("\n", $urls), CURLOPT_HTTPHEADER => array('Content-Type: text/plain'));
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
$res = json_decode($result, true);
if ($result==false) {
return json(array('code'=>0,'msg'=>'推送失败请仔细检查配置'));
}
if (isset($res['error'])) {
return json(array('code'=>0,'msg'=>'推送失败:' . $res['message'] . '错误代码' . $res['error'] . ''));
} else {
$path = 'application/extra/baidu.php';
$file = include $path;
$config = array(
'news' => $html_sz,
);
$res = array_merge($file, $config);
$str = '<?php return [';
foreach ($res as $key => $value){
$str .= '\''.$key.'\''.'=>'.'\''.$value.'\''.',';
};
$str .= ']; ';
file_put_contents($path, $str);
return json(array('code'=>200,'msg'=>'成功推送' . $res['success'] . '条,今天还可推送' . $res['remain'] . '条'));
}