-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
87 lines (76 loc) · 2.2 KB
/
index.php
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
<?php
/*
File: index.php
Author: [email protected]
Date: 2012.11.29
Usage: 公众平台的请求入口 + 示例(验证+消息)
*/
define("DEBUG", true);
define("TOKEN", "ym1623");
require_once(dirname(__FILE__) . "/wechat.php");
$w = new Wechat(TOKEN, DEBUG);
//首次验证,验证过以后可以删掉
if (isset($_GET['echostr'])) {
$w->valid();
exit(print_r($_REQUEST));
}
//回复用户
$w->reply("reply_cb");
//后续必要的处理...
/* TODO */
exit();
function reply_cb($request, $w)
{
print_r($request.'ha');
print_r($w);
if ($w->get_msg_type() == "location") {
return sprintf("你的位置:(%s, %s), 地址:%s",
$request['Location_X'], $request['Location_Y'], $request['Label']);
}
else if ($w->get_msg_type() == "image") { //echo back url
$PicUrl = $request['PicUrl'];
return "图片url:" . $PicUrl;
}
//else: Text
$content = trim($request['Content']);
if ($content === "Hello2BizUser") { //貌似第一次加入会发送这个
return "你好!";
}
if ($content !== "url") //发纯文本
{
//$w->set_funcflag(); //如果有必要的话,加星标,方便在web处理
if(!empty($content))
return "回复: " . $content;
else
return "请说点什么...";
}
else //发图文消息
{
//* 单个图文
return array(
"title" => "hello",
"description" => "world",
"pic" => "http://www.felix021.com/mm/pic/x.jpg",
"url" => "http://www.felix021.com/mm/test.php",
);
// */
/* 多个图文,并加星标
$w->set_funcflag();
return array(
array(
"title" => "a1",
"description" => "a1",
"pic" => "http://www.felix021.com/mm/pic/x.jpg",
"url" => "http://www.felix021.com/mm/test.php",
),
array(
"title" => "a2",
"description" => "a2",
"pic" => "http://www.felix021.com/mm/pic/fm.jpg",
"url" => "http://www.felix021.com/mm/test.php",
),
);
// */
}
}
?>