destoon百度小程序主动推送插件

    最近在做百度小程序,百度小程序额度增加了,就在想如何在destoon上发一条内容推送一条到小程序上,也不用每天手动推送。达到小程序端和站点自动同步,不会浪费推送限额。

上代码:

1、打开api\extend.func.php    【注意你这个文件有没有进行过二次开发,如果有,就将下面的复制进去即可】

增加函数:

  

//百度小程序推送
function baiduMini($url){
$str=file_get_contents('https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials&client_id=小程序app key&client_secret=小程序密钥&scope=smartapp_snsapi_base');
$array=json_decode($str,true);
$token=$array["access_token"];
$data['type'] = 1;
$data['url_list'] = $url;
$api = 'https://openapi.baidu.com/rest/2.0/smartapp/access/submitsitemap/api?access_token=' . $token;
$ch = curl_init();
$options =  array(
CURLOPT_URL => $api,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_NOBODY => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0,
CURLOPT_POSTFIELDS => http_build_query($data),
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HTTPHEADER => array('Content-Type: application/x-www-form-urlencoded'),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
$data = json_encode($result, true);
}

  打开module\mall\mall.class.php(其他模块的打开module\模块名称\模块名称.class.php)

  

function _($e) {

  在上面增加:

  

//百度小程序推送
function baidu_MiniPro($itemid) {
    global $_username, $MOD;
    if(is_array($itemid)) {
    foreach($itemid as $v) { $this->baidu($v); }
    } else {
    $this->itemid = $itemid;
    $item = $this->get_one();
    $item['linkurl'] = '/pages/'.$MOD['moduledir'].'/detail?id='.$itemid;  如果其他小程序不一致,修改即可
    $baidu = baiduMini($item['linkurl']);
    return true;
    }
}

  2-2、搜索:

  

if($post['status'] == 3 && $post['username'] && $MOD['credit_add']) {
  credit_add($post['username'], $MOD['credit_add']);
  credit_record($post['username'], $MOD['credit_add'], 'system', lang('my->credit_record_add', array($MOD['name'])), 'ID:'.$this->itemid);
}

  在下面增加:

  

if($post['status'] == 3) {
$this->baidu_MiniPro($this->itemid);//百度小程序
}

  

这样就搞定了,这样就每天只要发布都会自动同步到小程序上。

文章原创转自:http://www.kaotop.com/it/640619.html

posted @ 2021-12-07 13:14  圆柱模板  阅读(110)  评论(0编辑  收藏  举报