JAVA 实现微信公众号菜单设置功能
以下为菜单类
请求外链接方法
public static String AccessUrl(String url, String postString) { String result = null; HttpURLConnection conn = null; try { URL postUrl = new URL(url); conn = (HttpURLConnection) postUrl.openConnection(); conn.setRequestMethod("POST"); conn.setDoOutput(true); conn.setDoInput(true); conn.setUseCaches(false); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); conn.setConnectTimeout(10000); conn.setReadTimeout(10000); OutputStream os = conn.getOutputStream(); os.write(postString.getBytes("UTF-8")); // 往远程URL传递参数 os.flush(); os.close(); int code = conn.getResponseCode(); conn.getHeaderFields(); conn.getContentLength(); if (code == 200) {// 返回成功 BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8")); String line; StringBuffer buffer = new StringBuffer(); while ((line = reader.readLine()) != null) { buffer.append(line); } result = buffer.toString(); } else { logger.error("返回失败:" + code); } } catch (MalformedURLException e) { logger.error("Exception:" + e.getMessage()); } catch (IOException e) { logger.error("Exception:" + e.getMessage()); }finally{ if(conn != null){ conn.disconnect(); conn=null; } } return result; }
上一篇:
uniapp开发微信小程序-2.页面制作
下一篇:
微信小程序深坑之bindtouchend