processor.php
3.95 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
<?php
/**
* 图文回复处理类
*
* [WeEngine System] Copyright (c) 2013 WE7.CC
*/
defined('IN_IA') or exit('Access Denied');
class we7_wxwallModuleProcessor extends WeModuleProcessor {
public $name = 'WxwallChatRobotModuleProcessor';
public function respond() {
if ($this->inContext) {
return $this->respText($this->post());
} else {
return $this->respText($this->register());
}
}
private function register() {
global $_W;
if (empty($_W['openid'])) {
return '请先关注公众号再来参加活动吧!';
}
$sql = 'SELECT * FROM ' . tablename('wxwall_reply') . ' WHERE `rid` = :rid';
$wall = pdo_fetch($sql, array(':rid' => $this->rule));
if (empty($wall)) {
return '微信墙活动不存在或已经被删除!';
}
$this->beginContext();
return empty($wall['enter_tips']) ? '欢迎进入微信墙,请发表话题哦!' : $wall['enter_tips'];
}
private function post() {
global $_W;
if (!in_array($this->message['msgtype'], array('text', 'image'))) {
return '微信墙只能发表文字和图片';
}
$member = $this->getMember();
$sql = 'SELECT * FROM ' . tablename('wxwall_reply') . ' WHERE `rid` = :rid';
$wall = pdo_fetch($sql, array(':rid' => $this->rule));
if ( intval($wall['timeout']) > 0 && ($wall['timeout'] + $member['lastupdate']) < TIMESTAMP ) {
$this->endContext();
return '由于您长时间未操作,请重新进入微信墙!';
}
$this->refreshContext();
if ( (empty($wall['quit_command']) && $this->message['content'] == '退出') ||
(!empty($wall['quit_command']) && $this->message['content'] == $wall['quit_command'])) {
$this->endContext();
return empty($wall['quit_tips']) ? '您已成功退出微信墙' : $wall['quit_tips'];
}
$data = array(
'rid' => $this->rule,
'from_user' => $_W['openid'],
'type' => $this->message['type'],
'createtime' => TIMESTAMP,
);
if (empty($wall['isshow']) && empty($member['isblacklist'])) {
$data['isshow'] = 1;
}
// 文字类型信息
if ($this->message['type'] == 'text') {
$data['content'] = $this->message['content'];
}
// 图片类型信息
if ($this->message['type'] == 'image') {
load()->func('file');
load()->func('communication');
$image = ihttp_request($this->message['picurl']);
$filename = 'images/' . $_W['uniacid'] . '/' . date('Y/m/') . md5(TIMESTAMP + CLIENT_IP + random(12)) . '.jpg';
file_write($filename, $image['content']);
$data['content'] = $filename;
}
pdo_insert('wxwall_message', $data);
if (!empty($member['isblacklist'])) {
$content = '你已被列入黑名单,发送的消息需要管理员审核!';
} elseif (!empty($wall['isshow'])) {
$content = '发送消息成功,请等待管理员审核';
} elseif(!empty($wall['send_tips'])) {
$content = $wall['send_tips'];
} else {
$content = '发送消息成功。';
}
return $content;
}
private function getMember() {
global $_W;
$sql = 'SELECT `lastupdate`, `isblacklist`, `rid` FROM ' . tablename('wxwall_members') . ' WHERE `from_user` =
:from_user AND `rid` = :rid';
$params = array(':from_user' => $_W['openid'], ':rid' => $this->rule);
$member = pdo_fetch($sql, $params);
// 获取粉丝头像
$account = WeAccount::create($_W['acid']);
$fansInfo = $account->fansQueryInfo($_W['openid']);
if (empty($member)) {
$member = array(
'from_user' => $_W['openid'],
'rid' => $this->rule,
'isjoin' => 1,
'lastupdate' => TIMESTAMP,
'isblacklist' => 0,
);
if (!is_error($fansInfo)) {
$member['avatar'] = rtrim($fansInfo['headimgurl'], '0') . '132';
}
pdo_insert('wxwall_members', $member);
} else {
if (!is_error($fansInfo)) {
$member['avatar'] = rtrim($fansInfo['headimgurl'], '0') . '132';
}
$member['lastupdate'] = TIMESTAMP;
$params = array('from_user' => $_W['openid'],'rid' => $this->rule);
pdo_update('wxwall_members', $member, $params);
}
return $member;
}
public function hookBefore() {
global $_W, $engine;
}
}