最近百度小程序比较火,自己站点用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内核百度小程序输出接口的更多相关文章

  1. 自动生成百度小程序sitemap.txt文件路径

    因为业务需要,需要在目前项目上开发一个百度小程序,百度智能小程序上线了,但是内容每天得推送,不可能一个小程序路径一个推送吧,因为小程序路径和项目路径不一致. 因为项目是用ThinkPHP开发的,在此附 ...

  2. 逐浪CMS+百度小程序开源包发布-对接海量资源助力推广

    接入百度小程序海量流量就在使用Zoomla!逐浪CMS开发栈 这里有最强的CMS内核依托于国家高新企业Zoomla!逐浪之上 这里有最海量的用户流量依托于百度小程序 这里有最开放的技术栈 这里有最卓越 ...

  3. 百度小程序button去掉默认边框

    百度小程序button去掉默认边框: button::after{ border:none; }

  4. 微信小程序转换为百度小程序

    据粗略预估,微信小程序和百度小程序,有至少90%以上的相似代码,而且api的参数和返回的数据都是一致的,有一些不一致的将做如下介绍:.wxml文件,改成后辍名.swan.wxss文件,改成后辍名为.c ...

  5. 百度小程序自定义通用toast组件

    百度小程序Toast组件 author: @TiffanysBear 百度小程序自定义通用toast组件 BdToast百度小程序自定义通用组件-github地址 需求 手百小程序的toast仅支持在 ...

  6. 微信小程序转百度小程序代码

    听说百度小程序开始出现手机端搜索流量,作为SEO一员,必须搞他.但是又奈何之前做的都是微信小程序,所以用php写了一个微信小程序转百度小程序代码. 修改文件后缀名 .wxml转换为.swan .wxs ...

  7. 如何申请百度小程序的appid(目前不支持个人账号申请)

    一.搜索百度智能小程序,并使用百度账号登陆 填写相关资料进入审核阶段,审核成功即可进入百度小程序开发者后台.打开“智能小程序首页”-“设置”-“开发设置”, 查看百度小程序的 AppID

  8. thinkphp开发微信小程序后台流程

    thinkphp开发微信小程序后台流程,简单分享一下微信开发流程 1,注册微信小程序账号 2,注册好后,登陆微信小程序,下载微信小程序开发工具 3,用thinkphp开发企业后台,前台数据用json返 ...

  9. 百度小程序-form表单点击提交,input框内容不会清空

    百度小程序与微信小程序相似度90%.微信小程序转换为百度小程序,部分还是需要人工修改! 做了一个form留言表单,点击提交之后,input框第一次会清空,但是第二次就不会清空了! 不多说直接上代码! ...

随机推荐

  1. [数据结构 - 第6章] 树之二叉排序树(C语言实现)

    一.什么是二叉排序树? 对于普通的顺序存储来说,插入.删除操作很简便,效率高:而这样的表由于无序造成查找的效率很低. 对于有序线性表来说(顺序存储的),查找可用折半.插值.斐波那契等查找算法实现,效率 ...

  2. PHP- 如何在终端输出带颜色的字体?

    转自: http://www.neatstudio.com/show-2568-1.shtml 终端显示颜色,在以前的想法当中,都是因为有了.profile的配色方案.而我一般也都是 采用默认的(sn ...

  3. VMware版本为15安装win7旗舰版不能成功安装VMware tools

    VMware版本为15安装win7旗舰版不能成功安装VMware tools 出现的问题: 一直报错说需要系统更新到SP1系统,到网上找了很多升级方式,都未果 直接通过Windows Update,未 ...

  4. day02——while、字符串格式化、运算符、编码初识

    day02 while--关键字(死循环) 格式:while 条件: ​ 循环体 print(1) while True: print("痒") print("鸡你太美& ...

  5. Linux基础(09)aio高级编程

    1.出于安全性 Linux有一个机制 应用层和内核层是无法互相直接读取内存的, 他们要互相读取数据是有一个拷贝过程的, 如: 应用层要读取内核层的数据就调用read(), 内核就会先把数据copy到一 ...

  6. 【实战经验】--Xilinx--IPcore--PLL生成

    用途: PLL用于产生自己想要的时钟,可以倍频有可以分频,通常倍频. 生成: 1.打开ISE—— Project —— New source,选择IP(CORE Generator & Arc ...

  7. VC++如何利用Matlab2014b的图形引擎进行绘图

    VC++如何利用Matlab的图形引擎 在Visual C++ 2015 工程中使用 Matlab2014b 提供的图形引擎进行绘图的详细过程. 问题来源: 有时候用C++写一些演示程序,有数据可视化 ...

  8. Mysql向新建表中插入数据, Incorrect string value: '\xE5\xBC\xA0\xE4\xB8\x89' for column 'UserName' at row 1

    在本地通过MYSQL创建测试表 CREATE Table User ( UserId int not NULL PRIMARY KEY auto_increment, //主键自增 UserName ...

  9. 题解 POJ 2559-SP1805 【HISTOGRA - Largest Rectangle in a Histogram】

    题目链接: https://www.luogu.org/problemnew/show/SP1805 http://poj.org/problem?id=2559 思路: ## 单调栈 首先如果所有矩 ...

  10. 分页工具类PageResult

    1.工具类 public class PageResult implements Serializable { private Long total;//总记录数 private List rows; ...