微信开发--Two.菜单生成

微信菜单生成有好几种方法,微信公众平台生成,模拟微信平台生成等

微信公众平台生成:就是在微信开发者中心,通过Json生成。参考:http://jingyan.baidu.com/article/6525d4b1376613ac7d2e94f8.html

模拟微信平台生成:在代码中模拟出Json数据,然后token等参数以get方式传给微信平台,实现菜单生成。

参考代码:

 //生成菜单
    private void CreateMenu()
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("{");
        sb.Append(@"""button"":[");


        sb.Append("{");
        sb.Append(@"""name"":""项目介绍"",");
        sb.Append(@"""sub_button"":").Append("[");
        sb.Append("{");
        sb.Append(@"""type"":").Append(@"""view"",");
        sb.Append(@"""name"":").Append(@"""君地半月湾"",");
        sb.Append(@"""url"":").Append(@"""ProjectDetail.aspx?SubMenu=M1001""");
        sb.Append("},");
        sb.Append("{");
        sb.Append(@"""type"":").Append(@"""view"",");
        sb.Append(@"""name"":").Append(@"""君地新大陆"",");
        sb.Append(@"""url"":").Append(@"""ProjectDetail.aspx?SubMenu=M1002""");
        sb.Append("},");
        sb.Append("{");
        sb.Append(@"""type"":").Append(@"""view"",");
        sb.Append(@"""name"":").Append(@"""君地曼哈顿"",");
        sb.Append(@"""url"":").Append(@"""ProjectDetail.aspx?SubMenu=M1003""");
        sb.Append("}");
        sb.Append("]");
        sb.Append("},");

        sb.Append("{");
        sb.Append(@"""type"":").Append(@"""view"",") ;
        sb.Append(@"""click"":").Append(@"""经纪人"",");
        sb.Append(@"""url"":").Append(@"""BrokerIndex.aspx""");
        sb.Append("},");

        sb.Append("{");
        sb.Append(@"""name"":").Append(@"""互动专区"",");
        sb.Append(@"""sub_button"":").Append("[");
        sb.Append("{");
        sb.Append(@"""type"":").Append(@"""view"",");
        sb.Append(@"""name"":").Append(@"""最新活动"",");
        sb.Append(@"""url"":").Append(@"""CampaignList.aspx""");
        sb.Append("},");
        sb.Append("{");
        sb.Append(@"""type"":").Append(@"""view"",");
        sb.Append(@"""name"":").Append(@"""意见与建议"",");
        sb.Append(@"""url"":").Append(@"""Feedback.aspx""");
        sb.Append("},");
        sb.Append("{");
        sb.Append(@"""type"":").Append(@"""view"",");
        sb.Append(@"""name"":").Append(@"""联系我们"",");
        sb.Append(@"""url"":").Append(@"""LinkUs.aspx""");
        sb.Append("},");
        sb.Append("{");
        sb.Append(@"""type"":").Append(@"""view"",");
        sb.Append(@"""name"":").Append(@"""娱乐主题"",");
        sb.Append(@"""url"":").Append(@"""Games.aspx""");
        sb.Append("}");
        sb.Append("]");
        sb.Append("}");


        sb.Append("]");
        sb.Append("}");
        string strMenu = sb.ToString();

        string token = "-Bf8ciEpx2f9fGCsSs0nGpi_unu9kzQMKutaItYgKS8qtGrQ3FOtuZlNOYUNbC1jNfvrsF34vq6Z84z6RWlK9A";
        string i = GetPage("https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + token, strMenu); 
}
View Code

 

注:只有获取了自定义菜单的接口权限,才能实现自定义菜单。经测试,测试的微信账号不能生成自定义菜单,之前是可以,现在提示权限不足。

posted @ 2014-10-09 11:15  步子521  阅读(183)  评论(0编辑  收藏  举报