最近百度小程序比较火,自己站点用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. java 正则 replace 忽略大小写

    String description = model.getDescription(); if (!"".equals(description)) { //replace(/\&l ...

  2. DOM事件: DOM事件级别、DOM事件流、DOM事件模型、DOM事件捕获过程、自定义事件

    前端面试中只要问到事件,就肯定会有DOM事件:如果回答出来了,就会一直向下延申,其实这些东西都很简单,但我第一次被问到的时候,也是懵的: DOM事件级别: DOM0 element.onclick = ...

  3. ThinkPHP3验证码、文件上传、缩略图、分页(自定义工具类、session和cookie)

    验证码 TP框架中自带了验证码类 位置:Think/verify.class.php 在LoginController控制器中创建生存验证码的方法 login.html登陆模板中 在LoginCont ...

  4. LRU缓存实现

    LRU(Least recently used,最近最少使用)算法根据数据的历史访问记录来进行淘汰数据,其核心思想是“如果数据最近被访问过,那么将来被访问的几率也更高” 在java中可以采用Linke ...

  5. 030 SSM综合练习06--数据后台管理系统--SSM权限操作及Spring Security入门

    1.权限操作涉及的三张表 (1)用户表信息描述users sql语句: CREATE TABLE users ( id ) DEFAULT SYS_GUID () PRIMARY KEY, email ...

  6. 精通react之react-router4源码分析(100代码实现router功能)

    1.react-router4 是一个 react 组件 通过和 location / histroy 结合,来显示页面不同URL对应显示不同的组件 其中包含了三种路由.hash / boswer 等 ...

  7. jdk的下载路径和环境变量的配置

    一:jdk百度网盘的下载路径: 链接:https://pan.baidu.com/s/1pF41oGcTqouULsWKEBn3hw 提取码:p1y2 复制这段内容后打开百度网盘手机App,操作更方便 ...

  8. golang测试与性能调优

  9. JVM 参数调优配置

    在 tomcat 配置文件 tomcat/bin/catalina.sh 中 配置  JAVA_OPTS="-server -Xms2048m -Xmx2048m -Xss1024K -XX ...

  10. .net Dapper 实践系列(4) ---数据查询(Layui+Ajax+Dapper+MySQL)

    写在前面 上一小节,总结了数据显示时,会出现的日期问题.以及如何处理格式化日期.这个小节,主要总结的是使用Dapper 中的QueryMultiple方法依次显示查询多表的数据. 实践步骤 1.在Bo ...