Message.php
2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace Weasy\External\Api\Struct\Message;
use Weasy\External\Utils\Error\QyApiError;
use Weasy\External\Utils\Utils;
class Message
{
public $sendToAll = false; // bool, 是否全员发送, 即文档所谓 @all
public $touser = array(); // string array
public $toparty = array(); // uint array
public $totag = array(); // uint array
public $agentid = null; // uint
public $safe = null; // uint, 表示是否是保密消息,0表示否,1表示是,默认0
public $messageContent = null; // xxxMessageContent
/**
* @throws QyApiError
*/
public function CheckMessageSendArgs()
{
if (count($this->touser) > 1000) throw new QyApiError("touser should be no more than 1000");
if (count($this->toparty) > 100) throw new QyApiError("toparty should be no more than 100");
if (count($this->totag) > 100) throw new QyApiError("toparty should be no more than 100");
if (is_null($this->messageContent)) throw new QyApiError("messageContent is empty");
$this->messageContent->CheckMessageSendArgs();
}
/**
* @return array
*/
public function Message2Array()
{
$args = array();
if (true == $this->sendToAll) {
Utils::setIfNotNull("@all", "touser", $args);
} else {
//
$touser_string = null;
foreach ($this->touser as $item) {
$touser_string = $touser_string . $item . "|";
}
Utils::setIfNotNull($touser_string, "touser", $args);
//
$toparty_string = null;
foreach ($this->toparty as $item) {
$toparty_string = $toparty_string . $item . "|";
}
Utils::setIfNotNull($toparty_string, "toparty", $args);
//
$totag_string = null;
foreach ($this->totag as $item) {
$totag_string = $totag_string . $item . "|";
}
Utils::setIfNotNull($totag_string, "totag", $args);
}
Utils::setIfNotNull($this->agentid, "agentid", $args);
Utils::setIfNotNull($this->safe, "safe", $args);
$this->messageContent->MessageContent2Array($args);
return $args;
}
}