微信公众号的制作---测试号

来源:互联网 发布:淘宝卖什么暴利 编辑:程序博客网 时间:2024/05/24 13:28
1、注册微信公众号->开发工具->公众平台测试号->填写URL(Http://+公网地址+项目名)和Token(随便)->获取access_Token
(自己的) GET https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=?&secret=? (大写的改成自己)
appID
appsecret 
2、在浏览器中获取accessToken码,两小时失效,5分钟只能请求一次,一天只能请求200次
3、在公网测试并填取接口信息。
4、在浏览器访问按钮测试接口
1、测试用的接口
@RequestMapping("/authToken")
 @ResponseBody
public String wxTokenAuth(HttpServletRequest request){
  Map<String, String[]> param=request.getParameterMap();
  Set<String> keys=param.keySet();
  for(String key:keys){
   log.info(key+":"+Arrays.toString(param.get(key)));
  }
 return param.get("echostr")[0];
}
2、测试用的按钮接口Controller
@RequestMapping("/createMenu")
 @ResponseBody
 public String createMenu(){
  wxAuthService.createMenu();
  return "dddd";
 }
测试用的按钮Service
private final String ACCESS_TOKEN = "获取到的access_Token";
 @Override
 public boolean createMenu() {// 创建按钮
  HttpClientUtil util = new HttpClientUtil();
  JSONObject button = new JSONObject();
  JSONArray firstLevelButton = new JSONArray();
  JSONObject diyige = new JSONObject();// 第一个按钮
  JSONObject dierge = new JSONObject();// 第二个按钮
  JSONObject disange = new JSONObject();// 第三个按钮
  firstLevelButton.add(diyige);
  firstLevelButton.add(dierge);
  firstLevelButton.add(disange);
  diyige.put("type", "view");
  diyige.put("name", "首页");
  diyige.put("url", "http://111.231.85.115/testmaven/index/showIndex");
  dierge.put("type", "view");
  dierge.put("name", "鲜花");
  dierge.put("url", "http://111.231.85.115/testmaven/index/showClazzfy?id=10001&page=1");
  disange.put("type", "view");
  disange.put("name", "礼品");
  disange.put("url", "http://111.231.85.115/testmaven/index/showClazzfy?id=10004&page=1");
  button.put("button", firstLevelButton);
  Map<String, String> param = new HashMap<>();
  param.put("body", button.toJSONString());
  util.doPost("https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + ACCESS_TOKEN, button.toJSONString(),
    "UTF-8");
  return false;
 }

原创粉丝点击