微信開發教程(3)

由於微信如今能夠開通自定義菜單,不少人都不知道如何建立自定義菜單。我今天來分享一下,自定菜單如何建立! 下面直接看代碼:php

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


運行成功以後,會出現json

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

若是出現錯誤碼,能夠根據錯誤碼來分析錯誤! 微信api錯誤碼一覽表:http://mp.weixin.qq.com/wiki/index.php?title=%E8%BF%94%E5%9B%9E%E7%A0%81%E8%AF%B4%E6%98%8Eapi

目前就分享給你們這多吧!像查詢自定義菜單、刪除等,這些就按照微信api講得來就能實現! 微信

最後,若是你們有什麼不明白的,能夠直接給我留言!!app

相關文章
相關標籤/搜索