AFT博客
给你需要的内容 AFTSS.CN!

织梦百度小程序获取文章内容接口

接口标识:show

接口url:https://你的网站/api/index.php?action=show[&id=10]

接口参数:

织梦百度小程序获取文章内容接口

小程序代码

swan.request({ 
    url: app.globalData.api + "action=show", 
    data: { 
          typeid: that.data.typeid, 
          id: that.data.id, 
          relation: 1,//开启调用相关推荐 
          aid: app.globalData.aid 
     }, 
     method: 'POST', 
     header: { 
           'content-type': 'application/x-www-form-urlencoded', 
           'x-appsecret': app.globalData.appsecret 
      }, 
      success: function (res) { 
           var content=res.data.data; 
            ...... 
      } 
})

 

说明:

(1)该页面引入了require(‘https:/blog.aftss.cn/utils/util.js’),里边封装的有对时间的处理,因为api返回的是时间戳,需要处理

content.relations[i].pubdate = util.formatTime(content.relations[i].pubdate, 'Y-M-D');

(2)由于小程序不支持直接的html标签,所以引入bdparse插件,具体参考demo。

(3)relation默认关闭,需要修改代码来开启,参考demo

(4)字段中如果有数组,需要进行特殊处理,代码实例:

//判断是否有组图自动判断 
if (content.pictureurls){ 
       content.pictureurls=JSON.parse(content.pictureurls) 
}

(5)相关内容推荐,swan页面做了判断,如果没有内容默认不显示,而相关评价却没加,自己根据需要修改。

(6)接口返回的数据包含文章的上一篇和下一篇,调用代码:

that.setData({ 
     pre: content.preNext.pre, 
     next: content.preNext.next, 
})

前端:

<view class="nextpage mt10" bindtap="nextpage" data-id="{{pre.id}}">上一篇:{{pre.title}}</view> 
    <view class="nextpage" bindtap="nextpage" data-id="{{next.id}}" >下一篇:{{next.title}}</view>

 

 

赞(0)
版权声明:除特别注明外,本站所有文章均基于CC-BY-NC-SA 4.0原创,禁止任何形式的转载。
文章名称:《织梦百度小程序获取文章内容接口》
文章链接:https://blog.aftss.cn/877.html
文章版权归作者所有,未经允许请勿转载。
分享到