微信公众平台菜单创建

直接贴代码


package com.kkxxbb;


import java.io.IOException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.PostMethod;


public class WeixinMenu

{
 
public static void main(String[] args){
String token ="你的token值";
String url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token="+token;
/**
* 设置菜单
*/
String responeJsonStr = "{"+
    "\"button\":["+
    "{"+
         "\"type\":\"click\","+
         "\"name\":\"来一段\","+
         "\"key\":\"KKXXBA_ALL\""+
     "},"+
     "{"+
          "\"name\":\"分类\","+
          "\"sub_button\":["+
           "{"+
              "\"type\":\"click\","+
              "\"name\":\"个性签名\","+
              "\"key\":\"KKXXBA_T1\""+
           "},"+
           "{"+
              "\"type\":\"click\","+
              "\"name\":\"哈哈笑话\","+
              "\"key\":\"KKXXBA_T2\""+
           "},"+
           "{"+
              "\"type\":\"click\","+
              "\"name\":\"开心段子\","+
              "\"key\":\"KKXXBA_T3\""+
           "}]"+
      "},"+
      "{"+
          "\"type\":\"click\","+
          "\"name\":\"关于我们\","+
          "\"key\":\"KKXXBA_ABOUT\""+
     "}]"+
"}";


HttpClient client = new HttpClient();
PostMethod post = new PostMethod(url);
post.setRequestBody(responeJsonStr);
post.getParams().setContentCharset("utf-8");
//发送http请求
String respStr = "";
try {
client.executeMethod(post);
respStr = post.getResponseBodyAsString();
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(responeJsonStr);
System.out.println(respStr);
}

}

加微信公众帐号:kkxxba  看效果


阅读更多
想对作者说点什么? 我来说一句

公众号创建菜单

2015年09月17日 2KB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭