Thinkphp内核百度小程序输出接口
最近百度小程序比较火,自己站点用thinkphp打造的,所以写了这个Thinkphp的百度小程序输出接口,实现数据同步。
附上代码
<?php
namespace app\article\controller;
use think\Request;
use com\File;
use mip\Htmlp;
use mip\Mip;
class ApiArticle extends Mip
{
protected $beforeActionList = ['start'];
public function start() {
$this->itemModelNameSpace = 'app\article\model\Articles';
$this->item = $this->articles;
$this->itemCategory = $this->articlesCategory;
$this->itemContent = $this->articlesContent;
$this->itemType = 'article';
} public function itemList()
{
$page = input('post.page');
$limit = input('post.limit');
$orderBy = input('post.orderBy');
$order = input('post.order');
$cid = input('post.cid');
$keywords = input('post.keywords');
$domain = input('post.domain');
if (!$page) {
$page = 1;
}
if (!$limit) {
$limit = 10;
}
if (!$orderBy) {
$orderBy = 'id';
}
if (!$order) {
$order = 'desc';
}
$patern = '/^^((https|http|ftp)?:?\/\/)[^\s]+$/';
$itemList = model($this->itemModelNameSpace)->getItemList($cid,$page,$limit,$orderBy,$order,null,$where,$keywords);
$itemCount = model($this->itemModelNameSpace)->getCount($cid,'', $keywords);
if ($domain) {
if ($itemList) {
foreach ($itemList as $key => $val) {
$itemList[$key]['url'] = model($this->itemModelNameSpace)->getUrlByItemInfo($val,$domain);
}
}
} if ($itemList) {
foreach ($itemList as $key => $val) {
$itemList[$key]['publish_date'] = date('Y-m-d H:i:s',$itemList[$key]['publish_time']);
if ($itemList[$key]['firstImg']) {
if (!preg_match($patern,$itemList[$key]['firstImg'])) {
$itemList[$key]['firstImg'] = $this->domain . $itemList[$key]['firstImg'];
}
}
}
} return jsonSuccess('',['itemList' => $itemList,'total' => $itemCount,'page' => $page]);
} public function getItemInfo()
{
$uuid = input('post.uuid');
if ($uuid) {
$itemInfo = db($this->item)->where('uuid',$uuid)->find();
} else {
return jsonError('内容不存在');
}
$itemInfo = model($this->itemModelNameSpace)->getItemInfo('',$uuid);
$itemInfo['publish_date'] = date('Y-m-d H:i:s',$itemInfo['publish_time']);
$patern = '/^^((https|http|ftp)?:?\/\/)[^\s]+$/';
preg_match_all('/<img.*?src=[\'|\"](.*?)[\'|\"].*?[\/]?>/', $itemInfo['content'], $imagesArrays);
if ($imagesArrays) {
foreach($imagesArrays[1] as $k => $v) {
if (!preg_match($patern,$imagesArrays[1][$k])) {
$srcUrl = $this->domain . $imagesArrays[1][$k];
$itemInfo['content'] = str_replace($imagesArrays[1][$k],$srcUrl,$itemInfo['content']);
}
}
} return jsonSuccess('',$itemInfo);
}
}
Thinkphp内核百度小程序输出接口的更多相关文章
- 自动生成百度小程序sitemap.txt文件路径
因为业务需要,需要在目前项目上开发一个百度小程序,百度智能小程序上线了,但是内容每天得推送,不可能一个小程序路径一个推送吧,因为小程序路径和项目路径不一致. 因为项目是用ThinkPHP开发的,在此附 ...
- 逐浪CMS+百度小程序开源包发布-对接海量资源助力推广
接入百度小程序海量流量就在使用Zoomla!逐浪CMS开发栈 这里有最强的CMS内核依托于国家高新企业Zoomla!逐浪之上 这里有最海量的用户流量依托于百度小程序 这里有最开放的技术栈 这里有最卓越 ...
- 百度小程序button去掉默认边框
百度小程序button去掉默认边框: button::after{ border:none; }
- 微信小程序转换为百度小程序
据粗略预估,微信小程序和百度小程序,有至少90%以上的相似代码,而且api的参数和返回的数据都是一致的,有一些不一致的将做如下介绍:.wxml文件,改成后辍名.swan.wxss文件,改成后辍名为.c ...
- 百度小程序自定义通用toast组件
百度小程序Toast组件 author: @TiffanysBear 百度小程序自定义通用toast组件 BdToast百度小程序自定义通用组件-github地址 需求 手百小程序的toast仅支持在 ...
- 微信小程序转百度小程序代码
听说百度小程序开始出现手机端搜索流量,作为SEO一员,必须搞他.但是又奈何之前做的都是微信小程序,所以用php写了一个微信小程序转百度小程序代码. 修改文件后缀名 .wxml转换为.swan .wxs ...
- 如何申请百度小程序的appid(目前不支持个人账号申请)
一.搜索百度智能小程序,并使用百度账号登陆 填写相关资料进入审核阶段,审核成功即可进入百度小程序开发者后台.打开“智能小程序首页”-“设置”-“开发设置”, 查看百度小程序的 AppID
- thinkphp开发微信小程序后台流程
thinkphp开发微信小程序后台流程,简单分享一下微信开发流程 1,注册微信小程序账号 2,注册好后,登陆微信小程序,下载微信小程序开发工具 3,用thinkphp开发企业后台,前台数据用json返 ...
- 百度小程序-form表单点击提交,input框内容不会清空
百度小程序与微信小程序相似度90%.微信小程序转换为百度小程序,部分还是需要人工修改! 做了一个form留言表单,点击提交之后,input框第一次会清空,但是第二次就不会清空了! 不多说直接上代码! ...
随机推荐
- python之 小甲鱼教程 Easygui 篇
博客转自 https://blog.csdn.net/bestallen/article/details/51933427 终于有点实质性可以看到摸到的界面了,搜了一下虽然easygui用的不多,但是 ...
- 【记录】【mysql】的REPLACE()用法
操作前数据 操作 UPDATE `test_replace` SET PASSWORD ') WHERE id REPLACE(PASSWORD, '1', '77')意思就是password中的1替 ...
- python综合作业要求
要求: 1.课程成绩数据(学号尾数为0,1同学完成) 至少要完成内容:分析每年不同班级平均成绩情况.不同年份总体平均成绩情况.不同性别学生成绩情况,并用一定图表展示. 2.集美大学各省录取分数数据(学 ...
- centos 7 下使用jexus 配置ASP.NET Core
1.安装jexus Jexus独立版(专业版)的安装 Jexus“独立版”指的是自带.net运行时(mono),不需要在客户服务器安装mono就能正常运行的Jexus版本,该版本只支持 64位Linu ...
- [转帖]记一次KUBERNETES/DOCKER网络排障
记一次KUBERNETES/DOCKER网络排障 https://coolshell.cn/articles/18654.html 记得之前在一个公众号里面看过这个文章 讲的挺好的.. 物理机直接跑d ...
- 手撕面试官系列(四 ):MongoDB+Redis 面试专题
MongoDB (面试题+答案领取方式见侧边栏) 你说的 NoSQL 数据库是什么意思?NoSQL 与 RDBMS 直接有什么区别?为什么要使用和不使用NoSQL 数据库?说一说 NoSQL 数据 ...
- 微信公众号开发 token 验证程序
<?php traceHttp(); define("TOKEN", "gmll001"); $wechatObj = new wechatCallbac ...
- BJFU-216-基于链式存储结构的图书信息表的修改
#include<stdio.h> #include<stdlib.h> #define MAX 100 typedef struct Book{ double no; cha ...
- leetcode的Hot100系列--347. 前 K 个高频元素--hash表+直接选择排序
这个看着应该是使用堆排序,但我图了一个简单,所以就简单hash表加选择排序来做了. 使用结构体: typedef struct node { struct node *pNext; int value ...
- NOI2019 退役记
最终还是在意料之中退役了. 总的来说,这一年确实曲折坎坷,曾踏足山巅,也曾陷入低谷,二者都让我受益良多. 没有太多不甘,水平已经正常发挥,哪敢还有一丝奢求. 省选时其实已经早就做好退役的准备了,但命运 ...