-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwechat.menu.class.php
More file actions
53 lines (53 loc) · 1.68 KB
/
Copy pathwechat.menu.class.php
File metadata and controls
53 lines (53 loc) · 1.68 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
<?php
/**
* wechat menu class by red 2014.1.24
*/
class wechatMenu
{
var $token;
function init($appid,$secret)
{
$url = sprintf("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s",$appid,$secret);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$token_str = curl_exec($ch);
$token_Obj = json_decode($token_str,true);
$this->token = $token_Obj['access_token'];
}
function set_menu($menu)
{
$post_url = sprintf("https://api.weixin.qq.com/cgi-bin/menu/create?access_token=%s",$this->token);
$ch = curl_init($post_url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $menu);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: '.strlen($menu))
);
$resultJson = curl_exec($ch);
$resultObj = json_decode($resultJson,true);
echo $resultObj['errmsg'];
}
function query_menu()
{
$url = sprintf("https://api.weixin.qq.com/cgi-bin/menu/get?access_token=%s",$this->token);
$ch =curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$menu_str = curl_exec($ch);
echo $menu_str;
}
function delete_menu()
{
$url = sprintf("https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=%s",$this->token);
$ch =curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$delete_str = curl_exec($ch);
$delete_Obj = json_decode($delete_str);
echo $delete_Obj['errmsg'];
}
}
?>