zoukankan      html  css  js  c++  java
  • 创建自定义菜单

    将下面代码写入一个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;
    }

  • 相关阅读:
    多线程:C#.NET中使用BackgroundWorker在模态对话框中显示进度条
    通过外接程序将Outlook邮件导出成Word文档
    [轉]FusionChartsFree参数说明
    MSIL学习资源
    FastCGI Error 2147467259 (0x80004005)
    编程实现双击某个文件用指定程序打开
    Excel api Enumerations 常量
    [轉]全面认识页面设置之PageSetup 对象
    AjaxFileUploaderV2.1增加可上传多个文件
    [轉]VB.NET and C# Comparison
  • 原文地址:https://www.cnblogs.com/wujuntian/p/4520242.html
Copyright © 2011-2022 走看看