Client.php
5.66 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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?php
/**
* Created by PhpStorm.
* User: Ziy
* Date: 14/9/29
* Time: 下午5:15
*/
class YHMIm_Client
{
/**
* 原始发送消息
* @param array $mesData
*/
static function send(array $mesData)
{
$amqp = new YHMIm_Relay();
$amqp->exchange(YHMIm_Config::exchangeName);
$mesData = YHMIm_Agreement::factory($mesData)->getQueuePackageData();
$amqp->publish($mesData, YHMIm_Config::routeName);
$amqp->disconnect();
}
/**
* 图片消息
* @param $fromUid
* @param $toUid
* @param YHMIm_MessagesParam_YHMImage $body
* @throws Exception
*/
static function yhmImage($fromUid, $toUid, YHMIm_MessagesParam_YHMImage $body)
{
$mesData = array(
'to' => 'user:' . $toUid,
'from' => 'user:' . $fromUid,
'type' => 'yhm-image',
'body' => self::checkParam($body)
);
self::send($mesData);
}
/**
* 文字消息
* @param $fromUid
* @param $toUid
* @param $text
*/
static function yhmText($fromUid, $toUid, $text)
{
$mesData = array(
'to' => 'user:' . $toUid,
'from' => 'user:' . $fromUid,
'type' => 'yhm-text',
'body' => array(
'text' => $text
)
);
self::send($mesData);
}
/**
* 商品消息
* @param $fromUid
* @param $toUid
* @param YHMIm_MessagesParam_YHMProduct $body
* @throws Exception
*/
static function yhmProduct($fromUid, $toUid, YHMIm_MessagesParam_YHMProduct $body)
{
$mesData = array(
'to' => 'user:' . $toUid,
'from' => 'user:' . $fromUid,
'type' => 'yhm-product',
'body' => self::checkParam($body)
);
self::send($mesData);
}
/**
* 价格变更
* @param $fromUid
* @param $toUid
* @param YHMIm_MessagesParam_YHMProductChangePrice $body
* @throws Exception
*/
static function yhmProductChangePrice($fromUid, $toUid, YHMIm_MessagesParam_YHMProductChangePrice $body)
{
$mesData = array(
'to' => 'user:' . $toUid,
'from' => 'user:' . $fromUid,
'type' => 'yhm-product-change-price',
'body' => self::checkParam($body)
);
self::send($mesData);
}
/**
* 订单信息
* @param $fromUid
* @param $toUid
* @param YHMIm_MessagesParam_YHMOrderInfo $body
* @throws Exception
*/
static function yhmOrderInfo($fromUid, $toUid, YHMIm_MessagesParam_YHMOrderInfo $body)
{
$mesData = array(
'to' => 'user:' . $toUid,
'from' => 'user:' . $fromUid,
'type' => 'yhm-order-info',
'body' => self::checkParam($body)
);
self::send($mesData);
}
/**
* 关闭订单
* @param $fromUid
* @param $toUid
* @param YHMIm_MessagesParam_YHMOrderClose $body
* @throws Exception
*/
static function yhmOrderClose($fromUid, $toUid, YHMIm_MessagesParam_YHMOrderClose $body)
{
$mesData = array(
'to' => 'user:' . $toUid,
'from' => 'user:' . $fromUid,
'type' => 'yhm-order-close',
'body' => self::checkParam($body)
);
self::send($mesData);
}
/**
* 订单状态
* @param $fromUid
* @param $toUid
* @param YHMIm_MessagesParam_YHMOrderStatus $body
* @throws Exception
*/
static function yhmOrderStatus($fromUid, $toUid, YHMIm_MessagesParam_YHMOrderStatus $body)
{
$mesData = array(
'to' => 'user:' . $toUid,
'from' => 'user:' . $fromUid,
'type' => 'yhm-order-status',
'body' => self::checkParam($body)
);
self::send($mesData);
}
/**
* 投诉
* @param $fromUid
* @param $toUid
* @param YHMIm_MessagesParam_YHMComplain $body
* @throws Exception
*/
static function yhmComplain($fromUid, $toUid, YHMIm_MessagesParam_YHMComplain $body)
{
$mesData = array(
'to' => 'user:' . $toUid,
'from' => 'user:' . $fromUid,
'type' => 'yhm-order-complain',
'body' => self::checkParam($body)
);
self::send($mesData);
}
/**
* 降价通知
* @param $fromUid
* @param $toUid
* @param YHMIm_MessagesParam_YHMProductReducePrice $body
* @throws Exception
*/
static function yhmProductReducePrice($fromUid, $toUid, YHMIm_MessagesParam_YHMProductReducePrice $body)
{
$mesData = array(
'to' => 'user:' . $toUid,
'from' => 'user:' . $fromUid,
'type' => 'yhm-product-reduce-price',
'body' => self::checkParam($body)
);
self::send($mesData);
}
/**
* 商品消息
* @param $fromUid
* @param $toUid
* @param YHMIm_MessagesParam_YHMProduct $body
* @throws Exception
*/
static function yhmProductTxt($fromUid, $toUid, YHMIm_MessagesParam_YHMProductTxt $body)
{
$mesData = array(
'to' => 'user:' . $toUid,
'from' => 'user:' . $fromUid,
'type' => 'yhm-product-txt',
'body' => self::checkParam($body)
);
self::send($mesData);
}
/**
* 检查数据
* @param $body
* @throws Exception
*/
static private function checkParam($body)
{
$data = get_object_vars($body);
foreach ($data as $key => $val) {
if (is_null($val)) {
throw new Exception($key . ' Is Null.');
}
}
return $data;
}
}