Skip to content

Commit

Permalink
增加公众号文章属性
Browse files Browse the repository at this point in the history
修复 function_exist bug
增加公众号文章属性
修复公众号消息描述为空报错
  • Loading branch information
Hanson authored Jun 4, 2017
2 parents a97bfce + 2572091 commit 4a9a4eb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
31 changes: 29 additions & 2 deletions src/Message/Official.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

namespace Hanson\Vbot\Message;

use Illuminate\Support\Arr;

class Official extends Message implements MessageInterface
{
const TYPE = 'official';
Expand All @@ -18,6 +20,8 @@ class Official extends Message implements MessageInterface

private $url;

private $articles;

private $app;

public function make($msg)
Expand All @@ -32,7 +36,8 @@ protected function afterCreate()
$info = (array) $array['appmsg'];

$this->title = $info['title'];
$this->description = $info['des'];
$this->description = (string) $info['des'];
$this->articles = $this->getArticles($info);

$appInfo = (array) $array['appinfo'];

Expand All @@ -43,11 +48,33 @@ protected function afterCreate()

protected function getExpand():array
{
return ['title' => $this->title, 'description' => $this->description, 'app' => $this->app, 'url' => $this->url];
return ['title' => $this->title, 'description' => $this->description, 'app' => $this->app, 'url' => $this->url,
'articles' => $this->articles, ];
}

protected function parseToContent(): string
{
return '[公众号消息]';
}

private function getArticles($info)
{
if ($m = (array) Arr::get($info, 'mmreader') and isset($m['category'])) {
$articles = [];

foreach ($m['category'] as $key => $article) {
if ($key === 'item') {
$articles[] = [
'title' => (string) Arr::get((array) $article, 'title'),
'cover' => (string) Arr::get((array) $article, 'cover'),
'url' => (string) Arr::get((array) $article, 'url'),
];
}
}

return $articles;
}

return [];
}
}
2 changes: 1 addition & 1 deletion src/Support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use Hanson\Vbot\Foundation\Vbot;

if (!function_exists('app')) {
if (!function_exists('vbot')) {
/**
* Get the available container instance.
*
Expand Down

0 comments on commit 4a9a4eb

Please sign in to comment.