微信公眾號-建立選單列表
阿新 • • 發佈:2018-12-19
在開發微信公眾號時,需要建立自定義的選單列表,按照固定引數拼接即可,引數如下:
String param = "{\n" + "\t\"button\": [{\n" + "\t\t\t\"type\": \"click\",\n" + "\t\t\t\"name\": \"訂單管理\",\n" + "\t\t\t\"key\": \"ORDER\",\n" + "\t\t\t\"sub_button\": [{\n" + "\t\t\t\t\t\"type\": \"view\",\n" + "\t\t\t\t\t\"name\": \"待處理訂單\",\n" + "\t\t\t\t\t\"url\": \"http://授權地址/jump?path=實際頁面url\"\n" + "\t\t\t\t},\n" + "\t\t\t\t{\n" + "\t\t\t\t\t\"type\": \"view\",\n" + "\t\t\t\t\t\"name\": \"全部訂單\",\n" + "\t\t\t\t\t\"url\": \"http://授權地址/jump?path=實際頁面url\"\n" + "\t\t\t\t}, {\n" + "\t\t\t\t\t\"type\": \"view\",\n" + "\t\t\t\t\t\"name\": \"訂單查詢\",\n" + "\t\t\t\t\t\"url\": \"http://授權地址/jump?path=實際頁面url\"\n" + "\t\t\t\t}\n" + "\t\t\t]\n" + "\t\t},\n" + "\t\t{\n" + "\t\t\t\"type\": \"view\",\n" + "\t\t\t\"name\": \"機票管理\",\n" + "\t\t\t\"url\": \"http://授權地址/jump?path=實際頁面url\"\n" + "\t\t},\n" + "\t\t{\n" + "\t\t\t\"type\": \"click\",\n" + "\t\t\t\"name\": \"相關服務\",\n" + "\t\t\t\"key\": \"OTHER\",\n" + "\t\t\t\"sub_button\": [{\n" + "\t\t\t\t\t\"type\": \"click\",\n" + "\t\t\t\t\t\"name\": \"繫結賬號\",\n" + "\t\t\t\t\t\"key\": \"BIND_ACCOUN\"\n" + "\t\t\t\t},\n" + "\t\t\t\t{\n" + "\t\t\t\t\t\"type\": \"click\",\n" + "\t\t\t\t\t\"name\": \"退出登入\",\n" + "\t\t\t\t\t\"key\": \"QUIT\"\n" + "\t\t\t\t}\n" + "\t\t\t]\n" + "\t\t}\n" + "\t]\n" + "}";
http://授權地址/jump?path=實際頁面url
授權地址:是在微信公眾號服務端配置的授權地址,這樣就可以獲取到使用者資訊openid。
授權地址/jump:點選選單後跳轉連結,這個頁面用來獲取使用者資訊。
path=實際頁面url:後面的引數代表實際要跳轉的頁面連結,這樣便於區分不同的選單。
然後呼叫微信公眾號建立選單列表url,傳送post請求即可建立:
public static final String WX_CREATE_MENU = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN";