PHP如何实现微信公众号企业号自定义菜单接口-创新互联
小编给大家分享一下PHP如何实现微信公众号企业号自定义菜单接口,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!
创新互联建站不只是一家网站建设的网络公司;我们对营销、技术、服务都有自己独特见解,公司采取“创意+综合+营销”一体化的方式为您提供更专业的服务!我们经历的每一步也许不一定是最完美的,但每一步都有值得深思的意义。我们珍视每一份信任,关注我们的做网站、成都做网站质量和服务品质,在得到用户满意的同时,也能得到同行业的专业认可,能够为行业创新发展助力。未来将继续专注于技术创新,服务升级,满足企业一站式营销型网站建设需求,让再小的品牌网站建设也能产生价值!具体如下:
define(AppId, "wx666cae44xxxxxx2");//定义AppId,需要在微信公众平台申请自定义菜单后会得到 define(AppSecret, "d77026a714d443a01d0229xxxxxxxx");//定义AppSecret,需要在微信公众平台申请自定义菜单后会得到 include("menu.php");//引入微信类 $wechatObj = new Wechat();//实例化微信类 $creatMenu = $wechatObj->creatMenu();//创建菜单
微信类(menu.php)代码
class Wechat { private function getAccessToken() //获取access_token { $url = "/tupian/20230522/token $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":"/tupian/20230522/soft.html" }, { "type":"view", "name":"分销B型", "url":"/tupian/20230522/soft.html" },{ "type":"view", "name":"地接批发", "url":"/tupian/20230522/soft.html" },{ "type":"view", "name":"精简组团", "url":"/tupian/20230522/soft.html" },{ "type":"view", "name":"直客网站", "url":"/tupian/20230522/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":"/tupian/20230522/about.html" }, { "type":"view", "name":"公司新闻", "url":"/tupian/20230522/" }, { "type":"view", "name":"联系我们", "url":"/tupian/20230522/contact.html" } ] } ] }'; $menuPostUrl = "/tupian/20230522/create $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; } ?>
看完了这篇文章,相信你对“PHP如何实现微信公众号企业号自定义菜单接口”有了一定的了解,如果想了解更多相关知识,欢迎关注创新互联行业资讯频道,感谢各位的阅读!
本文标题:PHP如何实现微信公众号企业号自定义菜单接口-创新互联
文章起源:http://scyanting.com/article/djhohd.html