码迷,mamicode.com
首页 > 其他好文 > 详细

创建自定义菜单

时间:2015-05-21 19:10:45      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:

将下面代码写入一个php文件,然后在浏览器中运行即可为指定的公众号创建自定义菜单。

这里创建的都是view类按钮,将其中的‘链接’换成实际地址即可。(创建其他类型的按钮时原理一样)

$access_token = "公众号access_token";

$jsonmenu = ‘{
  "button":[
  {
    "type":"view",
    "name":"主按钮1",
    "url":"链接"
  },

  {
    "name":"主按钮2",
    "sub_button":[
    {
      "type":"view",
      "name":"子按钮",
      "url":"链接"
    },
    {
      "type":"view",
      "name":"子按钮",
      "url":"链接"
    },
    {
      "type":"view",
      "name":"子按钮",
      "url":"链接"
    }]
  },

  {
    "name":"主按钮3",
    "sub_button":[
    {
      "type":"view",
      "name":"子按钮",
      "url":"链接"
    },
    {
      "type":"view",
      "name":"子按钮",
      "url":"链接"
    }]
  }]
}‘;


$url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token;
$result = https_request($url, $jsonmenu);
var_dump($result);

function https_request($url,$data = null){
  $curl = curl_init();
  curl_setopt($curl, CURLOPT_URL, $url);
  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
  if (!empty($data)){
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  }
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  $output = curl_exec($curl);
  curl_close($curl);
  return $output;
}

创建自定义菜单

标签:

原文地址:http://www.cnblogs.com/wujuntian/p/4520242.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!