-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdefaultweixin.php
More file actions
337 lines (305 loc) · 10.8 KB
/
defaultweixin.php
File metadata and controls
337 lines (305 loc) · 10.8 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<?php
require 'weixin.class.php';
$flag=0;
ob_start();
header("content-type:text/xml;charset=utf-8");
if($_GET['code']){
$flag=1;
$ret = wxmessage::getAuthToken($_GET['code']);
if(isset($ret['openid'])){
$openid = $ret['openid'];
}
$sessionId = md5($openid);
session_id($sessionId);
session_start();
$_SESSION['user_id']=$sessionId;
}
else {
session_start();
}
$user_id=$_SESSION['user_id'];
class DefaultWeixin extends wxmessage {
public function processRequest($data) {
// $input is the content that user inputs
$input = $data->Content;
// deal with text msg from user
if ($this->isTextMsg()) {
switch ($input) {
case 'subscribe'://new user subscribes
$this->welcome();
break;
case 'Hello2BizUser'://only available before March 26,2013
$this->welcome();
break;
case 'news'://news
$this->fulinews();
break;
case 'music':
$this->yishengmusic();
break;
case 'joke':
$this->xiaohua();
break;
case 'aipinpin':
$this->aboutUs();
break;
case 'myinit':
$this->re_activity_initiate($data);
break;
case 'myjoin':
$this->re_activity_join($data);
break;
case 'myactivity':
$this->re_activity($data);
break;
default:
$this->text($input);
break;
}
}
// deal with geographical location
elseif ($this->isLocationMsg()) {
$this->fulinews();
} elseif ($this->isImageMsg()) {
$this->fulinews();
} elseif ($this->isLinkMsg()) {
$this->fulinews();
} elseif ($this->isEventMsg()) {
switch ($data->Event) {
//when user pressed button
case "CLICK":
$this->click($data);
break;
//case "JOIN":
}
} else {
}
}
/**
* Event message(button)
*/
private function click($data) {
$eventKey = $data->EventKey;
switch ($eventKey) {
case 'PUBLISH'://处理发布活动
$this->gopublish($data);
break;
}
}
private function gopublish($data) {
$post = array(
array(
'title' => '拼好活动',
'discription' => '现在发布吧',
'picurl' => 'https://raw.githubusercontent.com/ZhangQiaolun/PingPing/master/pic/party.jpg',
'url' => 'http://lovepingping.applinzi.com/publish.php?user=' .$data->FromUserName,
)
);
$this->outputNews($post);
}
/**
* return news
*/
private function fulinews() {
$text = 'QQ黄钻、蓝钻、红钻、绿钻或10Q币任选其一';
$posts = array(
array(
'title' => '福利来了',
'description' => $text,
'picurl' => 'http://mmsns.qpic.cn/mmsns/XWia2Xj7RZ8mhQaESostBicFaX2HjVBbJYKKCBk9PkuicKrSZdfNL7XAw/0',
'url' => 'http://mp.weixin.qq.com/mp/appmsg/show?__biz=MjM5MDE4Njg2MQ==&appmsgid=10000009&itemidx=1#wechat_redirect',
)
);
$xml = $this->outputNews($posts);
header('Content-Type: application/xml');
echo $xml;
}
/**
* return text
*/
private function text($text) {
$xml = $this->outputText($text);
header('Content-Type: application/xml');
echo $xml;
}
/**
* return joke
*/
private function xiaohua() {
$text = "你好,亲爱的朋友,我可能不在电脑旁。先看个笑话吧。\n朋友A:其实咱们和历史名人没啥区别,我要是活在几千年前,没准也是个名人。\n朋友B:你这么说就错了。\nA:怎么了?\nB:苹果砸在牛顿的头上,牛顿发现了万有引力定律;苹果砸在你的头上,你只会觉得这个苹果吃起来味道真不错。";
$xml = $this->outputText($text);
header('Content-Type: application/xml');
echo $xml;
}
/**
* return aipinpin
*/
private function aboutUs() {
$text = "爱拼拼是一个在线的拼团平台。您可以在这里发布活动,召集志同道合的小伙伴一起吃喝玩乐,或者约图自习。希望爱拼拼能给您的校园生活带来便利与舒心!\n输入以下信息获取回复:\n1、myactivity获得您的活动信息\n2、myjoin获得您加入的活动信息\n3、myinit获得您发起的活动信息\n4、joke\n5、music\n6、news";
$xml = $this->outputText($text);
header('Content-Type: application/xml');
echo $xml;
}
/**
* return myinit
*/
private function re_activity_initiate($data){
$mysql = new SaeMysql();
$sql1 = "SELECT activity_id
FROM activity_user_joiner
WHERE user_id = '$openid'
ORDER BY activity_time desc";
$result1 = $mysql->getData($sql1);
//如果还没有发起过活动
if (empty($result1)){
$text = "您还没有发起过活动,现在开始发布一个活动吧!";
$xml = $this->outputText($text);
header('Content-Type: application/xml');
echo $xml;
}
//已经发布过活动
else{
$sql2 = "SELECT *
FROM activity
WHERE id = '$result1[0]['activity_id']'";
$result2 = $mysql->getData($sql2);
$posts = array(
array(
'title' => '我发起的活动',
'discription' => "活动名称:".$result2[0]['activity_name']."n".
"活动时间:".$result2[0]['activity_time']."\n".
"活动地点:".$result2[0]['activity_place']."\n".
"活动描述:".$result2[0]['activity_describe']."\n",
)
);
$xml = $this->outputNews($posts);
header('Content-Type: application/xml');
echo $xml;
}
}
/**
* return myjoin
*/
private function re_activity_join($data){
$mysql = new SaeMysql();
$sql1 = "SELECT activity_id
FROM activity_user_joiner
WHERE joiner_id = '$openid'
ORDER BY activity_time desc";
$result1 = $mysql->getData($sql1);
//如果还没有参加过活动
if (empty($result1)){
$text = "您还没有参加过活动,现在开始参加一个活动吧!";
$xml = $this->outputText($text);
header('Content-Type: application/xml');
echo $xml;
}
//已经参加过活动
else{
$sql2 = "SELECT *
FROM activity
WHERE id = '$result1[0]['activity_id']'";
$result2 = $mysql->getData($sql2);
$posts = array(
array(
'title' => '我加入的活动',
'discription' => "活动名称:".$result2[0]['activity_name']."\n".
"活动时间:".$result2[0]['activity_time']."\n".
"活动地点:".$result2[0]['activity_place']."\n".
"活动描述:".$result2[0]['activity_describe']."\n",
)
);
$xml = $this->outputNews($posts);
header('Content-Type: application/xml');
echo $xml;
}
}
/**
* return myactivity
*/
private function re_activity($data){
$mysql = new SaeMysql();
$sql1 = "SELECT activity_id
FROM activity_user_joiner
WHERE user_id = '$openid' OR joiner_id = '$openid'
ORDER BY activity_time desc";
$result1 = $mysql->getData($sql1);
//如果还没有发起或参加活动
if (empty($result1)){
$text = "您还没有发起或参加过活动,现在开始尝试加入一个活动吧!";
$xml = $this->outputText($text);
header('Content-Type: application/xml');
echo $xml;
}
//已经有过活动信息
else{
$sql2 = "SELECT *
FROM activity
WHERE id = '$result1[0]['activity_id']'";
$result2 = $mysql->getData($sql2);
$posts = array(
array(
'title' => '即将开始的活动',
'discription' => "活动名称:".$result2[0]['activity_name']."\n".
"活动时间:".$result2[0]['activity_time']."\n".
"活动地点:".$result2[0]['activity_place']."\n".
"活动描述:".$result2[0]['activity_describe']."\n",
)
);
$xml = $this->outputNews($posts);
header('Content-Type: application/xml');
echo $xml;
}
}
/**
* return welcome msg
*/
private function welcome() {
$text = "亲爱的朋友,欢迎关注爱拼拼。回复“aipinpin”获得关于我们的信息吧!";
// outputText 用来返回文本信息
$xml = $this->outputText($text);
header('Content-Type: application/xml');
echo $xml;
}
private function music() {
$music = array(
'title' => '在春天里',
'discription' => '在春天里-汪峰',
'musicurl' => 'http://rubyeye-rubyeye.stor.sinaapp.com/inspring.wma',
'hdmusicurl' => 'http://rubyeye-rubyeye.stor.sinaapp.com/inspring.mp3'
);
$xml = $this->outputMusic($music);
//sae_log($xml);
header('Content-Type: application/xml');
echo $xml;
}
private function yishengmusic() {
$music = array(
'title' => '一生所爱',
'discription' => '为什么选这首歌呢?因为我的梦想是与一生所爱的人快乐一生。你的呢,亲爱的朋友?',
'musicurl' => 'http://rubyeye-rubyeye.stor.sinaapp.com/song/%E5%8D%A2%E5%86%A0%E5%BB%B7-%E4%B8%80%E7%94%9F%E6%89%80%E7%88%B1.mp3',
'hdmusicurl' => 'http://rubyeye-rubyeye.stor.sinaapp.com/song/%E5%8D%A2%E5%86%A0%E5%BB%B7-%E4%B8%80%E7%94%9F%E6%89%80%E7%88%B1.mp3'
);
$xml = $this->outputMusic($music);
header('Content-Type: application/xml');
echo $xml;
}
/**
* Pre processing,common usage:save the request into your database.
* Because weixin save your msgs only 5 days.
* @return boolean
*/
protected function beforeProcess($postData) {
return true;
}
protected function afterProcess() {
}
public function errorHandler($errno, $error, $file = '', $line = 0) {
$msg = sprintf('%s - %s - %s - %s', $errno, $error, $file, $line);
}
public function errorException(Exception $e) {
$msg = sprintf('%s - %s - %s - %s', $e->getCode(), $e->getMessage(), $e->getFile(), $e->getLine());
}
private function saveRequest($request) {
}
}