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框第一次会清空,但是第二次就不会清空了! 不多说直接上代码! ...
随机推荐
- [ARM-Linux开发]Linux下加载.ko驱动模块的两种方法:insmod与modprobe
假设要加载的驱动程序模块名为SHT21.ko 加载驱动模块 方法一: 进入SHT21.ko驱动模块文件所在的目录,然后直接 insmod SHT21.ko 即可 方法二: 将SHT21.ko文 ...
- unity 在editor编辑器下创建多个按钮
入坑最后发现就几句话,真是气死人了.发现自己掉坑里,脑子就变笨了,把代码贴给你们,保持大脑清醒. using System.Collections; using System.Collections. ...
- Endpoint is unreachable and there is no snapshot available for offline browsing
docker Portainer配置的时候出现这个错误:Endpoint is unreachable and there is no snapshot available for offline b ...
- 图论 --- 三维空间bfs
<传送门> [题目大意] 给你一个三维的迷宫,让你计算从入口走到出口最少步数. [题目分析] 其实和二维迷宫还是一样的,还是用队列来做,由于BFS算法一般是不需要回溯的,所以我们就用不着还 ...
- redis单机多节点集群
# ##安装Redis redis安装参考 https://www.cnblogs.com/renxixao/p/11442770.html Reids安装包里有个集群工具,要复制到/usr/loca ...
- Go基础编程实践(九)—— 网络编程
下载网页 package main import ( "io/ioutil" "net/http" "fmt" ) func main() ...
- python ---升级所有安装过的package
# -*- coding:utf8 -*- import pip from subprocess import call from pip._internal.utils.misc import ge ...
- linux安装好的mysql rpm -qa |grep mysql不见
输入: rpm -qa|grep -i mysql
- AutoFac的简单使用教程
Autofac可以对代码进行依赖注入,实现控制反转.以下是本菜鸟在初次入门时的代码配置,其源码,内部原理都还有待日后研究.目前也只是仅仅做到了能够使项目正常使用而已. 跟我一样刚刚入门的菜鸟朋友们可以 ...
- DotNet Core 2.2 MVC Razor 页面编译为 View.dll 文件的解决方法
使用文本文件编辑器打开项目文件,找到: <PropertyGroup> <TargetFramework>netcoreapp2.0</TargetFramewo ...