-
Notifications
You must be signed in to change notification settings - Fork 23
/
Menu.php
113 lines (102 loc) · 3.21 KB
/
Menu.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
108
109
110
111
112
113
<?php
require_once (dirname(__FILE__) . '/Tools.php');
/**
* 微信企业号
* 自定义菜单管理
* @author faith [email protected]
* @createtime 2015-08-06 17:27:29
*/
class Menu {
private $token;
private $tools;
public function __construct($token) {
$this -> token = $token;
$this -> tools = new Tools();
}
/**
* 设置token
*/
public function setToken($token = NULL) {
$this -> token = $token;
}
/**
* 获取token
*/
public function getToken() {
return $this -> token;
}
/**
* 创建应用的自定义菜单
* @param $agent_id 企业应用ID
* @param $button_list 菜单列表,数组形式,具体格式参考微信文档,地址:http://qydev.weixin.qq.com/wiki/index.php?title=%E5%88%9B%E5%BB%BA%E5%BA%94%E7%94%A8%E8%8F%9C%E5%8D%95
*/
public function createMenu($agent_id, $button_list) {
if (intval($agent_id) < 0) {
return json_encode(array('success' => FALSE, 'errmsg' => 'Agent_id must be greater than zero!', 'errcode' => -2));
}
if (empty($button_list) || !is_array($button_list)) {
return json_encode(array('success' => FALSE, 'errmsg' => 'Button_list is invalid!', 'errcode' => -2));
}
$url = "https://qyapi.weixin.qq.com/cgi-bin/menu/create?access_token={$this->token}&agentid={$agent_id}";
$data = array('button'=>$button_list);
$result = $this -> tools -> httpRequest($url, $data, 'post');
if ($result) {
if ($result['errcode'] == 0) {
$result['success'] = TRUE;
return json_encode($result);
} else {
$result['success'] = FALSE;
return json_encode($result);
}
} else {
return json_encode(array('success' => FALSE, 'errmsg' => 'Query fails!', 'errcode' => -2));
}
}
/**
* 删除企业应用自定义菜单
* @param $agent_id 企业应用ID
*/
public function deleteMenu($agent_id) {
if (intval($agent_id) < 0) {
return json_encode(array('success' => FALSE, 'errmsg' => 'Agent_id must be greater than zero!', 'errcode' => -2));
}
$url = "https://qyapi.weixin.qq.com/cgi-bin/menu/delete";
$data = array('access_token'=>$this->token, 'agentid'=>$agent_id);
$result = $this -> tools -> httpRequest($url, $data);
if ($result) {
if ($result['errcode'] == 0) {
$result['success'] = TRUE;
return json_encode($result);
} else {
$result['success'] = FALSE;
return json_encode($result);
}
} else {
return json_encode(array('success' => FALSE, 'errmsg' => 'Query fails!', 'errcode' => -2));
}
}
/**
* 根据应用ID获取其自定义菜单
* @param $agent_id 企业应用ID
*/
public function getMenu($agent_id) {
if (intval($agent_id) < 0) {
return json_encode(array('success' => FALSE, 'errmsg' => 'Agent_id must be greater than zero!', 'errcode' => -2));
}
$url = "https://qyapi.weixin.qq.com/cgi-bin/menu/get";
$data = array('access_token'=>$this->token, 'agentid'=>$agent_id);
$result = $this -> tools -> httpRequest($url, $data);
if ($result) {
if (!isset($result['errcode'])) {
$result['success'] = TRUE;
return json_encode($result);
} else {
$result['success'] = FALSE;
return json_encode($result);
}
} else {
return json_encode(array('success' => FALSE, 'errmsg' => 'Query fails!', 'errcode' => -2));
}
}
}
/* End of file */