String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + Appid() + "&secret=" + Secret()
String json = IOUtils.toString(new URL(url).openStream())
System.out.println("读取access token:"+json)
HttpURLConnection connection = (HttpURLConnection) new URL("https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" + 刚刚获得accessToken).openConnection()
connection.setRequestProperty("accept", "*/*")
connection.setRequestProperty("connection", "Keep-Alive")
connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)")
connection.setDoOutput(true)
connection.setDoInput(true)
connection.getOutputStream().write(("{\"touser\":\"" + 用户的openid + "\",\"msgtype\":\"text\",\"text\":{\"content\":\"" + 要发送的消息 + "\"}}").getBytes("utf-8"))
connection.getOutputStream().flush()
IOUtils.toString(connection.getInputStream())