MassSendApi::openidText()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 2
1
<?php
2
namespace Wechat\API;
3
4
/**
5
 * 高级群发接口.
6
 *
7
 * @author Tian.
8
 */
9
class MassSendApi extends BaseApi
10
{
11
12
    /**
13
     * ------------------------------------------------Group------------------------------------------------
14
     */
15
16
    /**
17
     * 图文消息
18
     *
19
     * @param  string  $media_id  用于群发的消息的media_id
20
     * @param  integer $group_id  群发到的分组的group_id,参加用户管理中用户分组接口,若is_to_all值为true,可不填写group_id
21
     * @param  boolean $is_to_all 用于设定是否向全部用户发送,选择true该消息群发给所有用户,选择false可根据group_id发送给指定群组的用户
22
     *
23
     * @return int       msg_id      发送出去的消息ID
24
     */
25 View Code Duplication
    public function allMpnews($media_id = '', $is_to_all = false, $group_id = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
    {
27
        $queryStr                        = [];
28
        $queryStr['filter']['is_to_all'] = $is_to_all;
29
        if ($is_to_all == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
30
            $queryStr['filter']['group_id'] = $group_id;
31
        }
32
        $queryStr['mpnews']['media_id'] = $media_id;
33
        $queryStr['msgtype']            = 'mpnews';
34
35
        $this->module = 'message';
36
37
        $res = $this->_post('mass/sendall', $queryStr);
38
39
        return $res;
40
    }
41
42
    /**
43
     * 文本消息
44
     *
45
     * @param  string  $content   文字
46
     * @param  integer $group_id  群发到的分组的group_id,参加用户管理中用户分组接口,若is_to_all值为true,可不填写group_id
47
     * @param  boolean $is_to_all 用于设定是否向全部用户发送,选择true该消息群发给所有用户,选择false可根据group_id发送给指定群组的用户
48
     *
49
     * @return int       msg_id      发送出去的消息ID
50
     */
51 View Code Duplication
    public function allText($content = '', $is_to_all = false, $group_id = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
52
    {
53
        $queryStr                        = [];
54
        $queryStr['filter']['is_to_all'] = $is_to_all;
55
        if ($is_to_all == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
56
            $queryStr['filter']['group_id'] = $group_id;
57
        }
58
        $queryStr['text']['content'] = $content;
59
        $queryStr['msgtype']         = 'text';
60
61
        $this->module = 'message';
62
63
        $res = $this->_post('mass/sendall', $queryStr);
64
65
        return $res;
66
    }
67
68
    /**
69
     * 语音(注意此处media_id需通过基础支持中的上传下载多媒体文件来得到)
70
     *
71
     * @param  string  $media_id  用于群发的消息的media_id
72
     * @param  integer $group_id  群发到的分组的group_id,参加用户管理中用户分组接口,若is_to_all值为true,可不填写group_id
73
     * @param  boolean $is_to_all 用于设定是否向全部用户发送,选择true该消息群发给所有用户,选择false可根据group_id发送给指定群组的用户
74
     *
75
     * @return int       msg_id      发送出去的消息ID
76
     */
77 View Code Duplication
    public function allVoice($media_id = '', $is_to_all = false, $group_id = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
78
    {
79
        $queryStr                        = [];
80
        $queryStr['filter']['is_to_all'] = $is_to_all;
81
        if ($is_to_all == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
82
            $queryStr['filter']['group_id'] = $group_id;
83
        }
84
        $queryStr['voice']['media_id'] = $media_id;
85
        $queryStr['msgtype']           = 'voice';
86
87
        $this->module = 'message';
88
89
        $res = $this->_post('mass/sendall', $queryStr);
90
91
        return $res;
92
    }
93
94
    /**
95
     * 图片(注意此处media_id需通过基础支持中的上传下载多媒体文件来得到)
96
     *
97
     * @param  string  $media_id  用于群发的消息的media_id
98
     * @param  integer $group_id  群发到的分组的group_id,参加用户管理中用户分组接口,若is_to_all值为true,可不填写group_id
99
     * @param  boolean $is_to_all 用于设定是否向全部用户发送,选择true该消息群发给所有用户,选择false可根据group_id发送给指定群组的用户
100
     *
101
     * @return int       msg_id      发送出去的消息ID
102
     */
103 View Code Duplication
    public function allImage($media_id = '', $is_to_all = false, $group_id = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
104
    {
105
        $queryStr                        = [];
106
        $queryStr['filter']['is_to_all'] = $is_to_all;
107
        if ($is_to_all == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
108
            $queryStr['filter']['group_id'] = $group_id;
109
        }
110
        $queryStr['image']['media_id'] = $media_id;
111
        $queryStr['msgtype']           = 'image';
112
113
        $this->module = 'message';
114
115
        $res = $this->_post('mass/sendall', $queryStr);
116
117
        return $res;
118
    }
119
120
    /**
121
     * 视频(请注意,此处视频的media_id需通过POST请求到下述接口特别地得到)
122
     *
123
     * @param  string  $media_id  用于群发的消息的media_id
124
     * @param  integer $group_id  群发到的分组的group_id,参加用户管理中用户分组接口,若is_to_all值为true,可不填写group_id
125
     * @param  boolean $is_to_all 用于设定是否向全部用户发送,选择true该消息群发给所有用户,选择false可根据group_id发送给指定群组的用户
126
     *
127
     * @return int       msg_id      发送出去的消息ID
128
     */
129 View Code Duplication
    public function allMpvideo($media_id = '', $is_to_all = false, $group_id = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
130
    {
131
        $queryStr                        = [];
132
        $queryStr['filter']['is_to_all'] = $is_to_all;
133
        if ($is_to_all == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
134
            $queryStr['filter']['group_id'] = $group_id;
135
        }
136
        $queryStr['mpvideo']['media_id'] = $media_id;
137
        $queryStr['msgtype']             = 'mpvideo';
138
139
        $this->module = 'message';
140
141
        $res = $this->_post('mass/sendall', $queryStr);
142
143
        return $res;
144
    }
145
146
    /**
147
     * 卡券(注意图文消息的card_id需要通过上述方法来得到)
148
     *
149
     * @param  string  $card_id   card_id
150
     * @param  integer $group_id  群发到的分组的group_id,参加用户管理中用户分组接口,若is_to_all值为true,可不填写group_id
151
     * @param  boolean $is_to_all 用于设定是否向全部用户发送,选择true该消息群发给所有用户,选择false可根据group_id发送给指定群组的用户
152
     *
153
     * @return int       msg_id      发送出去的消息ID
154
     */
155 View Code Duplication
    public function allWxcard($card_id = '', $is_to_all = false, $group_id = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
156
    {
157
        $queryStr                        = [];
158
        $queryStr['filter']['is_to_all'] = $is_to_all;
159
        if ($is_to_all == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
160
            $queryStr['filter']['group_id'] = $group_id;
161
        }
162
        $queryStr['wxcard']['card_id'] = $card_id;
163
        $queryStr['msgtype']           = 'wxcard';
164
165
        $this->module = 'message';
166
167
        $res = $this->_post('mass/sendall', $queryStr);
168
169
        return $res;
170
    }
171
172
173
    /**
174
     * ------------------------------------------------Openid------------------------------------------------
175
     */
176
177
    /**
178
     * 图文消息
179
     *
180
     * @param  string $media_id 用于设定是否向全部用户发送,选择true该消息群发给所有用户,选择false可根据group_id发送给指定群组的用户
181
     * @param  array  $openids  填写图文消息的接收者,一串OpenID列表,OpenID最少2个,最多10000个
182
     *
183
     * @return int     msg_id     发送出去的消息ID
184
     */
185
    public function openidMpnews($media_id = '', $openids = [])
186
    {
187
        $queryStr                       = [];
188
        $queryStr['touser']             = $openids;
189
        $queryStr['mpnews']['media_id'] = $media_id;
190
        $queryStr['msgtype']            = 'mpnews';
191
192
        $this->module = 'message';
193
194
        $res = $this->_post('mass/send', $queryStr);
195
196
        return $res;
197
    }
198
199
    /**
200
     * 文本消息
201
     *
202
     * @param  string $content 文字
203
     * @param  array  $openids 填写图文消息的接收者,一串OpenID列表,OpenID最少2个,最多10000个
204
     *
205
     * @return int     msg_id     发送出去的消息ID
206
     */
207
    public function openidText($content = '', $openids = [])
208
    {
209
        $queryStr                    = [];
210
        $queryStr['touser']          = $openids;
211
        $queryStr['text']['content'] = $content;
212
        $queryStr['msgtype']         = 'text';
213
214
        $this->module = 'message';
215
216
        $res = $this->_post('mass/send', $queryStr);
217
218
        return $res;
219
    }
220
221
    /**
222
     * 语音(注意此处media_id需通过基础支持中的上传下载多媒体文件来得到)
223
     *
224
     * @param  string $media_id 用于群发的消息的media_id
225
     * @param  array  $openids  填写图文消息的接收者,一串OpenID列表,OpenID最少2个,最多10000个
226
     *
227
     * @return int     msg_id     发送出去的消息ID
228
     */
229
    public function openidVoice($media_id = '', $openids = [])
230
    {
231
        $queryStr                      = [];
232
        $queryStr['touser']            = $openids;
233
        $queryStr['voice']['media_id'] = $media_id;
234
        $queryStr['msgtype']           = 'voice';
235
236
        $this->module = 'message';
237
238
        $res = $this->_post('mass/send', $queryStr);
239
240
        return $res;
241
    }
242
243
    /**
244
     * 图片(注意此处media_id需通过基础支持中的上传下载多媒体文件来得到)
245
     *
246
     * @param  string $media_id 用于群发的消息的media_id
247
     * @param  array  $openids  填写图文消息的接收者,一串OpenID列表,OpenID最少2个,最多10000个
248
     *
249
     * @return int     msg_id     发送出去的消息ID
250
     */
251
    public function openidImage($media_id = '', $openids = [])
252
    {
253
        $queryStr                      = [];
254
        $queryStr['touser']            = $openids;
255
        $queryStr['image']['media_id'] = $media_id;
256
        $queryStr['msgtype']           = 'image';
257
258
        $this->module = 'message';
259
260
        $res = $this->_post('mass/send', $queryStr);
261
262
        return $res;
263
    }
264
265
    /**
266
     * 视频(请注意,此处视频的media_id需通过POST请求到下述接口特别地得到)
267
     *
268
     * @param  string $media_id 用于群发的消息的media_id
269
     * @param  array  $openids  填写图文消息的接收者,一串OpenID列表,OpenID最少2个,最多10000个
270
     * @param  string $title
271
     * @param  string $description
272
     *
273
     * @return string     msg_id     发送出去的消息ID
274
     */
275
    public function openidVideo($media_id = '', $openids = [], $title = '', $description = '')
276
    {
277
        $queryStr                      = [];
278
        $queryStr['touser']            = $openids;
279
        $queryStr['video']['media_id'] = $media_id;
280
281
        if (!empty($title)) {
282
            $queryStr['video']['title'] = $title;
283
        }
284
285
        if (!empty($description)) {
286
            $queryStr['video']['description'] = $description;
287
        }
288
289
        $queryStr['msgtype'] = 'video';
290
291
        $this->module = 'message';
292
293
        $res = $this->_post('mass/send', $queryStr);
294
295
        return $res;
296
    }
297
298
    /**
299
     * 卡券(注意图文消息的card_id需要通过上述方法来得到)
300
     *
301
     * @param  string $card_id card_id
302
     * @param  array  $openids 填写图文消息的接收者,一串OpenID列表,OpenID最少2个,最多10000个
303
     *
304
     * @return int     msg_id     发送出去的消息ID
305
     */
306
    public function openidWxcard($card_id = '', $openids = [])
307
    {
308
        $queryStr                      = [];
309
        $queryStr['touser']            = $openids;
310
        $queryStr['wxcard']['card_id'] = $card_id;
311
        $queryStr['msgtype']           = 'wxcard';
312
313
        $this->module = 'message';
314
315
        $res = $this->_post('mass/send', $queryStr);
316
317
        return $res;
318
    }
319
320
321
    /**
322
     * ------------------------------------------------预览接口------------------------------------------------
323
     */
324
325
    /**
326
     * 图文消息
327
     *
328
     * @param  string $media_id 用于设定是否向全部用户发送,选择true该消息群发给所有用户,选择false可根据group_id发送给指定群组的用户
329
     * @param  string $userid   接收消息用户对应该公众号的openid,该字段也可以改为towxname,以实现对微信号的预览
330
     * @param  string $type     接受用户 是 openid  还是 wxname
331
     *
332
     * @return int     msg_id     发送出去的消息ID
333
     */
334
    public function previewMpnews($media_id = '', $userid = '', $type = 'openid')
335
    {
336
        $queryStr = [];
337
338
        if ($type == 'towxname') {
339
            $queryStr['towxname'] = $userid;
340
        } else {
341
            $queryStr['touser'] = $userid;
342
        }
343
344
        $queryStr['mpnews']['media_id'] = $media_id;
345
        $queryStr['msgtype']            = 'mpnews';
346
347
        $this->module = 'message';
348
349
        $res = $this->_post('mass/preview', $queryStr);
350
351
        return $res;
352
    }
353
354
    /**
355
     * 文本消息
356
     *
357
     * @param  string $content 文字
358
     * @param  string $userid  接收消息用户对应该公众号的openid,该字段也可以改为towxname,以实现对微信号的预览
359
     * @param  string $type    接受用户 是 openid  还是 wxname
360
     *
361
     * @return int     msg_id     发送出去的消息ID
362
     */
363
    public function previewText($content = '', $userid = '', $type = 'openid')
364
    {
365
        $queryStr = [];
366
367
        if ($type == 'towxname') {
368
            $queryStr['towxname'] = $userid;
369
        } else {
370
            $queryStr['touser'] = $userid;
371
        }
372
373
        $queryStr['text']['content'] = $content;
374
        $queryStr['msgtype']         = 'text';
375
376
        $this->module = 'message';
377
378
        $res = $this->_post('mass/preview', $queryStr);
379
380
        return $res;
381
    }
382
383
    /**
384
     * 语音(注意此处media_id需通过基础支持中的上传下载多媒体文件来得到)
385
     *
386
     * @param  string $media_id 用于群发的消息的media_id
387
     * @param  string $userid   接收消息用户对应该公众号的openid,该字段也可以改为towxname,以实现对微信号的预览
388
     * @param  string $type     接受用户 是 openid  还是 wxname
389
     *
390
     * @return int     msg_id     发送出去的消息ID
391
     */
392
    public function previewVoice($media_id = '', $userid = '', $type = 'openid')
393
    {
394
        $queryStr = [];
395
396
        if ($type == 'towxname') {
397
            $queryStr['towxname'] = $userid;
398
        } else {
399
            $queryStr['touser'] = $userid;
400
        }
401
402
        $queryStr['voice']['media_id'] = $media_id;
403
        $queryStr['msgtype']           = 'voice';
404
405
        $this->module = 'message';
406
407
        $res = $this->_post('mass/preview', $queryStr);
408
409
        return $res;
410
    }
411
412
    /**
413
     * 图片(注意此处media_id需通过基础支持中的上传下载多媒体文件来得到)
414
     *
415
     * @param  string $media_id 用于群发的消息的media_id
416
     * @param  string $userid   接收消息用户对应该公众号的openid,该字段也可以改为towxname,以实现对微信号的预览
417
     * @param  string $type     接受用户 是 openid  还是 wxname
418
     *
419
     * @return int     msg_id     发送出去的消息ID
420
     */
421
    public function previewImage($media_id = '', $userid = '', $type = 'openid')
422
    {
423
        $queryStr = [];
424
425
        if ($type == 'towxname') {
426
            $queryStr['towxname'] = $userid;
427
        } else {
428
            $queryStr['touser'] = $userid;
429
        }
430
431
        $queryStr['image']['media_id'] = $media_id;
432
        $queryStr['msgtype']           = 'image';
433
434
        $this->module = 'message';
435
436
        $res = $this->_post('mass/preview', $queryStr);
437
438
        return $res;
439
    }
440
441
    /**
442
     * 视频(请注意,此处视频的media_id需通过POST请求到下述接口特别地得到)
443
     *
444
     * @param  string $media_id 用于群发的消息的media_id
445
     * @param  string $userid   接收消息用户对应该公众号的openid,该字段也可以改为towxname,以实现对微信号的预览
446
     * @param  string $type     接受用户 是 openid  还是 wxname
447
     *
448
     * @return int     msg_id     发送出去的消息ID
449
     */
450
    public function previewMpvideo($media_id = '', $userid = '', $type = 'openid')
451
    {
452
        $queryStr = [];
453
454
        if ($type == 'towxname') {
455
            $queryStr['towxname'] = $userid;
456
        } else {
457
            $queryStr['touser'] = $userid;
458
        }
459
460
        $queryStr['mpvideo']['media_id'] = $media_id;
461
        $queryStr['msgtype']             = 'mpvideo';
462
463
        $this->module = 'message';
464
465
        $res = $this->_post('mass/preview', $queryStr);
466
467
        return $res;
468
    }
469
470
    /**
471
     * 卡券(注意图文消息的card_id需要通过上述方法来得到)
472
     *
473
     * @param  string $card_id card_id
474
     * @param  string $userid  接收消息用户对应该公众号的openid,该字段也可以改为towxname,以实现对微信号的预览
475
     * @param  string $type    接受用户 是 openid  还是 wxname
476
     *
477
     * @return int     msg_id     发送出去的消息ID
478
     */
479
    public function previewWxcard($card_id = '', $userid = '', $type = 'openid')
480
    {
481
        $queryStr = [];
482
483
        if ($type == 'towxname') {
484
            $queryStr['towxname'] = $userid;
485
        } else {
486
            $queryStr['touser'] = $userid;
487
        }
488
489
        $queryStr['wxcard']['card_id'] = $card_id;
490
        $queryStr['msgtype']           = 'wxcard';
491
492
        $this->module = 'message';
493
494
        $res = $this->_post('mass/preview', $queryStr);
495
496
        return $res;
497
    }
498
499
    /**
500
     * ------------------------------------------------删除群发------------------------------------------------
501
     */
502
503
    /**
504
     * 删除群发【订阅号与服务号认证后均可用】
505
     * 群发只有在刚发出的半小时内可以删除,发出半小时之后将无法被删除
506
     *
507
     * @param string $msg_id 发送出去的消息ID
508
     *
509
     * @return array|bool
510
     */
511
512
    public function delete($msg_id)
513
    {
514
        if (empty($msg_id)) {
515
            $this->setError('参数缺失');
516
517
            return false;
518
        }
519
520
        $queryStr           = [];
521
        $queryStr['msg_id'] = $msg_id;
522
523
        $this->module = 'message';
524
525
        $res = $this->_post('mass/delete', $queryStr);
526
527
        return $res;
528
    }
529
530
    /**
531
     * ------------------------------------------------查询群发消息发送状态------------------------------------------------
532
     */
533
534
    /**
535
     * 查询群发消息发送状态【订阅号与服务号认证后均可用】
536
     *
537
     * @param string $msg_id 发送出去的消息ID
538
     *
539
     * @return array|bool
540
     */
541
542
    public function massGet($msg_id)
543
    {
544
        if (empty($msg_id)) {
545
            $this->setError('参数缺失');
546
547
            return false;
548
        }
549
550
        $queryStr           = [];
551
        $queryStr['msg_id'] = $msg_id;
552
553
        $this->module = 'message';
554
555
        $res = $this->_post('mass/get', $queryStr);
556
557
        return $res;
558
    }
559
560
}