zblog
当前位置:首页 > 商学院 > zblog > 正文内容

zblog

百度小程序搜索组件批量提交文章代码

豫唐网络2022-07-01 16:122813

本方案为计划任务解决方案。

1、在文章表新建一个字段,如log_ytecn_bdsp,设置默认值为0。

2、在根目录创建一个文件,比如baidusearchpost.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($arrayas$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();
}

?>

<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">

<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8">
<metahttp-equiv="X-UA-Compatible"content="IE=7"/>
<title>自动推送</title>
</head>

<bodystyle="line-height:20px">


<?php
foreach($asas$key=>$item){
?>
<div><?phpecho$item;?>
</div>
<?php
}
if($zd){
?>
<script>
setTimeout(function(){
location.href="<?phpecho$zbp->host."baidusearchpost.php";?>";
},3000);
</script>
<span>暂停3秒后继续>>></span>
<ahref="<?phpecho$zbp->host.'baidusearchpost.php';?>">如果您的浏览器没有自动跳转,请点击这里</a><br>
<?php
}
?>
</body>

</html>

3、在浏览器里面执行下面的链接

域名/baidusearchpost.php

等待出现“推送完毕”, 说明已推送结束。

4、完毕。

扫描二维码推送至手机访问。

版权声明:本文由汤阴县豫唐网络科技有限公司发布,如需转载请注明出处。

本文链接:https://www.ytecn.com/post/281.html

分享给朋友:

相关文章

phpQuery获取HTML图片

phpQuery获取HTML图片

phpQuery获取HTML图片/** *获取html文本里的img *@paramstring$contenthtml内容 *@returnarray图片列表数组item格式<pre&g...

zblog提示授权文件非法怎么办

zblog提示授权文件非法怎么办

zblog在开启主题或者插件的时候,有时候会提示授权文件非法。这种需要怎么处理么?解决方案如下:进入后台,点击应用中心,使用购买此主题或者插件的账户登录应用中心商城,然后再开启即可解决问题。...

zblog商业授权

zblog商业授权

zblog的商用链接,已与2022年01月28从官网移除,git开源协议MIT。如你依然不放心,可以找豫唐购买授权服务。豫唐是zblog的指定授权商之一。Z-Blog 授权价格及服务支持版本授权许可:...

zblog主题插件导航函数

zblog主题插件导航函数

1、在主题或者插件的include.php文件添加导航函数functionytecn_SubMenu($id){ $arySubMenu=array( 0=>array('插件说明&...

zblog的面包屑路径怎么调用

zblog的面包屑路径怎么调用

文章页调用面包屑当前位置:<ahref="{$host}">首页</a> {php} $html=''; functionnavcat...