WelcomeMsg.php
3.1 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
namespace Weasy\External\Api\Struct\ExternalContact;
use Weasy\External\Api\Struct\ExternalContact\Messages\LinkMsg;
use Weasy\External\Api\Struct\ExternalContact\Messages\MiniprogramMsg;
use Weasy\External\Api\Struct\ExternalContact\Messages\TextMsg;
use Weasy\External\Api\Struct\ExternalContact\Messages\ImageMsg;
use Weasy\External\Utils\Error\ParameterError;
use Weasy\External\Utils\Utils;
class WelcomeMsg
{
/**
* @var string
*/
public $welcome_code;
/**
* @var TextMsg
*/
public $text = null;
/**
* @var ImageMsg
*/
public $image = null;
/**
* @var LinkMsg
*/
public $link = null;
/**
* @var MiniprogramMsg
*/
public $miniprogram = null;
/**
* 数组to欢迎消息
*
* @param array $arr
*
* @return WelcomeMsg
*/
static public function array2WelcomeMsg(array $arr)
{
$welcomeMsg = new WelcomeMsg();
$welcomeMsg->welcome_code = Utils::arrayGet($arr, "welcome_code");
if (array_key_exists("text", $arr) && $text = $arr['text']) {
if (is_array($text)) {
$welcomeMsg->text = new TextMsg();
$welcomeMsg->text->content = Utils::arrayGet($text, 'content');
}
}
if (array_key_exists("image", $arr) && $image = $arr['image']) {
if (is_array($image)) {
$welcomeMsg->image = new ImageMsg();
$welcomeMsg->image->media_id = Utils::arrayGet($image, 'media_id');
}
}
if (array_key_exists("link", $arr) && $link = $arr['link']) {
if (is_array($link)) {
$welcomeMsg->link = new LinkMsg();
$welcomeMsg->link->title = Utils::arrayGet($link, 'title');
$welcomeMsg->link->picurl = Utils::arrayGet($link, 'picurl');
$welcomeMsg->link->desc = Utils::arrayGet($link, 'desc');
$welcomeMsg->link->url = Utils::arrayGet($link, 'url');
}
}
if (array_key_exists("miniprogram", $arr) && $miniprogram = $arr['miniprogram']) {
if (is_array($miniprogram)) {
$welcomeMsg->miniprogram = new MiniprogramMsg();
$welcomeMsg->miniprogram->title = Utils::arrayGet($miniprogram, 'title');
$welcomeMsg->miniprogram->pic_media_id = Utils::arrayGet($miniprogram, 'pic_media_id');
$welcomeMsg->miniprogram->appid = Utils::arrayGet($miniprogram, 'appid');
$welcomeMsg->miniprogram->page = Utils::arrayGet($miniprogram, 'page');
}
}
return $welcomeMsg;
}
/**
* 检查Args
*
* @param WelcomeMsg $welcomeMsg
*
* @throws ParameterError
*/
static public function checkArgs(WelcomeMsg $welcomeMsg)
{
Utils::checkNotEmptyStr($welcomeMsg->welcome_code, "welcome_code");
if (is_null($welcomeMsg->text) && is_null($welcomeMsg->image) && is_null($welcomeMsg->link) && is_null($welcomeMsg->miniprogram)) {
throw new ParameterError("text, image, link, and miniprogram cannot be empty at the same time");
}
}
}