-
Notifications
You must be signed in to change notification settings - Fork 0
/
menuCreate.php
86 lines (79 loc) · 2.54 KB
/
menuCreate.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
<?php
header("Content-type: text/html; charset=UTF-8");
$AppID='wx617cebc36f07f558';
$AppSecret='ed3f8afe3655a8d2cd4bfefaac55115a';
$token_url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$AppID."&secret=".$AppSecret;
$access_token=getAccessToken($token_url);
$result=createMenu($access_token);
echo $result;
function getAccessToken($token_url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $token_url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
// curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$tmpInfo = curl_exec($ch);
if (curl_errno($ch)) {
echo curl_error($ch);
exit;
}
curl_close($ch);
$tempResult=json_decode($tmpInfo)->access_token;
return $tempResult;
}
function createMenu($access_token){
$post_data='{
"button":[
{
"type":"click",
"name":"行情",
"key":"MENU_PRICE"
},
{
"type":"click",
"name":"随机推荐",
"key":"MENU_RECOMMEND"
},
{
"name":"更多",
"sub_button":[
{
"type":"click",
"name":"下载",
"key":"SUNMENU_DOWNLOAD"
},
{
"type":"click",
"name":"背景",
"key":"SUNMENU_BACKGROUND"
},
{
"type":"click",
"name":"所有公司",
"key":"SUBMENU_ALL"
}]
}]
}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
// curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$tmpInfo = curl_exec($ch);
if (curl_errno($ch)) {
echo curl_error($ch);
exit;
}
curl_close($ch);
return $tmpInfo;
}
?>