/**
* 微信公眾號(hào)菜單 view 模式
*
* @author cdj
* @date 2018年7月26日 下午2:02:57
*/
public class ViewEntity {
public String type;
public String name;
public String url;
public ViewEntity() {
super();
// TODO Auto-generated constructor stub
}
public ViewEntity(String type, String name, String url) {
super();
this.type = type;
this.name = name;
this.url = url;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}
/**
* 微信公眾號(hào)多級(jí)菜單按鈕實(shí)體類
*
* @author cdj
* @date 2018年7月26日 下午2:08:40
*/
public class MenuEntity {
public String name;
/**下級(jí)菜單按鈕 集合 */
public List
寫(xiě)一個(gè)工具類直接獲json,zl
import java.util.ArrayList;
import java.util.List;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.modou.park.entity.wechat.MenuEntity;
import com.modou.park.entity.wechat.ViewEntity;
/**
* 微信公眾號(hào)獲取button創(chuàng)建
* @author cdj
* @date 2018年7月26日 下午2:22:02
*/
public class WxCreateButtonUtils {
/**
* 獲得微信公眾號(hào)菜單
* @return
*/
public static String getWxCreateButtonJson() {
JSONObject jsonObject = new JSONObject();
List lobjs = new ArrayList<>();
List firstvl = new ArrayList<>();
ViewEntity infoEntity = new ViewEntity("view", "個(gè)人信息", "http://www.xxx.com/xxxxxxxxx.html");//寫(xiě)自己的要跳轉(zhuǎn)的url
firstvl.add(infoEntity);
MenuEntity thirdEntity = new MenuEntity("我的",firstvl);
lobjs.add(thirdEntity);
jsonObject.put("button", lobjs);
System.out.println(jsonObject);
return JSON.toJSONString(jsonObject);
}
}