-
Notifications
You must be signed in to change notification settings - Fork 593
/
Action.php
107 lines (99 loc) · 3.64 KB
/
Action.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/**
* WeChatHelper Plugin
*
* @copyright Copyright (c) 2013 Binjoo (http://binjoo.net)
* @license GNU General Public License 2.0
*
*/
include_once 'Utils.php';
class WeChatHelper_Action extends Typecho_Widget implements Widget_Interface_Do
{
protected $db;
protected $options;
protected $user;
public function __construct($request, $response, $params = NULL)
{
parent::__construct($request, $response, $params);
/** 初始化数据库 */
$this->db = Typecho_Db::get();
/** 初始化常用组件 */
$this->options = $this->widget('Widget_Options');
$this->user = $this->widget('Widget_User');
}
public function execute() {}
public function valid() {
$echoStr = $this->request->get('echostr');
if($this->checkSignature($this->options->WCH_token)){
echo $echoStr;
exit;
}
}
private function checkSignature($token) {
$signature = $this->request->get('signature');
$timestamp = $this->request->get('timestamp');
$nonce = $this->request->get('nonce');
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr, SORT_STRING);
$tmpStr = implode($tmpArr);
$tmpStr = sha1($tmpStr);
if($tmpStr == $signature){
return true;
}else{
return false;
}
}
/**
* 数据
*
*/
public function postAction(){
Typecho_Widget::widget('WeChatHelper_Widget_WeChat')->action();
/*
$dir = __TYPECHO_ROOT_DIR__ . __TYPECHO_PLUGIN_DIR__ . '/WeChatHelper';
$myfile = $dir.'/wechatDebug.txt';
//echo $myfile;
$file_pointer = @fopen($myfile,"a");
@fwrite($file_pointer, $this->get_http_raw());
@fclose($file_pointer);
*/
}
public function action(){
if($this->request->is('valid')){
if($this->request->isGet()){
$this->valid();
}else if($this->request->isPost()){
$this->postAction();
}
}else if($this->request->is('config')){ //插件设置业务
Typecho_Widget::widget('WeChatHelper_Widget_Config')->action();
}else if($this->request->is('customreply')){ //自定义回复业务
Typecho_Widget::widget('WeChatHelper_Widget_CustomReply')->action();
}else if($this->request->is('users')){ //用户业务
Typecho_Widget::widget('WeChatHelper_Widget_Users')->action();
}else if($this->request->is('menus')){ //菜单业务
Typecho_Widget::widget('WeChatHelper_Widget_Menus')->action();
}
/*
if($this->request->isGet()){
$this->on($this->request->is('valid'))->valid();
if($this->request->is('users')){ //用户业务
Typecho_Widget::widget('WeChatHelper_Widget_Users')->action();
}
}
if($this->request->isPost()){
$this->on($this->request->is('valid'))->postAction();
if($this->request->is('config')){ //插件设置业务
Typecho_Widget::widget('WeChatHelper_Widget_Config')->action();
}else if($this->request->is('customreply')){ //自定义回复业务
Typecho_Widget::widget('WeChatHelper_Widget_CustomReply')->action();
}else if($this->request->is('users')){ //用户业务
Typecho_Widget::widget('WeChatHelper_Widget_Users')->action();
}else if($this->request->is('menus')){ //菜单业务
Typecho_Widget::widget('WeChatHelper_Widget_Menus')->action();
}
}
*/
}
}
?>