php-wechat-sdk/src/Wechat/Work/Chat.php

82 lines
1.9 KiB
PHP
Raw Normal View History

2019-01-29 05:56:25 +00:00
<?php
namespace App\Wechat\Work;
class Chat extends Base
{
protected $id;
public function __construct($id = null)
{
parent::__construct();
$this->id = $id;
}
public function create(array $users, $owner = null, $name = null)
{
$params = [
'userlist' => $users,
];
if ($name) {
$params['name'] = $name;
}
if ($owner) {
$params['owner'] = $owner;
}
if ($this->id != null) {
$params['chatid'] = $this->id;
}
$request = $this->transformForJsonRequest('POST', 'appchat/create', $params);
$resp = $this->client->send($request);
return json_decode($resp->getBody(), true);
}
public function get($chatId)
{
$request = $this->transformForJsonRequest('GET', 'appchat/get?chatid=' . $chatId);
$resp = $this->client->send($request);
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 = [
'chatid' => $chatId,
];
if ($name) {
$params['name'] = $name;
}
if ($owner) {
$params['owner'] = $owner;
}
if ($add) {
$params['add_user_list'] = $add;
}
if ($del) {
$params['del_user_list'] = $del;
}
$request = $this->transformForJsonRequest('POST', 'appchat/update', $params);
$resp = $this->client->send($request);
return json_decode($resp->getBody(), true);
}
}