zblog百度小程序搜索组件批量提交文章代码
时间:2023年09月25日
/来源:网络
/编辑:佚名
本方案为计划任务解决方案。
1、在文章表新建一个字段,如log_ytecn_bdsp,设置默认值为0。
2、在根目录创建一个文件,比如baidusearchpost.php,
点击复制代码 PHP
<?php
require 'zb_system/function/c_system_base.php';
$zbp->Load();
$client_id=$zbp->Config('ytecn_zhouyi')->appkey;
$client_secret=$zbp->Config('ytecn_zhouyi')->appsecret;
$url="https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials&client_id=".$client_id."&client_secret=".$client_secret."&scope=smartapp_snsapi_base";
$w=array();
$w['count']=5;
$w['where_custom']=array(array('=', 'log_ytecn_bdsp', 0));
$w['order_custom']=array('log_ID' => 'ASC');
$array=GetList($w);
$as=array();
if(count($array)){
foreach ($array as $cc) {
$id=$cc->ID;
$title=$cc->Title;
$intro=$cc->Intro;
$intro = preg_replace('/[\r\n\s]+/', ' ', trim(SubStrUTF8(TransferHTML($intro,'[nohtml]'),135)).'...');
$ajax = Network::Create();
$ajax->open('GET', $url);
$ajax->enableGzip();
$ajax->setTimeOuts(60, 60, 0, 0);
$ajax->send();
$response = json_decode($ajax->responseText, true);
if (empty($response['access_token'])){
$as[]='推送搜索失败';
}else{
$access_token=$response['access_token'];
$post='[{
"path":"/pages/article/index?id='.$id.'",
"jump_app_key":"'.$client_id.'",
"title":"'.$title.'",
"mapp_type":2001,
"schema":"{\"datatype\":2,\"desc\":\"'.$intro.'\",\"detail\":{\"params\":{\"title\":\"'.$title.'\",\"desc\":\"'.$intro.'\",\"app_key\":\"'.$client_id.'\",\"jump_url\":\"/pages/article/index?id='.$id.'\",\"jump_type\":0}}}"
}]';
$header = array("Content-Type:application/json");
$api = "https://openapi.baidu.com/rest/2.0/smartapp/search/submit/schema?access_token=".$access_token;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $api);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
$result = curl_exec($curl);
$as[]='推送成功';
$sql = $zbp->db->sql->get()->update($zbp->table['Post'])
->where('=', 'log_ID', $id)
->data(array('log_ytecn_bdsp' => '1'))
->sql;
$zbp->db->Query($sql);
$zd=1;
}
}
}else{
$zd=0;
echo "推送完毕";
die();
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title>自动推送</title>
</head>
<body style="line-height:20px">
<?php
foreach ($as as $key =>$item) {
?>
<div><?php echo $item; ?>
</div>
<?php
}
if($zd){
?>
<script>
setTimeout(function() {
location.href = "<?php echo $zbp->host."baidusearchpost.php"; ?>";
}, 3000);
</script>
<span>暂停3秒后继续 >>> </span>
<a href="<?php echo $zbp->host.'baidusearchpost.php'; ?>">如果您的浏览器没有自动跳转,请点击这里</a><br>
<?php
}
?>
</body>
</html>
3、在浏览器里面执行下面的链接
点击复制代码 PHP
域名/baidusearchpost.php
等待出现“推送完毕”, 说明已推送结束。
4、完毕。
1、在文章表新建一个字段,如log_ytecn_bdsp,设置默认值为0。
2、在根目录创建一个文件,比如baidusearchpost.php,
点击复制代码 PHP
<?php
require 'zb_system/function/c_system_base.php';
$zbp->Load();
$client_id=$zbp->Config('ytecn_zhouyi')->appkey;
$client_secret=$zbp->Config('ytecn_zhouyi')->appsecret;
$url="https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials&client_id=".$client_id."&client_secret=".$client_secret."&scope=smartapp_snsapi_base";
$w=array();
$w['count']=5;
$w['where_custom']=array(array('=', 'log_ytecn_bdsp', 0));
$w['order_custom']=array('log_ID' => 'ASC');
$array=GetList($w);
$as=array();
if(count($array)){
foreach ($array as $cc) {
$id=$cc->ID;
$title=$cc->Title;
$intro=$cc->Intro;
$intro = preg_replace('/[\r\n\s]+/', ' ', trim(SubStrUTF8(TransferHTML($intro,'[nohtml]'),135)).'...');
$ajax = Network::Create();
$ajax->open('GET', $url);
$ajax->enableGzip();
$ajax->setTimeOuts(60, 60, 0, 0);
$ajax->send();
$response = json_decode($ajax->responseText, true);
if (empty($response['access_token'])){
$as[]='推送搜索失败';
}else{
$access_token=$response['access_token'];
$post='[{
"path":"/pages/article/index?id='.$id.'",
"jump_app_key":"'.$client_id.'",
"title":"'.$title.'",
"mapp_type":2001,
"schema":"{\"datatype\":2,\"desc\":\"'.$intro.'\",\"detail\":{\"params\":{\"title\":\"'.$title.'\",\"desc\":\"'.$intro.'\",\"app_key\":\"'.$client_id.'\",\"jump_url\":\"/pages/article/index?id='.$id.'\",\"jump_type\":0}}}"
}]';
$header = array("Content-Type:application/json");
$api = "https://openapi.baidu.com/rest/2.0/smartapp/search/submit/schema?access_token=".$access_token;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $api);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
$result = curl_exec($curl);
$as[]='推送成功';
$sql = $zbp->db->sql->get()->update($zbp->table['Post'])
->where('=', 'log_ID', $id)
->data(array('log_ytecn_bdsp' => '1'))
->sql;
$zbp->db->Query($sql);
$zd=1;
}
}
}else{
$zd=0;
echo "推送完毕";
die();
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title>自动推送</title>
</head>
<body style="line-height:20px">
<?php
foreach ($as as $key =>$item) {
?>
<div><?php echo $item; ?>
</div>
<?php
}
if($zd){
?>
<script>
setTimeout(function() {
location.href = "<?php echo $zbp->host."baidusearchpost.php"; ?>";
}, 3000);
</script>
<span>暂停3秒后继续 >>> </span>
<a href="<?php echo $zbp->host.'baidusearchpost.php'; ?>">如果您的浏览器没有自动跳转,请点击这里</a><br>
<?php
}
?>
</body>
</html>
3、在浏览器里面执行下面的链接
点击复制代码 PHP
域名/baidusearchpost.php
等待出现“推送完毕”, 说明已推送结束。
4、完毕。
新闻资讯 更多
热门文章
- 178Moban源码谈谈免费源码与收费源码的区别
- 2帝国CMS忘记后台登陆用户名、密码、认证码的解决方法
- 3帝国CMS(EmpireCMS) v7.5后台任意代码执行漏洞及具体修复方法
- 4帝国CMS和WordPress 哪个好?哪个适合建站?
- 5如何解决Discuz的密码错误次数过多请15分钟后登陆的问题
- 6帝国cms灵动标签取得内容和栏目链接地址
- 7emlog pro 注册码“开心”教程(如果有一天,emlog官方版 或者 emlog免费版 跑路了,那用户怎么办?)
- 8织梦CMS在nginx下设置伪静态方法(附nginx伪静态规则)
- 9帝国cms后台登录出现”您还未登录”怎么解决?
- 10帝国cms7.5忘记登录密码 和忘记登录认证码以及多次登录 失败被锁定解决办法