网友真实露脸自拍10p,成人国产精品秘?久久久按摩,国产精品久久久久久无码不卡,成人免费区一区二区三区

小程序模板網(wǎng)

如何開發(fā)小程序中的朋友圈功能

發(fā)布時(shí)間:2018-06-07 14:46 所屬欄目:小程序開發(fā)教程

一、開發(fā)功能分析:

1.各條內(nèi)容以列表展示 
2.點(diǎn)擊,可展示內(nèi)容詳情 
3.評論功能

二、數(shù)據(jù)庫建立

這里列表與詳細(xì),我們用一個(gè)表來實(shí)現(xiàn),評論用第二個(gè)表。總計(jì)2個(gè)表

1.post 表 
我們可以直接這樣導(dǎo)入一個(gè)JSON,但由于首頁的資訊這樣操作,導(dǎo)致數(shù)據(jù)都一模一樣,這次我們使用云函數(shù)定時(shí)采集數(shù)據(jù)到數(shù)據(jù)庫。

2.采集數(shù)據(jù) 
數(shù)據(jù)結(jié)構(gòu)地址:

var url = 'https://apiquan.ithome.com/api/post?categoryid=0&type=0&orderTime=1526981875455&visistCount=&pageLength=' 
如果手動(dòng)導(dǎo)入可以導(dǎo)入此數(shù)據(jù)結(jié)構(gòu):

 

  1. {
  2. "id":266716,
  3. "t":"普通聯(lián)通卡可以轉(zhuǎn)米粉卡嗎?",
  4. "c":"[雜談]",
  5. "cn":"暢談",
  6. "uid":100058,
  7. "un":"中國火箭軍",
  8. "rn":"諾基亞 Lumia 930",
  9. "pt":"/Date(1527057744773)/",
  10. "rt":"/Date(1527060538403)/",
  11. "vc":0,
  12. "rc":17,
  13. "IC":false,
  14. "IH":false,
  15. "ot":"/Date(-62135596800000)/"
  16. }

云函數(shù)獲取網(wǎng)址數(shù)據(jù)代碼:

 

  1. function onRequest(request, response, modules) {
  2. var http = modules.oHttp;
  3. var url = 'https://apiquan.ithome.com/api/post?categoryid=0&type=0&orderTime=1526981875455&visistCount=&pageLength='
  4. http(url, function(error, res, body) {
  5. response.end(body);
  6. });
  7. }

點(diǎn)擊測試看結(jié)果:

這樣就可以拿到目標(biāo)網(wǎng)址數(shù)據(jù).  如何插入到數(shù)據(jù)庫,看下面代碼:

 

  1. db.insert({
  2. "table":"XXX", //表名
  3. "data":{"a":"XXXX","b":"XXXX"} //需要更新的數(shù)據(jù),格式為JSON
  4. },function(err,data){ //回調(diào)函數(shù)
  5. });

上面是插入單行數(shù)據(jù),如果批量插入,可以使用下面代碼:

 

  1. function onRequest(request, response, modules) {
  2. var http = modules.oHttp;
  3. var db = modules.oData;
  4. var url = 'https://apiquan.ithome.com/api/post?categoryid=0&type=0&orderTime=1526981875455&visistCount=&pageLength='
  5. http(url, function(error, res, body) {
  6.  
  7. //結(jié)果轉(zhuǎn)為對象類型
  8. var results =JSON.parse(body);
  9.  
  10. var arr = [];
  11. //循環(huán)更新數(shù)據(jù)
  12. for (var i in results) {
  13. newdata = {
  14. "method": "post",
  15. "path": "/1/classes/post",
  16. "body":results[i]
  17. };
  18. arr.push(newdata)
  19. }
  20.  
  21. //獲取數(shù)組對象
  22. var bat = modules.oBatch;
  23. //批量操作
  24. bat.exec({
  25. "data": {
  26. "requests": arr
  27. }
  28. }, function (err, data) {
  29. //回調(diào)函數(shù)
  30. response.end(data);
  31. return;
  32. });
  33.  
  34. response.end(JSON.stringify(results.length));
  35. });
  36. }

點(diǎn)擊測試,效果下如圖:

3.定時(shí)任務(wù)  當(dāng)然你也可以設(shè)置個(gè)定時(shí)任務(wù),我這里設(shè)置結(jié)果:

當(dāng)然你也可以設(shè)置每小時(shí),每天,每分鐘,每秒,每隔5分鐘等等,規(guī)則可以自己定義,具體請看云函數(shù)文檔,文檔地址:  定時(shí)任務(wù)云函數(shù)文檔

這里我們把朋友圈的數(shù)據(jù)表建立,并采集了相關(guān)數(shù)據(jù),下次我們在講修改mpvue小程序代碼。


易優(yōu)小程序(企業(yè)版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://www.xiuhaier.com/wxmini/doc/course/24507.html 復(fù)制鏈接 如需定制請聯(lián)系易優(yōu)客服咨詢:800182392 點(diǎn)擊咨詢
QQ在線咨詢
AI智能客服 ×