GroupMsg.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
<?php
/**
* GroupMsg.php
*
* @Author: Ghaoo
* @Date 2020/7/7 0007
*/
namespace Weasy\External\Api\Struct\ExternalContact;
use Weasy\External\Api\Struct\ExternalContact\Messages\ImageMsg;
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\Utils\Utils;
class GroupMsg
{
public $chat_type = "group";
public $sender = "";
public $external_userid = [];
/**
* @var TextMsg
*/
public $text = null;
/**
* @var ImageMsg
*/
public $image = null;
/**
* @var LinkMsg
*/
public $link = null;
/**
* @var MiniprogramMsg
*/
public $miniprogram = null;
static public function array2GroupMsg(array $arr)
{
$groupMsg = new GroupMsg();
if (array_key_exists("chat_type", $arr) && $chat_type = $arr['chat_type']) {
if (in_array($chat_type, ["single", "group"])) {
$groupMsg->chat_type = $chat_type;
if ($chat_type == "single") {
if (array_key_exists("external_userid", $arr) && $external_userid = $arr['external_userid']) {
if (is_array($external_userid)) {
$groupMsg->external_userid = $external_userid;
}
}
}
}
}
if (array_key_exists("sender", $arr) && $sender = $arr['sender']) {
$groupMsg->sender = $sender;
}
if (array_key_exists("text", $arr) && $text = $arr['text']) {
if (is_array($text)) {
$groupMsg->text = new TextMsg();
$groupMsg->text->content = Utils::arrayGet($text, 'content');
}
}
if (array_key_exists("image", $arr) && $image = $arr['image']) {
if (is_array($image)) {
$groupMsg->image = new ImageMsg();
$groupMsg->image->media_id = Utils::arrayGet($image, 'media_id');
}
}
if (array_key_exists("link", $arr) && $link = $arr['link']) {
if (is_array($link)) {
$groupMsg->link = new LinkMsg();
$groupMsg->link->title = Utils::arrayGet($link, 'title');
$groupMsg->link->picurl = Utils::arrayGet($link, 'picurl');
$groupMsg->link->desc = Utils::arrayGet($link, 'desc');
$groupMsg->link->url = Utils::arrayGet($link, 'url');
}
}
if (array_key_exists("miniprogram", $arr) && $miniprogram = $arr['miniprogram']) {
if (is_array($miniprogram)) {
$groupMsg->miniprogram = new MiniprogramMsg();
$groupMsg->miniprogram->title = Utils::arrayGet($miniprogram, 'title');
$groupMsg->miniprogram->pic_media_id = Utils::arrayGet($miniprogram, 'pic_media_id');
$groupMsg->miniprogram->appid = Utils::arrayGet($miniprogram, 'appid');
$groupMsg->miniprogram->page = Utils::arrayGet($miniprogram, 'page');
}
}
return $groupMsg;
}
}