Skip to content
thenbsp edited this page Mar 3, 2016 · 2 revisions

消息实体

消息实体是用户在与公众号交互中,被动回复给用户的消息对象,有以下几种类型:

文字消息

use Thenbsp\Wechat\Message\Entity\Text;

$entity= new Text();
$entity->setContent('你好');

图片消息

use Thenbsp\Wechat\Message\Entity\Image;

$entity= new Image();
$entity->setMediaId('media id');

语音消息

use Thenbsp\Wechat\Message\Entity\Voice;

$entity= new Voice();
$entity->setMediaId('media id');

视频消息

use Thenbsp\Wechat\Message\Entity\Video;

$entity= new Video();
$entity->setMediaId('media id');
$entity->setTitle('video title');
$entity->setDescription('video description');

音乐消息

use Thenbsp\Wechat\Message\Entity\Music;

$entity= new Music();
$entity->setTitle('music title');
$entity->setDescription('music description');
$entity->setMusicUrl('music url');
$entity->setHQMusicUrl('HQ music url');
$entity->setThumbMediaId('thumb media id');

图文消息

use Thenbsp\Wechat\Message\Entity\Article;
use Thenbsp\Wechat\Message\Entity\ArticleItem;

$item1 = new ArticleItem();
$item1->setTitle('article 1 title');
$item1->setDescription('article 1 description');
$item1->setPicUrl('article 1 pic url');
$item1->setUrl('article 1 url');

$item2 = new ArticleItem();
$item2->setTitle('article 2 title');
$item2->setDescription('article 2 description');
$item2->setPicUrl('article 2 pic url');
$item2->setUrl('article 2 url');

$item3 = new ArticleItem();
$item3->setTitle('article 3 title');
$item3->setDescription('article 3 description');
$item3->setPicUrl('article 3 pic url');
$item3->setUrl('article 3 url');

$entity = new Article();
$entity->addItem($item1);
$entity->addItem($item2);
$entity->addItem($item3);