zblog
當前位置:首頁 > 商學院 > zblog > 正文内容

zblog

百度小(xiǎo)程序搜索組件(jiàn)批量提交文章代碼

豫唐網絡2022-07-01 16:121846

本方案為(wèi)計劃任務解決方案。

1、在文章表新建一(yī)個(gè)字段,如log_ytecn_bdsp,設置默認值為(wèi)0。

2、在根目錄創建一(yī)個(gè)文件(jiàn),比如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 ($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>自(zì)動推送</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秒(miǎo)後繼續 >>> </span>
    <a href="<?php echo $zbp->host.'baidusearchpost.php'; ?>">如果您的浏覽器(qì)沒有自(zì)動跳轉,請點擊這裡(lǐ)</a><br>
    <?php
    }
    ?>
</body>

</html>

3、在浏覽器(qì)裡(lǐ)面執行下(xià)面的鏈接

域名/baidusearchpost.php

等待出現“推送完畢”, 說明已推送結束。

4、完畢。

掃描二維碼推送至手機(jī)訪問。

版權聲明:本文由湯陰縣飄瑾網絡科技(jì)工(gōng)作室發布,如需轉載請注明出處。

本文鏈接:

分享給朋友(yǒu):

相(xiàng)關文章

php中截取中文字符串

php中截取中文字符串

截取GB2312中文字符串function mysubstr($str, $start, $len) {     $t...

zblogphp當天發表的文章日期标紅(hóng)

zblogphp當天發表的文章日期标紅(hóng)

模拟下(xià)代碼場景。{foreach $articles as $article} <h4 class="post-date">{...

zba文件(jiàn)怎麽使用?zba文件(jiàn)是什麽?

zba文件(jiàn)怎麽使用?zba文件(jiàn)是什麽?

        .zba是zblogphp的專用應用格式。應用格式又(yòu)分主題和插件(jiàn)兩種。   ...

zblog插件(jiàn)怎麽安裝

zblog插件(jiàn)怎麽安裝

        zblog的插件(jiàn)分為(wèi)應用中心插件(jiàn)和自(zì)定義插件(jiàn)兩大類。應用中心插件(jiàn)又(yòu)分為(wèi)免費(fèi)插件(jiàn)和付費(fèi)插件(jiàn)。自(zì)定義插件(jiàn)分為(wèi)...

zblog文章頁調用同分類文章

zblog文章頁調用同分類文章

zblog文章頁調用同分類文章需要用到(dào)getlist函數,居然代碼如下(xià){php} $cid=$article->Category->RootID?$article->Categor...