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框第一次会清空,但是第二次就不会清空了! 不多说直接上代码! ...
随机推荐
- java修改文件所有者及其权限
1.设置所有者 管理文件所有者 Files.getOwner()和Files.setOwner()方法 要使用UserPrincipal来管理文件的所有者 (1)更改文件的所有者 import jav ...
- WIFI-Direct(Wifi直连)、AirPlay、DLAN、Miracast功能介绍
不知道大家对无线同屏技术有多少了解,当这种技术普及的时候,我想我们的工作与生活又会方便很多吧!下面是目前三种主流同屏技术的介绍: 目前这种将终端信号经由WiFi传输到电视.电视盒的技术有三种:DLNA ...
- AutoIt实现软件自动化安装
AutoIt下载安装 1.下载:https://www.autoitscript.com/site/autoit/downloads/ 2.安装,一直点下一步 3.安装好可以看到开始菜单如下(需要用到 ...
- 字符串A转换到字符串B,只能一次一次转换,每次转换只能把字符串A中的一个字符全部转换成另一个字符,是否能够转换成功
public class DemoTest { public static void main(String[] args) { System.)); } /** * 有一个字符串A 有一个字符串B ...
- golang学习笔记 ---常用第三方包
包的介绍 包类似Java中概念,jar是源代码管理,分发的最小单位. 目前多数包来自 Github官方包来自 golang.org/x/... 可以在如下网址查询到高频使用的第三方包清单https:/ ...
- 论文笔记:DeepCF
Abstract 推荐系统可以看作用户和物品的匹配问题,不过user以及item两者的语义空间差异太大,直接匹配不太符合实际.主流的改进CF的方法有两类:基于表示学习的CF方法以及基于函数学习的表示方 ...
- Ambari调整日志级别:How to enable debug logging in Ambari Server and Ambari Agent ?
PURPOSE When troubleshooting Ambari issues, it may be necessary to enable debug logging in the Ambar ...
- Linux 6 修改ssh默认远程端口号
linux 默认的ssh远程端口是22,有时默认端口会遭到别有用心的人们扫描或攻击,为了时我们的系统更加安全那就需要修改远程端口号 操作步骤:1.修改ssh_config配置文件 vim /etc/s ...
- selenium中元素操作之浏览器窗口滚动&网页日期控件操作(js操作)(五)
js的滚动条scrollIntoView() Arguments[] - python与js之间的羁绊 1.移动到元素element对象的“底端”,与当前窗口的“底部”对齐: driver.execu ...
- XXL-JOB使用命令行的方式启动python时,日志过多导致阻塞的解决方式
一.Runtime.getRuntime().exec()的阻塞问题 这个问题也不能算是XXL-JOB的问题,而是Java的Runtime.getRuntime().exec()造成的,Buffere ...