Home > Backend Development > PHP Tutorial > WeChat custom menu processing and development example_PHP tutorial

WeChat custom menu processing and development example_PHP tutorial

WBOY
Release: 2016-07-13 09:57:03
Original
869 people have browsed it

WeChat custom menu processing and development example

Creation of custom menu

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

define("APPID", "your appid");

define("APPSECRET", "your appsecret ");

$token_access_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . APPID . "&secret=" . APPSECRET;

$res = file_get_contents($token_access_url); //Get the file content or get the content of the network request

//echo $res;

$result = json_decode($res, true); //Accept a JSON format string and convert it into a PHP variable

$access_token = $result['access_token'];

define("ACCESS_TOKEN", $access_token); //Define access_token as a constant for ease of use.

$make_menu_url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" . ACCESS_TOKEN;

$menuData = ' {

"button":[

{

"type":"click",

"name":"Today's song",

"key":"V1001_TODAY_MUSIC"

},

{

"name":"menu",

"sub_button":[

{

"type":"view",

"name":"Search",

"url":"http://www.soso.com/"

},

{

"type":"view",

"name":"video",

"url":"http://v.qq.com/"

},

{

"type":"click",

"name":"Like us",

"key":"V1001_GOOD"

}]

}]

}';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $make_menu_url);

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 6.0; Windows NT 5.1; .NET CLR 1.1.4322)");

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt($ch, CURLOPT_AUTOREFERER, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $menuData);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

$info = curl_exec($ch);

//Determine whether there are errors during execution, and if so, send a data error report.

if (curl_errno($ch)) {

echo 'Error' . curl_error($ch); //User checks whether the curl module is enabled in the PHP running environment.

}

curl_close($ch);

print_r($info); //View the data returned after the post is submitted to the WeChat server.

Acquisition of custom menu

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

 

define("APPID", "您的appid");

define("APPSECRET", "您的appsecret ");

 

$token_access_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . APPID . "&secret=" . APPSECRET;

$res = file_get_contents($token_access_url); //获取文件内容或获取网络请求的内容

$result = json_decode($res, true); //接受一个 JSON 格式的字符串并且把它转换为 PHP 变量

$access_token = $result['access_token'];

 

$make_menu_url = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=" . $access_token;

 

$menu_json = file_get_contents($make_menu_url);

 

echo $menu_json;

1 2

3

4

5

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

 

define("APPID", "您的appid");

define("APPSECRET", "您的appsecret ");

 

$token_access_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . APPID . "&secret=" . APPSECRET;

$res = file_get_contents($token_access_url); //获取文件内容或获取网络请求的内容

$result = json_decode($res, true); //接受一个 JSON 格式的字符串并且把它转换为 PHP 变量

$access_token = $result['access_token'];

 

$make_menu_url = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=" . $access_token;

 

$menu_json = file_get_contents($make_menu_url);

 

echo $menu_json;

6 7 8

910 11 12 13 14 15
define("APPID", "your appid"); define("APPSECRET", "your appsecret "); $token_access_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . APPID . "&secret=" . APPSECRET; $res = file_get_contents($token_access_url); //Get the file content or get the content of the network request $result = json_decode($res, true); //Accept a JSON format string and convert it into a PHP variable $access_token = $result['access_token']; $make_menu_url = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=" . $access_token; $menu_json = file_get_contents($make_menu_url); echo $menu_json; Deletion of custom menu
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template