91 lines
2.5 KiB
PHP
91 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace Wechat\Work;
|
|
|
|
abstract class Message extends Base
|
|
{
|
|
|
|
const TYPE_TEXT = 'text';
|
|
const TYPE_IMAGE = 'image';
|
|
const TYPE_VOICE = 'voice';
|
|
const TYPE_VIDEO = 'video';
|
|
const TYPE_FILE = 'file';
|
|
const TYPE_TEXT_CARD = 'textcard';
|
|
const TYPE_NEWS = 'news';
|
|
const TYPE_MP_NEWS = 'mpnews';
|
|
|
|
protected $type;
|
|
protected $attr;
|
|
protected $safe;
|
|
|
|
protected $params;
|
|
|
|
abstract public function toArray();
|
|
|
|
public function ofAgent($agentId)
|
|
{
|
|
$this->params['agentid'] = $agentId;
|
|
return $this;
|
|
}
|
|
|
|
public function toUser($user)
|
|
{
|
|
$this->params['touser'] = $user;
|
|
return $this;
|
|
}
|
|
|
|
public function send()
|
|
{
|
|
$request = $this->transformForJsonRequest('POST', 'message/send',
|
|
$this->toArray());
|
|
$resp = $this->client->send($request);
|
|
return json_decode($resp->getBody(), true);
|
|
}
|
|
|
|
// {
|
|
// switch ($this->type) {
|
|
// case self::TYPE_TEXT:
|
|
// return [
|
|
// 'text' => [
|
|
// 'content' => $this->attr['content'],
|
|
// ]
|
|
// ];
|
|
// case self::TYPE_IMAGE:
|
|
// return [
|
|
// 'image' => [
|
|
// 'media_id' => $this->attr['media_id'],
|
|
// ]
|
|
// ];
|
|
// case self::TYPE_VOICE:
|
|
// return [
|
|
// 'voice' => [
|
|
// 'media_id' => $this->attr['media_id'],
|
|
// ]
|
|
// ];
|
|
// case self::TYPE_VIDEO:
|
|
// return [
|
|
// 'video' => [
|
|
// 'media_id' => $this->attr['media_id'],
|
|
// 'title' => $this->attr['title'],
|
|
// 'description' => $this->attr['description'],
|
|
// ]
|
|
// ];
|
|
// case self::TYPE_FILE:
|
|
// return [
|
|
// 'file' => [
|
|
// 'media_id' => $this->attr['media_id'],
|
|
// ]
|
|
// ];
|
|
// case self::TYPE_TEXT_CARD:
|
|
// $arr = [
|
|
// 'textcard' => [
|
|
// 'title' => $this->attr['title'],
|
|
// 'description' => $this->attr['description'],
|
|
// 'url' => $this->attr['url'],
|
|
// 'btntxt' => $this->attr['btntxt'],
|
|
// ]
|
|
// ];
|
|
// }
|
|
// }
|
|
|
|
} |