本文实例讲述了PHP实现微信公众号企业号自定义菜单接口。分享给大家供大家参考,具体如下:

define(AppId, "wx666cae44xxxxxx2");//定义AppId,需要在微信公众平台申请自定义菜单后会得到
define(AppSecret, "d77026a714d443a01d0229xxxxxxxx");//定义AppSecret,需要在微信公众平台申请自定义菜单后会得到
include("menu.php");//引入微信类
$wechatObj = new Wechat();//实例化微信类
$creatMenu = $wechatObj->creatMenu();//创建菜单

微信类(menu.php)代码

<"https://api.weixin.qq.com/cgi-bin/token".AppId."&secret=".AppSecret;
 $data = getCurl($url);//通过自定义函数getCurl得到https的内容
 $resultArr = json_decode($data, true);//转为数组
 return $resultArr["access_token"];//获取access_token
 }
 public function creatMenu()//创建菜单
 {
 $accessToken = $this->getAccessToken();//获取access_token
 $menuPostString = '{//构造POST给微信服务器的菜单结构体
 "button":[
   {
      "name":"产品介绍",
      "sub_button":[
      {
        "type":"view",
        "name":"分销A型",
        "url":"http://www.yourwebname.com/fenxiao/jianjie/soft.html"
      },
      {
        "type":"view",
        "name":"分销B型",
        "url":"http://www.yourwebname.com/fenxiaob/jianjie/soft.html"
      },{
        "type":"view",
        "name":"地接批发",
        "url":"http://www.yourwebname.com/dijie/jianjie/soft.html"
      },{
        "type":"view",
        "name":"精简组团",
        "url":"http://www.yourwebname.com/zutuan/jianjie/soft.html"
      },{
        "type":"view",
        "name":"直客网站",
        "url":"http://www.yourwebname.com/tripal/jianjie/soft.html"
      }]
    },
   {
      "name":"申请试用",
      "sub_button":[
      {
        "type":"click",
        "name":"分销A型",
        "key":"fxa"
      },
      {
        "type":"click",
        "name":"分销B型",
        "key":"fxb"
      },
      {
        "type":"click",
        "name":"地接批发",
        "key":"dj"
      },
      {
        "type":"click",
        "name":"精简组团",
        "key":"zutuan"
      },
      {
        "type":"click",
        "name":"直客网站",
        "key":"zhike"
      }
      ]
    },
      {
      "name":"博纵在线",
      "sub_button":[
      {
        "type":"view",
        "name":"企业介绍",
        "url":"http://www.yourwebname.com/about.html"
      },
      {
        "type":"view",
        "name":"公司新闻",
        "url":"http://www.yourwebname.com/news/company/"
      },
      {
        "type":"view",
        "name":"联系我们",
        "url":"http://www.yourwebname.com/contact.html"
      }
      ]
    }
    ]
 }';
 $menuPostUrl = "https://api.weixin.qq.com/cgi-bin/menu/create".$accessToken;//POST的url
 $menu = dataPost($menuPostString, $menuPostUrl);//将菜单结构体POST给微信服务器
 }
}
function getCurl($url){//get https的内容
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL,$url);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);//不输出内容
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
 $result = curl_exec($ch);
 curl_close ($ch);
 return $result;
}
function dataPost($post_string, $url) {//POST方式提交数据
 $context = array ('http' => array ('method' => "POST", 'header' => "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) \r\n Accept: */*", 'content' => $post_string ) );
 $stream_context = stream_context_create ( $context );
 $data = file_get_contents ( $url, FALSE, $stream_context );
 return $data;
}
"_blank" href="https://www.jb51.net/Special/556.htm">PHP微信开发技巧汇总》、《PHP编码与转码操作技巧汇总》、《PHP网络编程技巧总结》、《php字符串(string)用法总结》、《PHP中json格式数据操作技巧汇总》及《PHP针对XML文件操作技巧总结》

希望本文所述对大家PHP程序设计有所帮助。

华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com

稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!

昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。

这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。

而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?