当前位置:网站首页>百度小程序自动提交搜索
百度小程序自动提交搜索
2022-06-29 06:32:00 【繁华pk落幕】
背景:新上线了小程序,使用了小程序自带的搜索组件,需要提交一些文章到搜索上才能在小程序里搜索出来,但是官方给出的接口一次只能提交50次,所以自己写了一个循环进行整个栏目的提交.也是为了做一个备份
使用的后台:
我使用的建站是pbootcms,如果你是其他的cms系统,可以适当修改
后台html:
新增一个按钮用于触发请求:
<button type="submit" name="submit" value="bdapp_search_all" class="layui-btn layui-btn-sm">百度小程序搜索全提交</button>截图如下:

后台方法:
\apps\admin\controller\content\ContentController.php
其他的cms需要到对应的php下了
在这里找到对应的方法,添加case分支,pb的可以搜baiduzz这个关键词,这个是pb自带的百度推送的分支处理
case 'bdapp_search_all':
$list = post('list');
$urls = post('urls');
$mcode = post('mcode', 'var');
//这个是小程序id,获取小程序的流程,可能会不一样的,我这里是保存到数据库中了
$client_id = $this->config('xcx_client_id');
//查询数据库获取所有的id,status=1的
$ids_list = $this->model->getList_search_ids($mcode);
$ids = '';
foreach($ids_list as $key => $ids_list){
if(($key % 9) != 0 || $key== 0){
$ids .= ($ids_list->id . ",");
}else{
$ids = trim($ids,',');
$in_sql = 'a.id in (' . $ids . ')';
$post_list = $this->model->getList($mcode, $in_sql, false);
$post_data = array();
//开始封装数据
foreach( $post_list as $key => $value ){
$tags = explode(',',$value->tags);
$tags = array_splice($tags,3);
$post_data[] = array(
'path' => '/pages/article/view?id=' . $value->id,//小程序的路径
'jump_app_key' => $client_id,
'title' => $value->title,
'mapp_type' => 2001,//这是内容类型,一般填这个就是
'schema' => json_encode([
'datatype'=>2,
'desc'=>$value->description,
'cate_name'=>$tags,
'detail'=>[
'params'=>[
'title'=>$value->title,
'desc'=>$value->description,
//'image'=>$value->ico,//这里如果需要图片,需要用http://xxx/xx.jpg 这样的格式,不能用相对路径
'author'=>$value->author,
'tags'=>$tags,
'publishTime'=> substr($value->date,0,16),
'app_key'=>$client_id,
'jump_url'=>'/pages/article/view?id=' . $value->id,
'jump_type'=>0
]
]
],JSON_UNESCAPED_UNICODE)
);
}
$post_data = json_encode($post_data,JSON_UNESCAPED_UNICODE);
//获取小程序的token
$access_token = $this->getAccessToken();
$api = "https://openapi.baidu.com/rest/2.0/smartapp/search/submit/schema?access_token=".$access_token;
$header = array('Content-Type:application/json');
$result = post_baiduapp($api, $post_data, $header);
if ( $result->errno==0 ) {
//$result->msg('成功推送小程序搜索'.ids);
} else {
$err_msg .= '推送发生错误:'. $ids;
}
$ids="";//重新初始化
}
}
alert_back($err_msg);
exit();
break;在 model中添加一个数据请求 \apps\admin\model\content\ContentModel.php
// 获取文章列表
public function getList_search_ids($mcode)
{
$field = array(
'a.id'
);
$join = array(
array(
'ay_content_sort b',
'a.scode=b.scode',
'LEFT'
),
array(
'ay_model d',
'b.mcode=d.mcode',
'LEFT'
)
);
return parent::table('ay_content a')->field($field)
->where("a.status='1'")
->where("b.mcode='$mcode'")
->join($join)
->order('a.id DESC')
->select();
}好了主要就是修改以上的三个地方.不过需要注意的是如果一次性提交的数量比较多的话,可能会报请求超时,不过数据提交是没用问题的.
效果展示:

边栏推荐
- The simple problem of leetcode is to divide an array into three parts equal to sum
- Servlet version conflict causes page 404
- Programming specification and variables of shell script
- What has urbanization brought to our mental health and behavior?
- Review of MySQL knowledge points
- Venn diagram proportional and color shading with semi transparency
- Regular expressions for shell script values
- QT writing map comprehensive application 58 compatible with multi browser kernel
- Conditional test, if and case conditional test statements of shell script
- ASP. Net core 6 framework unveiling example demonstration [03]:dapr initial experience
猜你喜欢

Parsing rshub document auto generation API

2-nitro-5,10,15,20-tetra (4-methylphenyl) porphyrin copper (no2tmpp) Cu) /2-nitro-5,10,15,20-tetra (4-methylphenyl) porphyrin (no2tmpp) H2) Qiyue porphyrin supply
![[deep learning] - maze task learning I (to realize the random movement of agents)](/img/c1/95b476ec62436a35d418754e4b11dc.jpg)
[deep learning] - maze task learning I (to realize the random movement of agents)

Programming specification and variables of shell script

Rearrangement string of leetcode simple question

2022.02.15 - 240. Lucky number in matrix

Manual (functional) test 1

How to change the password after forgetting the MySQL password (the latest version of 2022 detailed tutorial nanny level)

There are two ways for golang to develop mobile applications

Difference between parametric continuity and geometric continuity
随机推荐
How to use regex in file find
Failure: unable to log in to "taxpayer equity platform"
想请教一下,究竟有哪些劵商推荐?在线开户是安全么?
2-nitro-5,10,15,20-tetra (4-methylphenyl) porphyrin copper (no2tmpp) Cu) /2-nitro-5,10,15,20-tetra (4-methylphenyl) porphyrin (no2tmpp) H2) Qiyue porphyrin supply
Browser local storage
Slot
Can I cast int to a variable of type byte? What happens if the value is larger than the range of byte type?
ICLR is going to have a big discussion on the deep generation model. Max welling and the winner of the AAAI million dollar award are here. Bengio is one of the organizers
Why is there a packaging type?
Longest substring between two identical characters of leetcode simple question
National Defense University project summary
Parsing rshub document auto generation API
Skills of writing test cases efficiently
Mongodb paging method
The first commercial spacewalk of mankind is finalized! Musk SpaceX announced a new round of space travel plan, and the American rich became repeat customers
Modularization and modular specification commonjs
Haar cascades and LBP cascades in face detection [closed] - Haar cascades vs. LBP cascades in face detection [closed]
What has urbanization brought to our mental health and behavior?
Venn diagram proportional and color shading with semi transparency
How to change the password after forgetting the MySQL password (the latest version of 2022 detailed tutorial nanny level)