MessageFactory.php
2.96 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
<?php
/**
* Created by PhpStorm.
* User: HanSon
* Date: 2017/1/14
* Time: 11:54
*/
namespace Hanson\Vbot\Core;
use Hanson\Vbot\Message\Entity\Emoticon;
use Hanson\Vbot\Message\Entity\Image;
use Hanson\Vbot\Message\Entity\Location;
use Hanson\Vbot\Message\Entity\Message;
use Hanson\Vbot\Message\Entity\Recall;
use Hanson\Vbot\Message\Entity\Recommend;
use Hanson\Vbot\Message\Entity\RedPacket;
use Hanson\Vbot\Message\Entity\RequestFriend;
use Hanson\Vbot\Message\Entity\Share;
use Hanson\Vbot\Message\Entity\Text;
use Hanson\Vbot\Message\Entity\Touch;
use Hanson\Vbot\Message\Entity\Transfer;
use Hanson\Vbot\Message\Entity\Video;
use Hanson\Vbot\Message\Entity\Voice;
class MessageFactory
{
public function make($selector, $msg)
{
return $this->handleMessageByType($msg);
}
/**
* 处理消息类型
* @param $msg
* @return Message
*/
private function handleMessageByType($msg)
{
switch($msg['MsgType']){
case 1: //文本消息
if(Location::isLocation($msg)){
return new Location($msg);
}else{
return new Text($msg);
}
case 3: // 图片消息
return new Image($msg);
case 34: // 语音消息
return new Voice($msg);
case 43: // 视频
return new Video($msg);
case 47: // 动画表情
return new Emoticon($msg);
case 10002:
return new Recall($msg);
case 10000:
if(str_contains($msg['Content'], '利是') || str_contains($msg['Content'], '红包') || str_contains($msg['Content'], 'Red Packet')){
return new RedPacket($msg);
}
else if(str_contains($msg['Content'], '添加') || str_contains($msg['Content'], 'have added')){
# 添加好友
}
break;
case 49:
preg_match('/type>(\d+)<\/type/', $msg['Content'], $matches);
if($msg['Status'] == 3 && $msg['FileName'] === '微信转账'){
return new Transfer($msg);
}elseif($matches[1] === 5){
return new Share($msg);
}elseif($matches[1] === 33){
print_r('xcx');
// return new Share($msg);
}
case 37: // 好友验证
return new RequestFriend($msg);
case 42: //共享名片
return new Recommend($msg);
case 62:
//Video
break;
case 51:
if($msg['ToUserName'] === $msg['StatusNotifyUserName']){
return new Touch($msg);
}
break;
case 53:
//VideoCall
break;
default:
//Unknown
break;
}
}
}