欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  微信小程序

微信开发系列教程(3)

程序员文章站 2022-03-17 14:22:10
...
因为微信现在可以开通自定义菜单,很多人都不知道如何创建自定义菜单。我今天来分享一下,自定菜单如何创建! 下面直接看代码:
<?php
//根据申请到的appid要获取access_toke值,https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=SECRET
$url = "http://api.weixin.qq.com/cgi-bin/menu/create?access_token=";
$jsonData = '{"button":[{"type":"click","name":"论坛","key":"FORUM"},{"type":"click","name":"发现","sub_button":[{"type":"click","name":"附近的人","key":"NEARBY_PEOPLE"},{"type":"click","name":"附近的帖子","key":"NEARBY_TOPIC"}],"key":"FIND"},{"name":"我","sub_button":[{"type":"click","name":"我的资料","key":"MY_PROFILE"},{"type":"click","name":"我的积分","key":"MY_POINTS"},{"type":"click","name":"我的帖子","key":"MY_TOPIC"}],"key":"MY"}]}'; //格式按照微信api来写就行
echo "<pre>";
var_dump(post($url, $jsonData));
function post($url, $jsonData){
    $ch = curl_init($url) ;
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS,$jsonData);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    $result = curl_exec($ch) ;
    curl_close($ch) ;
    return $result;
}

运行成功之后,会出现

{"errcode":0,"errmsg":"ok"}

目前就分享给大家这多吧!像查询自定义菜单、删除等,这些就按照微信api讲得来就能实现!

以上就是微信开发系列教程(3)的详细内容,更多请关注其它相关文章!

相关标签: 微信开发