微信公众号调用客服接口发送信息
2017-04-13 13:53
393 查看
public void customSend(String content,String openId,String accessToken){ JSONObject json=new JSONObject(); JSONObject text=new JSONObject(); text.element("content", content); json.element("touser", openId); json.element("text", text); json.element("msgtype", "text"); PrintWriter out = null; BufferedReader in = null; String result = ""; try { URL realUrl = new URL("https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token="+accessToken); // 打开和URL之间的连接 URLConnection conn = realUrl.openConnection(); // 设置通用的请求属性 conn.setRequestProperty("accept", "*/*"); conn.setRequestProperty("connection", "Keep-Alive"); conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); // 发送POST请求必须设置如下两行 conn.setDoOutput(true); conn.setDoInput(true); // 获取URLConnection对象对应的输出流 out = new PrintWriter(conn.getOutputStream()); // 发送请求参数 out.print(json.toString()); // flush输出流的缓冲 out.flush(); // 定义BufferedReader输入流来读取URL的响应 in = new BufferedReader( new InputStreamReader(conn.getInputStream())); String line; while ((line = in.readLine()) != null) { result += line; } System.out.println("客服消息result:"+result); } catch (Exception e) { System.out.println("向客服发送 POST 请求出现异常!"+e); e.printStackTrace(); } //使用finally块来关闭输出流、输入流 finally{ try{ if(out!=null){ out.close(); } if(in!=null){ in.close(); } } catch(IOException ex){ ex.printStackTrace(); } } }
相关文章推荐
- php调用微信客服消息接口给用户发送信息
- C# 调用微信公众号接口发送客服消息示例
- 微信公众号多客服功能的实现--向指定客服发送信息
- 微信公众号客服接口升级 支持第三方平台调用
- 微信公众号 调用客服接口实现图文推送实例、
- 调用微信公众号现金红包接口给用户发送红包
- 微信公众号平台接口开发:发送客服消息
- C# 调用微信公众号接口获取会员信息示例
- 微信支付配置信息,JSAPI接口,H5调用微信js接口支付,微信公众号支付
- 微信公众号网页能够访问,但注册信息发送不到配置好的接口
- 微信公众号客服接口给指定用户openid发送消息
- 调用微信公众号现金红包接口给用户发送红包
- 微信支付配置信息,JSAPI接口,H5调用微信js接口支付,微信公众号支付
- android 中调用接口发送短信
- android 中调用接口发送短信
- Python调用飞信接口发送短信
- 调用系统发送短信、邮件等信息功能
- 中国网建SMS短信接口调用(java发送和接收手机短信)
- android中可以通过两种方式调用接口发送短信
- 微信公众平台开发(73) 客服接口发送客服消息