cgp php,Thinkphp内核百度小程序输出接口

最近百度小程序比较火,自己站点用thinkphp打造的,所以写了这个Thinkphp的百度小程序输出接口,实现数据同步。

附上代码

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('//', $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);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值