-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathReceive.php
152 lines (142 loc) · 4.11 KB
/
Receive.php
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
namespace WeChat;
use WeChat\Contracts\BasicPushEvent;
/**
* 公众号推送管理
* Class Receive
* @package WeChat
*/
class Receive extends BasicPushEvent
{
/**
* 转发多客服消息
* @param string $account
* @return $this
*/
public function transferCustomerService($account = '')
{
$this->message = [
'CreateTime' => time(),
'ToUserName' => $this->getOpenid(),
'FromUserName' => $this->getToOpenid(),
'MsgType' => 'transfer_customer_service',
];
empty($account) || $this->message['TransInfo'] = ['KfAccount' => $account];
return $this;
}
/**
* 设置文本消息
* @param string $content 文本内容
* @return $this
*/
public function text($content = '')
{
$this->message = [
'MsgType' => 'text',
'CreateTime' => time(),
'Content' => $content,
'ToUserName' => $this->getOpenid(),
'FromUserName' => $this->getToOpenid(),
];
return $this;
}
/**
* 设置回复图文
* @param array $newsData
* @return $this
*/
public function news($newsData = [])
{
$this->message = [
'CreateTime' => time(),
'MsgType' => 'news',
'Articles' => $newsData,
'ToUserName' => $this->getOpenid(),
'FromUserName' => $this->getToOpenid(),
'ArticleCount' => count($newsData),
];
return $this;
}
/**
* 设置图片消息
* @param string $mediaId 图片媒体ID
* @return $this
*/
public function image($mediaId = '')
{
$this->message = [
'MsgType' => 'image',
'CreateTime' => time(),
'ToUserName' => $this->getOpenid(),
'FromUserName' => $this->getToOpenid(),
'Image' => ['MediaId' => $mediaId],
];
return $this;
}
/**
* 设置语音回复消息
* @param string $mediaid 语音媒体ID
* @return $this
*/
public function voice($mediaid = '')
{
$this->message = [
'CreateTime' => time(),
'MsgType' => 'voice',
'ToUserName' => $this->getOpenid(),
'FromUserName' => $this->getToOpenid(),
'Voice' => ['MediaId' => $mediaid],
];
return $this;
}
/**
* 设置视频回复消息
* @param string $mediaid 视频媒体ID
* @param string $title 视频标题
* @param string $description 视频描述
* @return $this
*/
public function video($mediaid = '', $title = '', $description = '')
{
$this->message = [
'CreateTime' => time(),
'MsgType' => 'video',
'ToUserName' => $this->getOpenid(),
'FromUserName' => $this->getToOpenid(),
'Video' => [
'Title' => $title,
'MediaId' => $mediaid,
'Description' => $description,
],
];
return $this;
}
/**
* 设置音乐回复消息
* @param string $title 音乐标题
* @param string $desc 音乐描述
* @param string $musicurl 音乐地址
* @param string $hgmusicurl 高清音乐地址
* @param string $thumbmediaid 音乐图片缩略图的媒体id(可选)
* @return $this
*/
public function music($title, $desc, $musicurl, $hgmusicurl = '', $thumbmediaid = '')
{
$this->message = [
'CreateTime' => time(),
'MsgType' => 'music',
'ToUserName' => $this->getOpenid(),
'FromUserName' => $this->getToOpenid(),
'Music' => [
'Title' => $title,
'Description' => $desc,
'MusicUrl' => $musicurl,
'HQMusicUrl' => $hgmusicurl,
],
];
if ($thumbmediaid) {
$this->message['Music']['ThumbMediaId'] = $thumbmediaid;
}
return $this;
}
}