//请求微信自定义菜单
var date = new PushWxMenuDto();
date.button = new List<WxMenuDto>();
var meuns = BulidTreeForWeiXin(adminWeiXinMenuList, 0);
date.button.AddRange(meuns);
var postDate = JsonConvert.SerializeObject(date);
//获取微信token
var _access_token = WeiXin.AdminMessage.BaseAdminSendMessage.Get_Access_token();
//调用微信创建菜单接口
var url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + _access_token;
var results = WebServiceApi.PostServer(url, postDate);
var wxResult = JsonConvert.DeserializeObject<ResultMsg>(results);
/// <summary>
/// 发布公众号菜单实体对象
/// </summary>
public class PushWxMenuDto
{
public List<WxMenuDto> button { get; set; }
}
/// <summary>
/// 一级菜单
/// </summary>
public class WxMenuDto
{
/// <summary>
/// 菜单类型
/// </summary>
public string type { get; set; }
/// <summary>
/// 菜单名称
/// </summary>
public string name { get; set; }
/// <summary>
/// 菜单链接
/// </summary>
public string url { get; set; }
/// <summary>
/// 子菜单
/// </summary>
public List<WxMenuDto> sub_button { get; set; }
}
/// <summary>
/// 微信消息发送返回的对象
/// https://mp.weixin.qq.com/advanced/tmplmsg?action=faq&token=656247441&lang=zh_CN
/// </summary>
[DataContract]
public class ResultMsg
{
/// <summary>
/// 0为成功
/// </summary>
[DataMember]
public string errcode { get; set; }
[DataMember]
public string errmsg { get; set; }
}