首頁  >  文章  >  微信小程式  >  微信開發系列教程(3)

微信開發系列教程(3)

高洛峰
高洛峰原創
2017-03-31 14:22:161789瀏覽

因為微信現在可以開通自訂選單,很多人都不知道如何建立自訂選單。我今天來分享一下,自定選單如何創建! 下面直接看程式碼:

<?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;
}

運行成功之後,會出現

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

目前就分享給大家這很多吧!像是查詢自訂選單、刪除等,這些就按照微信api講得來就能實現!

以上是微信開發系列教程(3)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn