我是靠谱客的博主 大力机器猫,最近开发中收集的这篇文章主要介绍java微信消息发送消息_JAVA模拟微信消息发送请求,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

JavaWeb模拟微信(网页版)发送消息到好友。PS:不是公众号,是好友之间,或者发送到群。

1、发送文字消息到好友,或群。

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);

}

}

最后

以上就是大力机器猫为你收集整理的java微信消息发送消息_JAVA模拟微信消息发送请求的全部内容,希望文章能够帮你解决java微信消息发送消息_JAVA模拟微信消息发送请求所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(52)

评论列表共有 0 条评论

立即
投稿
返回
顶部