1. 程式人生 > 其它 >destoon百度小程式主動推送外掛

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

千行程式碼,Bug何處藏。 縱使上線又怎樣,朝令改,夕斷腸。