PHP程序里面
URL地址相對(duì)路徑:https://it0772.net/index.php
PHP文件相對(duì)路徑:D:\wwwroot\yufengly\wwwroot/dayrui/App/
使用任意API查詢接口,查詢搜索文章標(biāo)題關(guān)鍵字“歡歌螺韻 魅力魚峰”,然后返回一個(gè)json數(shù)據(jù),里面包含有文章數(shù)據(jù)
https://it0772.net/index.php?appid=2&appsecret=XXX&s=news&c=search&keyword=歡歌螺韻 魅力魚峰
這是現(xiàn)在查詢到的數(shù)據(jù),我要如何獲取里面的文章內(nèi)容
"id": "1069",
"catid": "155",
"title": "“歡歌螺韻 魅力魚峰”⒀:飛“閱”鄉(xiāng)村",
"thumb": null,
"keywords": null,
"description": "夢(mèng)幻新安、水山秘境、金色龍江……魚峰區(qū)里雍。。。。",
"hits": "223",
"uid": "0",
"author": "cyberadmin",
"status": "9",
"url": "https://it0772.net/index.php?c=show&id=1069",
"link_id": "0",
"tableid": "0",
"inputip": "XXXXXXX",
"inputtime": "2020-09-29 11:37:59",
"updatetime": "2020-10-14 11:44:56",
"comments": "0",
"avgsort": "0.00",
"displayorder": "0",
"relateNews": null,
"media": "",
"newsform": "魚峰區(qū)委宣傳部",
"fabuzhe": "本站",
"thumbs": [
"4419"
],
"shzxx": null,
"fujian": [],
"zxts_total": "0",
"kfpl": "2",
"test_total": "0",
"wailian": "",
"_inputtime": "1601350679",
"_updatetime": "1602647096",
"_thumbs": "[\"4419\"]",
"_fujian": ""
},
插件版權(quán):官方插件
插件名稱:API接口
這個(gè)api是返回的主表數(shù)據(jù),文章內(nèi)容是附表,所以不會(huì)返回他,需要寫一個(gè)回調(diào)方法
參考文檔:《回調(diào)方法的定義》
開源是一種精神,但不是義務(wù),幫忙是情分,不幫也不要抱怨,建議大家多研究代碼、多閱讀代碼、多翻閱社區(qū)歷史問題!
打開或新建文件/dayrui/My/Library/Http.php,這個(gè)文件專門是定義回調(diào)方法的
<?php namespace My\Library; class Http extends \Phpcmf\Library\Http { //// 上面是系統(tǒng)自帶的 /// 下面是自己加的+++++++++++ public function my_news_list_data($data) { $rt = []; // 這里根據(jù)項(xiàng)目的$data輸出格式來(lái)定義PHP的數(shù)據(jù)寫法, // 每個(gè)接口的寫法幾乎不一樣,下面是測(cè)試?yán)? if ($data) { foreach ($data as $t) { $ext = \Phpcmf\Service::table_site('news_data_'.intval($t['tableid']))->get($t['id']); $rt[] = [ 'content'=> dr_ueditor_html($ext['content'], $t['title']), 'title' => $t['title'], // 標(biāo)題 'id' => $t['id'], // id號(hào) 'catname' => dr_cat_value('news', $t['catid'], 'name'), // news模塊的當(dāng)前內(nèi)容欄目名稱 'thumb' => dr_thumb($t['thumb'], 200, 200), // 圖片id轉(zhuǎn)換為地址 'updatetime' => dr_date($t['_updatetime'], 'Y-m-d H:i:s'), // 時(shí)間轉(zhuǎn)換 ]; } } return $rt; } // 上面是自己加的+++++++++++ //// 下面是系統(tǒng)自帶的 }請(qǐng)求的url后綴加一個(gè)
開源是一種精神,但不是義務(wù),幫忙是情分,不幫也不要抱怨,建議大家多研究代碼、多閱讀代碼、多翻閱社區(qū)歷史問題!
回復(fù)@官方插件實(shí)習(xí)技術(shù) 可是回調(diào)方法怎么得到附表的內(nèi)容?
回調(diào)方法里面我已經(jīng)寫好了,調(diào)用附表內(nèi)容
回復(fù)@1451599023
開源是一種精神,但不是義務(wù),幫忙是情分,不幫也不要抱怨,建議大家多研究代碼、多閱讀代碼、多翻閱社區(qū)歷史問題!
回復(fù)@官方插件實(shí)習(xí)技術(shù)
public function my_news_list_data($data) { $rt = []; // 這里根據(jù)項(xiàng)目的$data輸出格式來(lái)定義PHP的數(shù)據(jù)寫法, // 每個(gè)接口的寫法幾乎不一樣,下面是測(cè)試?yán)? if ($data) { foreach ($data['list'] as $t) { $ext = \Phpcmf\Service::table_site('news_data_'.intval($t['tableid']))->get($t['id']); $rt[] = [ 'content'=> dr_ueditor_html($ext['content'], $t['title']), 'title' => $t['title'], // 標(biāo)題 'id' => $t['id'], // id號(hào) 'catname' => dr_cat_value('news', $t['catid'], 'name'), // news模塊的當(dāng)前內(nèi)容欄目名稱 'thumb' => dr_thumb($t['thumb'], 200, 200), // 圖片id轉(zhuǎn)換為地址 'updatetime' => dr_date($t['_updatetime'], 'Y-m-d H:i:s'), // 時(shí)間轉(zhuǎn)換 ]; } } return $rt; }{ "code": 1, "msg": "view", "data": { "member": [], "meta_keywords": "歡歌螺韻,魅力魚峰", "meta_title": "歡歌螺韻魅力魚峰_文章_柳州市魚峰區(qū)旅游網(wǎng)", "meta_description": "柳州市魚峰區(qū)旅游網(wǎng)", "cat": [], "top": [], "get": { "appid": "2", "appsecret": "MZSTNB9961023B977F", "keyword": "歡歌螺韻%魅力魚峰" }, "list": [ { "id": "1069", "catid": "155", "title": "“歡歌螺韻 魅力魚峰”⒀:飛“閱”鄉(xiāng)村", "thumb": null, "keywords": null, "description": "夢(mèng)幻新安、水山秘境、金色龍江……魚峰區(qū)里雍、白沙兩鎮(zhèn)有著豐富的人文與自然風(fēng)光。今天我們一起飛“閱”魚峰,以全新的角度領(lǐng)略鄉(xiāng)村魅力吧!青龍雙洲 宣傳部提供夢(mèng)幻新安 蔡繼青攝美麗家園 黎寒池?cái)z立沖半島 梁...", "hits": "223", "uid": "0", "author": "cyberadmin", "status": "9", "url": "https://it0772.net/index.php?c=show&id=1069", "link_id": "0", "tableid": "0", "inputip": "111.59.70.77", "inputtime": "2020-09-29 11:37:59", "updatetime": "2020-10-14 11:44:56", "comments": "0", "avgsort": "0.00", "displayorder": "0", "relateNews": null, "media": "", "newsform": "魚峰區(qū)委宣傳部", "fabuzhe": "本站", "thumbs": [ "4419" ], "shzxx": null, "fujian": [], "zxts_total": "0", "kfpl": "2", "test_total": "0", "wailian": "", "_inputtime": "1601350679", "_updatetime": "1602647096", "_thumbs": "[\"4419\"]", "_fujian": "" }, { "id": "1066", "catid": "155", "title": "“歡歌螺韻 魅力魚峰”⑿潮人和吃貨的打卡圣地,這些地方你一定不能錯(cuò)過", "thumb": null, "keywords": null, "description": "“歡歌螺韻 魅力魚峰 ” ,柳州市的大部分風(fēng)景名勝都坐落在魚峰區(qū),魚峰區(qū)內(nèi)不僅有國(guó)家級(jí)AAAA景區(qū)多達(dá)10個(gè),更擁有白蓮洞遺址、鯉魚嘴遺址、胡志明舊居、昆侖關(guān)戰(zhàn)役舊址4個(gè)全國(guó)重點(diǎn)文物保護(hù)單位及自治區(qū)級(jí)...", "hits": "1189", "uid": "0", "author": "cyberadmin", "status": "9", "url": "https://it0772.net/index.php?c=show&id=1066", "link_id": "0", "tableid": "0", "inputip": "111.59.70.77", "inputtime": "2020-09-25 09:09:10", "updatetime": "2020-09-27 15:22:27", "comments": "0", "avgsort": "0.00", "displayorder": "0", "relateNews": null, "media": "", "newsform": "魅力魚峰、箭盤山街道辦事處、白蓮街道辦事處", "fabuzhe": "本站", "thumbs": [ "4406" ], "shzxx": null, "fujian": [], "zxts_total": "0", "kfpl": "2", "test_total": "0", "wailian": "", "_inputtime": "1600996150", "_updatetime": "1601191347", "_thumbs": "[\"4406\"]", "_fujian": "" },我沒改對(duì)嗎,提示系統(tǒng)故障了
把錯(cuò)誤日志內(nèi)容發(fā)來(lái)看看,方法是:http://help.xunruicms.com/658.html
你需要把你完整的請(qǐng)求URL給我,我再給你改改URL的參數(shù)和回調(diào),【敏感key參數(shù)請(qǐng)?zhí)砑拥健皟H管理員可見區(qū)域”】
開源是一種精神,但不是義務(wù),幫忙是情分,不幫也不要抱怨,建議大家多研究代碼、多閱讀代碼、多翻閱社區(qū)歷史問題!
回復(fù)@官方插件實(shí)習(xí)技術(shù)
<?php defined('SYSTEMPATH') || exit('No direct script access allowed'); ?> CRITICAL - 2020-10-21 15:43:46 --> Call to undefined method Phpcmf\Service::table_site() # https://it0772.net/index.php?appid=2&appsecret=MZSTNB9961023B977F&s=news&c=search&keyword=%E6%AC%A2%E6%AD%8C%E8%9E%BA%E9%9F%B5%20%E9%AD%85%E5%8A%9B%E9%B1%BC%E5%B3%B0&api_call_function=my_news_list_data # SELECT * FROM `yfly_1_news` WHERE (`yfly_1_news`.`id` IN(992,994,996,1000,1016,1039,1057,1059,1060,1061,1064,1066,1069)) ORDER BY `yfly_1_news`.`updatetime` DESC LIMIT 0,10 #0 D:\wwwroot\yufengly\wwwroot\dayrui\Fcms\Core\View.php(203): My\Library\Http->my_news_list_data(Array) #1 D:\wwwroot\yufengly\wwwroot\dayrui\Fcms\Control\Home\Module.php(363): Phpcmf\View->display('search.html') #2 D:\wwwroot\yufengly\wwwroot\dayrui\App\News\Controllers\Search.php(12): Phpcmf\Home\Module->_Search() #3 D:\wwwroot\yufengly\wwwroot\dayrui\System\CodeIgniter.php(847): Phpcmf\Controllers\Search->index() #4 D:\wwwroot\yufengly\wwwroot\dayrui\System\CodeIgniter.php(338): CodeIgniter\CodeIgniter->runController(Object(Phpcmf\Controllers\Search)) #5 D:\wwwroot\yufengly\wwwroot\dayrui\System\CodeIgniter.php(246): CodeIgniter\CodeIgniter->handleRequest(NULL, Object(Config\Cache), false) #6 D:\wwwroot\yufengly\wwwroot\dayrui\Fcms\Init.php(327): CodeIgniter\CodeIgniter->run() #7 D:\wwwroot\yufengly\wwwroot\index.php(44): require('D:\\wwwroot\\yufe...') #8 {main}這個(gè)錯(cuò)誤是cms版本低了,升級(jí)下cms
回復(fù)@1451599023
開源是一種精神,但不是義務(wù),幫忙是情分,不幫也不要抱怨,建議大家多研究代碼、多閱讀代碼、多翻閱社區(qū)歷史問題!
不好意思,回調(diào)函數(shù)我寫錯(cuò)了
<?php namespace My\Library; class Http extends \Phpcmf\Library\Http { //// 上面是系統(tǒng)自帶的 /// 下面是自己加的+++++++++++ public function my_news_list_data($data) { $rt = []; // 這里根據(jù)項(xiàng)目的$data輸出格式來(lái)定義PHP的數(shù)據(jù)寫法, // 每個(gè)接口的寫法幾乎不一樣,下面是測(cè)試?yán)? if ($data['list']) { foreach ($data['list'] as $t) { $ext = \Phpcmf\Service::M()->table_site('news_data_'.intval($t['tableid']))->get($t['id']); $rt[] = [ 'content'=> dr_ueditor_html($ext['content'], $t['title']), 'title' => $t['title'], // 標(biāo)題 'id' => $t['id'], // id號(hào) 'catname' => dr_cat_value('news', $t['catid'], 'name'), // news模塊的當(dāng)前內(nèi)容欄目名稱 'thumb' => dr_thumb($t['thumb'], 200, 200), // 圖片id轉(zhuǎn)換為地址 'updatetime' => dr_date($t['_updatetime'], 'Y-m-d H:i:s'), // 時(shí)間轉(zhuǎn)換 ]; } } return $rt; } // 上面是自己加的+++++++++++ //// 下面是系統(tǒng)自帶的 }開源是一種精神,但不是義務(wù),幫忙是情分,不幫也不要抱怨,建議大家多研究代碼、多閱讀代碼、多翻閱社區(qū)歷史問題!
回復(fù)@官方插件實(shí)習(xí)技術(shù) 還是報(bào)錯(cuò)
2020-10-21 16:16:08 --> Error 文件: D:\wwwroot\yufengly\wwwroot\dayrui\My\Library\Http.php 行號(hào): 54 錯(cuò)誤: Call to undefined function My\Library\dr_ueditor_html() {"html":"<pre><code><span class=\"line\"><span class=\"number\">47<\/span> <\/span><span style=\"color: #c7c7c7\">$rt <\/span><span style=\"color: #f1ce61;\">= [];\n<span class=\"line\"><span class=\"number\">48<\/span> <\/span><span style=\"color: #767a7e; font-style: italic\">\/\/ 這里根據(jù)項(xiàng)目的$data輸出格式來(lái)定義PHP的數(shù)據(jù)寫法,\n<span class=\"line\"><span class=\"number\">49<\/span> \/\/ 每個(gè)接口的寫法幾乎不一樣,下面是測(cè)試?yán)覾n<span class=\"line\"><span class=\"number\">50<\/span> <\/span><span style=\"color: #f1ce61;\">if (<\/span><span style=\"color: #c7c7c7\">$data<\/span><span style=\"color: #f1ce61;\">[<\/span><span style=\"color: #869d6a\">'list'<\/span><span style=\"color: #f1ce61;\">]) {\n<span class=\"line\"><span class=\"number\">51<\/span> foreach (<\/span><span style=\"color: #c7c7c7\">$data<\/span><span style=\"color: #f1ce61;\">[<\/span><span style=\"color: #869d6a\">'list'<\/span><span style=\"color: #f1ce61;\">] as <\/span><span style=\"color: #c7c7c7\">$t<\/span><span style=\"color: #f1ce61;\">) {\n<span class=\"line\"><span class=\"number\">52<\/span> <\/span><span style=\"color: #c7c7c7\">$ext <\/span><span style=\"color: #f1ce61;\">= \\<\/span><span style=\"color: #c7c7c7\">Phpcmf<\/span><span style=\"color: #f1ce61;\">\\<\/span><span style=\"color: #c7c7c7\">Service<\/span><span style=\"color: #f1ce61;\">::<\/span><span style=\"color: #c7c7c7\">M<\/span><span style=\"color: #f1ce61;\">()-><\/span><span style=\"color: #c7c7c7\">table_site<\/span><span style=\"color: #f1ce61;\">(<\/span><span style=\"color: #869d6a\">'news_data_'<\/span><span style=\"color: #f1ce61;\">.<\/span><span style=\"color: #c7c7c7\">intval<\/span><span style=\"color: #f1ce61;\">(<\/span><span style=\"color: #c7c7c7\">$t<\/span><span style=\"color: #f1ce61;\">[<\/span><span style=\"color: #869d6a\">'tableid'<\/span><span style=\"color: #f1ce61;\">]))-><\/span><span style=\"color: #c7c7c7\">get<\/span><span style=\"color: #f1ce61;\">(<\/span><span style=\"color: #c7c7c7\">$t<\/span><span style=\"color: #f1ce61;\">[<\/span><span style=\"color: #869d6a\">'id'<\/span><span style=\"color: #f1ce61;\">]);\n<span class=\"line\"><span class=\"number\">53<\/span> <\/span><span style=\"color: #c7c7c7\">$rt<\/span><span style=\"color: #f1ce61;\">[] = [\n<span class='line highlight'><span class='number'>54<\/span> 'content'=> dr_ueditor_html($ext['content'], $t['title']),\n<\/span><\/span><span style=\"color: #869d6a\"><\/span><span style=\"color: #f1ce61;\"><\/span><span style=\"color: #c7c7c7\"><\/span><span style=\"color: #f1ce61;\"><\/span><span style=\"color: #c7c7c7\"><\/span><span style=\"color: #f1ce61;\"><\/span><span style=\"color: #869d6a\"><\/span><span style=\"color: #f1ce61;\"><\/span><span style=\"color: #c7c7c7\"><\/span><span style=\"color: #f1ce61;\"><\/span><span style=\"color: #869d6a\"><\/span><span style=\"color: #f1ce61;\"><span class=\"line\"><span class=\"number\">55<\/span> <\/span><span style=\"color: #869d6a\">'title' <\/span><span style=\"color: #f1ce61;\">=> <\/span><span style=\"color: #c7c7c7\">$t<\/span><span style=\"color: #f1ce61;\">[<\/span><span style=\"color: #869d6a\">'title'<\/span><span style=\"color: #f1ce61;\">], <\/span><span style=\"color: #767a7e; font-style: italic\">\/\/ 標(biāo)題\n<span class=\"line\"><span class=\"number\">56<\/span> <\/span><span style=\"color: #869d6a\">'id' <\/span><span style=\"color: #f1ce61;\">=> <\/span><span style=\"color: #c7c7c7\">$t<\/span><span style=\"color: #f1ce61;\">[<\/span><span style=\"color: #869d6a\">'id'<\/span><span style=\"color: #f1ce61;\">], <\/span><span style=\"color: #767a7e; font-style: italic\">\/\/ id號(hào)\n<span class=\"line\"><span class=\"number\">57<\/span> <\/span><span style=\"color: #869d6a\">'catname' <\/span><span style=\"color: #f1ce61;\">=> <\/span><span style=\"color: #c7c7c7\">dr_cat_value<\/span><span style=\"color: #f1ce61;\">(<\/span><span style=\"color: #869d6a\">'news'<\/span><span style=\"color: #f1ce61;\">, <\/span><span style=\"color: #c7c7c7\">$t<\/span><span style=\"color: #f1ce61;\">[<\/span><span style=\"color: #869d6a\">'catid'<\/span><span style=\"color: #f1ce61;\">], <\/span><span style=\"color: #869d6a\">'name'<\/span><span style=\"color: #f1ce61;\">), <\/span><span style=\"color: #767a7e; font-style: italic\">\/\/ news模塊的當(dāng)前內(nèi)容欄目名稱\n<span class=\"line\"><span class=\"number\">58<\/span> <\/span><span style=\"color: #869d6a\">'thumb' <\/span><span style=\"color: #f1ce61;\">=> <\/span><span style=\"color: #c7c7c7\">dr_thumb<\/span><span style=\"color: #f1ce61;\">(<\/span><span style=\"color: #c7c7c7\">$t<\/span><span style=\"color: #f1ce61;\">[<\/span><span style=\"color: #869d6a\">'thumb'<\/span><span style=\"color: #f1ce61;\">], <\/span><span style=\"color: #c7c7c7\">200<\/span><span style=\"color: #f1ce61;\">, <\/span><span style=\"color: #c7c7c7\">200<\/span><span style=\"color: #f1ce61;\">), <\/span><span style=\"color: #767a7e; font-style: italic\">\/\/ 圖片id轉(zhuǎn)換為地址\n<span class=\"line\"><span class=\"number\">59<\/span> <\/span><span style=\"color: #869d6a\">'updatetime' <\/span><span style=\"color: #f1ce61;\">=> <\/span><span style=\"color: #c7c7c7\">dr_date<\/span><span style=\"color: #f1ce61;\">(<\/span><span style=\"color: #c7c7c7\">$t<\/span><span style=\"color: #f1ce61;\">[<\/span><span style=\"color: #869d6a\">'_updatetime'<\/span><span style=\"color: #f1ce61;\">], <\/span><span style=\"color: #869d6a\">'Y-m-d H:i:s'<\/span><span style=\"color: #f1ce61;\">), <\/span><span style=\"color: #767a7e; font-style: italic\">\/\/ 時(shí)間轉(zhuǎn)換\n<span class=\"line\"><span class=\"number\">60<\/span> <\/span><span style=\"color: #f1ce61;\">];\n<span class=\"line\"><span class=\"number\">61<\/span> }\n<\/span><\/code><\/pre>"} 查詢: SELECT * FROM `yfly_1_news_data_0` WHERE `id` = 1069 地址: https://it0772.net/index.php?appid=2&appsecret=MZSTNB9961023B977F&s=news&c=search&keyword=%E6%AC%A2%E6%AD%8C%E8%9E%BA%E9%9F%B5%20%E9%AD%85%E5%8A%9B%E9%B1%BC%E5%B3%B0&api_call_function=my_news_list_data 來(lái)源:這個(gè)是cms版本低了,升級(jí)cms,我本地運(yùn)行ok的
回復(fù)@1451599023
開源是一種精神,但不是義務(wù),幫忙是情分,不幫也不要抱怨,建議大家多研究代碼、多閱讀代碼、多翻閱社區(qū)歷史問題!
回復(fù)@官方插件實(shí)習(xí)技術(shù) 怎么刪除剛剛的回復(fù)的信息?
回調(diào)方法很舒服,想加什么字段就可以輸出什么字段