WeChat development tutorial series (3)

高洛峰
Release: 2017-03-31 14:22:16
Original
1858 people have browsed it

Because WeChat can now open custom menus, many people don’t know how to create custom menus. Today I will share how to create a custom menu! Let’s look at the code directly:

<?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 = &#39;{"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"}]}&#39;; //格式按照微信api来写就行
echo "<pre class="brush:php;toolbar:false">";
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(&#39;Content-Type: application/json&#39;));
    $result = curl_exec($ch) ;
    curl_close($ch) ;
    return $result;
}
Copy after login

After successful operation,

{"errcode":0,"errmsg":"ok"}
Copy after login

will appear. I’ll share this with you now! Such as querying custom menus, deleting, etc., these can be realized according to the WeChat API!

The above is the detailed content of WeChat development tutorial series (3). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!