JAVA模拟微信消息发送请求
来源:互联网 发布:原材料追溯软件 编辑:程序博客网 时间:2024/04/29 14:35
JavaWeb模拟微信(网页版)发送消息到好友。PS:不是公众号,是好友之间,或者发送到群。
1、发送文字消息到好友,或群。
1、登录微信网页版,使用firebug抓取发送文字的请求:https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxsendmsg
2、分析参数:
这里写图片描述
{\”BaseRequest\”:{\”Uin\”:123456,\”Sid\”:\”123456\”,\”Skey\”:\”@crypt_c799f4fc_7f98126a5836d9ed6fdbff40cd491c5f\”,\”DeviceID\”:\”e155964836553096\”},\”Msg\”:{\”Type\”:1,\”Content\”:\”hello\”,\”FromUserName\”:\”@abe6eb6ac61b71451c703f7126b8e454\”,\”ToUserName\”:\”abe6eb6ac61b71451c703f7126b8e454\”,\”LocalID\”:\”“+currentTimeMillis+”\”,\”ClientMsgId\”:\”“+currentTimeMillis+”\”}}
uin:表示微信帐号id,sid:每次会话生成新的,sky:每次会话生成新的,FromUserName:消息发送人,ToUserName:消息接收人,DeviceID:可重复
示例代码:
package com.klay.wewhat;import org.apache.http.HttpEntity;import org.apache.http.HttpResponse;import org.apache.http.HttpStatus;import org.apache.http.client.HttpClient;import org.apache.http.client.methods.HttpPost;import org.apache.http.entity.StringEntity;import org.apache.http.impl.client.DefaultHttpClient;import org.apache.http.message.BasicHeader;/** * send text * @author klay * */public class SendText { public static String requestUrl = "https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxsendmsg"; public static String cookie = ""; public static void sendMsg(String requestUrl,String cookie){ String url = "https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxsendmsg";//请求链接 HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url); post.addHeader(new BasicHeader("cookie", cookie)); //其实cookie可以不设置,也能发送 Long currentTimeMillis = System.currentTimeMillis(); String requestParam = "{\"BaseRequest\":{\"Uin\":You id,\"Sid\":\"EwwSa9Jb1fSGjQW1\",\"Skey\":\"@crypt_c799f4fc_7f98126a5836d9ed6fdbff40cd491c5f\",\"DeviceID\":\"e155964836553096\"},\"Msg\":{\"Type\":1,\"Content\":\"hello.J\",\"FromUserName\":\"@123\",\"ToUserName\":\"123\",\"LocalID\":\""+currentTimeMillis+"\",\"ClientMsgId\":\""+currentTimeMillis+"\"}}"; try { StringEntity s = new StringEntity(requestParam); post.setEntity(s); HttpResponse res = client.execute(post); if (res.getStatusLine().getStatusCode() == HttpStatus.SC_OK){ HttpEntity entity = res.getEntity(); } } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { sendMsg(requestUrl,cookie); }}
0 0
- JAVA模拟微信消息发送请求
- java 微信发送客服消息
- java微信开发发送消息
- Java 微信发送模板消息
- Java 微信发送模板消息
- 微信公众平台模拟登陆和发送消息详解
- 微信发送消息
- JAVA模拟发送HTTP请求
- nodejs微信开发测试,模拟微信事件、消息等请求
- 向微信发送消息
- 微信发送客服消息
- 微信发送模板消息
- 发送微信模板消息
- 微信模板消息发送
- 微信发送模板消息
- 微信发送文本消息
- 微信模板消息发送
- 微信定时发送消息
- 如何在lua中打印一个数组(table)
- PHP CLI 模式详解
- nodeJs mongodb凭据验证
- LintCode: 最大子数组
- 根据两点经纬坐标计算两点间的距离[JAVA]
- JAVA模拟微信消息发送请求
- c++类中静态函数不能调用类中的非静态函数原因
- MFC中两个对话框之间数据传递
- 工作总结-Xcode7中使用静态库环境配置手册
- Android解耦库EventBus的使用和源码分析
- Android VelocityTracker与GestureDetector使用简介
- Auto layout: Hundreds of warning and several errors
- ListView 里面的checkBox,当其中一个被选中,其余全不被选中
- 直方图均衡化