This commit is contained in:
候学杰 2019-02-20 16:28:32 +08:00
parent 06d17d9766
commit 2f75f83084
3 changed files with 18 additions and 12 deletions

View File

@ -4,18 +4,20 @@ namespace Wechat\Work;
use Wechat\Work\Message\MessageInterface;
class Chat extends Base
class Chat
{
protected $id;
protected $work;
public function __construct($id = null)
public function __construct($id, $work)
{
parent::__construct();
$this->work = $work;
$this->id = $id;
}
/**
* 发送消息
* @param $msg MessageInterface
* @return mixed
*/
@ -58,14 +60,6 @@ class Chat extends Base
return json_decode($resp->getBody(), true);
}
public function send(Message $message)
{
$request = $this->transformForJsonRequest('POST', 'appchat/send',
array_merge(['chatid' => $this->id], $message->toArray()));
$resp = $this->client->send($request);
return json_decode($resp->getBody(), true);
}
public function update($chatId, array $add = null, array $del = null, $name = null, $owner = null)
{
$params = [

View File

@ -16,7 +16,7 @@ abstract class MessageInterface
protected $type;
protected $params;
protected $params = [];
protected $attr;
public function toUser($user)

View File

@ -10,9 +10,21 @@ class Work extends Base
parent::__construct($config);
}
/**
* 消息推送
* @return Message
*/
public function message()
{
return new Message($this);
}
/**
* 群聊接口
*/
public function chat($id)
{
return new Chat($id, $this);
}
}