Giter Site home page Giter Site logo

wechat-api's Introduction

wechat-api

wechat-api 是微信个人号的Java版本API,让个人号具备更多能力,提供方便的接口调用。

在线文档

@biezhi on zhihu

特性

  • 使用简单,引入依赖即可
  • 支持本地图片和终端输出二维码
  • 本地自动登录
  • 支持文本、图片、视频、撤回消息等
  • 支持发送文本、图片、附件
  • 注解绑定消息监听
  • 群聊、单聊支持
  • 添加好友验证
  • 撤回消息获取
  • JDK7+

使用

本地开发的同学请先安装 lombok 插件并确保你的JDK环境是1.7+

引入 maven 依赖

<dependency>
    <groupId>io.github.biezhi</groupId>
    <artifactId>wechat-api</artifactId>
    <version>1.0.6</version>
</dependency>

构建自己的小机器人

public class HelloBot extends WeChatBot {
    
    public HelloBot(Config config) {
        super(config);
    }
    
    @Bind(msgType = MsgType.TEXT)
    public void handleText(WeChatMessage message) {
        if (StringUtils.isNotEmpty(message.getName())) {
            log.info("接收到 [{}] 的消息: {}", message.getName(), message.getText());
            this.sendMsg(message.getFromUserName(), "自动回复: " + message.getText());
        }
    }
    
    public static void main(String[] args) {
        new HelloBot(Config.me().autoLogin(true).showTerminal(true)).start();
    }
    
}

Bot API

/**
 * 给文件助手发送消息
 *
 * @param msg 消息内容
 * @return 发送是否成功
 */
boolean sendMsgToFileHelper(String msg);

/**
 * 给某个用户发送消息
 *
 * @param name 用户UserName
 * @param msg  消息内容
 * @return 发送是否成功
 */
boolean sendMsg(String name, String msg);

/**
 * 根据名称发送消息
 *
 * @param name 备注或昵称,精确匹配
 * @param msg  消息内容
 * @return 发送是否成功
 */
boolean sendMsgByName(String name, String msg);

/**
 * 给某个用户发送图片消息
 *
 * @param name    用户UserName
 * @param imgPath 图片路径
 * @return 发送是否成功
 */
boolean sendImg(String name, String imgPath);

/**
 * 根据名称发送图片消息
 *
 * @param name    备注或昵称,精确匹配
 * @param imgPath 图片路径
 * @return 发送是否成功
 */
boolean sendImgName(String name, String imgPath);

/**
 * 给用户发送文件
 *
 * @param name     用户UserName
 * @param filePath 文件路径
 * @return 发送是否成功
 */
boolean sendFile(String name, String filePath);

/**
 * 根据名称发送文件消息
 *
 * @param name     备注或昵称,精确匹配
 * @param filePath 文件路径
 * @return 发送是否成功
 */
boolean sendFileName(String name, String filePath);

更多API见文档

TODO

  1. 接收位置
  2. 撤回消息查看
  3. 发送文件消息
  4. 多线程处理消息

开源协议

MIT

wechat-api's People

Contributors

avrilmaomao avatar hellokaton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wechat-api's Issues

群消息接收不到,是什么情况?

listen方法有个while一直在无条件循环,当我在微信退出登录后,软件直接不停的提示在别处登录。但是正常登录又收不到消息?

关于api_key和api-secret

// 这里的api_key和api_secret可以自己申请一个
private final String KEY = "?api_key=你的api_key&api_secret=你的api_secret";

请问 api_key和api-secret 是可以向腾讯申请吗?

Myeclipse 里 运行 为啥什么都没有

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building wechat-robot 0.0.2
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> tomcat-maven-plugin:1.1:run (default-cli) > compile @ wechat-robot >>>
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ wechat-robot ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ wechat-robot ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] <<< tomcat-maven-plugin:1.1:run (default-cli) < compile @ wechat-robot <<<
[INFO]
[INFO] --- tomcat-maven-plugin:1.1:run (default-cli) @ wechat-robot ---
[INFO] Skipping non-war project
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.303 s
[INFO] Finished at: 2017-03-06T17:38:31+08:00
[INFO] Final Memory: 12M/150M
[INFO] ------------------------------------------------------------------------

链接

README的图片挂掉了

有使用demo

比如加好友,同意好友,加群,我在代码里面貌似都没找到.

二维码显示不了

我申请了机器人,然后运行程序,但是二维码生成不成功,请问这是咋回事?

收到一条好友消息就异常

Exception in thread "main" java.lang.NullPointerException
at io.github.biezhi.wechat.Utils.unicodeToUtf8(Utils.java:138)
at io.github.biezhi.wechat.api.WechatApi.wxSendMessage(WechatApi.java:724)
at io.github.biezhi.wechat.api.WechatApi.sendText(WechatApi.java:745)
at io.github.biezhi.wechat.model.UserMessage.sendText(UserMessage.java:113)
at io.github.biezhi.wechat.robot.TulingRobot.userMessage(TulingRobot.java:46)
at io.github.biezhi.wechat.ui.StartUI.handle_msg(StartUI.java:254)
at io.github.biezhi.wechat.ui.StartUI.handle(StartUI.java:352)
at io.github.biezhi.wechat.ui.StartUI.listen(StartUI.java:140)
at io.github.biezhi.wechat.ui.StartUI.start(StartUI.java:119)
at io.github.biezhi.wechat.Application.main(Application.java:22)
@biezhi

自己补充了个图片发送的,不成功,大神帮忙看看,谢谢

/**
 * 发送图片
 */
int fileID=0;
private void webwxsendimg(WechatMeta meta, File file, String to) {
	String url ="https://file.wx.qq.com/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json";
	String ID="WU_FILE_"+fileID;
    fileID++;
    String[] ck=meta.getCookie().trim().split(";");
    String webwx_data_ticket="";
    for(int s=0;s<ck.length;s++){
    	if(ck[s].contains("webwx_data_ticket")){
    		System.out.println(ck[s]);
    	webwx_data_ticket=ck[s].trim().substring(ck[s].indexOf("webwx_data_ticket")+18);
    	}
    }
    if(webwx_data_ticket.equals("")){System.out.println("webwx_data_ticket   is   null");return;}
	String clientMsgId = DateKit.getCurrentUnixTime() + StringKit.getRandomNumber(5);
	Date currentTime =new Date(file.lastModified()+1000*60*60*8);
    SimpleDateFormat sdf =new SimpleDateFormat("EEE MMM d yyyy HH:mm:ss 'GMT+0800'", Locale.US);  
	sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
	String lastModified=sdf.format(currentTime);
	JSONObject body = new JSONObject();
	StringBuffer sbr=new StringBuffer();
	JSONObject Msg = new JSONObject();
    String fegenum="-----------------------------"+"00content0boundary00"+"\r\n";
    String end="---------------------------"+"00content0boundary00"+"--\r\n";
	body.put("UploadType", 2);
	body.put("BaseRequest", meta.getBaseRequest());
	body.put("ClientMediaId", clientMsgId);
	body.put("TotalLen", file.length());
	body.put("StartPos", 0);
	body.put("DataLen", file.length());
	body.put("MediaType", 4);
	body.put("FromUserName", meta.getUser().getString("UserName"));
	body.put("ToUserName", to);
    try {
		body.put("FileMd5", getMd5ByFile(file));
	} catch (FileNotFoundException e) {
		// TODO 自动生成的 catch 块
		e.printStackTrace();
	}
	
	
    sbr=sbr.append(fegenum);
    sbr=sbr.append("Content-Disposition: form-data; name=\"id\"\r\n\r\n");
    sbr=sbr.append(ID+"\r\n");
    sbr=sbr.append(fegenum);
    sbr=sbr.append("Content-Disposition: form-data; name=\"name\"\r\n\r\n");
    sbr=sbr.append(file.getName()+"\r\n");
    sbr=sbr.append(fegenum);
    sbr=sbr.append("Content-Disposition: form-data; name=\"type\"\r\n\r\n");
    sbr=sbr.append("image/png\r\n");
    sbr=sbr.append(fegenum);
    sbr=sbr.append("Content-Disposition: form-data; name=\"lastModifiedDate\"\r\n\r\n");
    sbr=sbr.append(lastModified+"\r\n\r\n");
    sbr=sbr.append(fegenum);
    sbr=sbr.append("Content-Disposition: form-data; name=\"size\"\r\n\r\n");
    sbr=sbr.append(file.length()+"\r\n");
    sbr=sbr.append(fegenum);
    sbr=sbr.append("Content-Disposition: form-data; name=\"mediatype\"\r\n\r\n");
    sbr=sbr.append("pic\r\n");
    sbr=sbr.append(fegenum);
    sbr=sbr.append("Content-Disposition: form-data; name=\"uploadmediarequest\"\r\n\r\n");
    sbr=sbr.append(body.toString()+"\r\n");
    sbr=sbr.append(fegenum);
    sbr=sbr.append("Content-Disposition: form-data; name=\"webwx_data_ticket\"\r\n\r\n");
    sbr=sbr.append(webwx_data_ticket+"\r\n");
    sbr=sbr.append(fegenum);
    sbr=sbr.append("Content-Disposition: form-data; name=\"pass_ticket\"\r\n\r\n");
    sbr=sbr.append(meta.getPass_ticket()+"\r\n");
    sbr=sbr.append(fegenum);
    sbr=sbr.append("Content-Disposition: form-data; name=\"filename\"; filename=\""+file.getName()+"\"\r\nContent-Type: image/png\r\n\r\n");
    System.out.println(sbr);
	final InputStream stream;
	long lenth=file.length();
	byte[] imgbyte=null;
	try {
		imgbyte=readFileImage(file);
	} catch (IOException e1) {
		// TODO 自动生成的 catch 块
		e1.printStackTrace();
	}
	byte[] sbrbyte=sbr.toString().getBytes();
	byte[] endbyte=end.getBytes();
    int ne=sbrbyte.length+imgbyte.length+endbyte.length;
    byte[] ne1=new byte[ne];
    System.arraycopy(sbrbyte, 0, ne1, 0, sbrbyte.length);
    System.arraycopy(imgbyte, 0, ne1, sbrbyte.length, imgbyte.length);
    System.arraycopy(endbyte, 0, ne1, sbrbyte.length+imgbyte.length, endbyte.length);
    System.out.println(new String(ne1));
    HttpsURLConnection connection=(new HttpsGetData(url)).getpostcon();
    connection.setRequestProperty("contentType","multipart/form-data; boundary=---------------------------00content0boundary00");
    OutputStream output;
    try {
		output=connection.getOutputStream();
		 output.write(sbrbyte);
		 output.write(imgbyte);
		 output.write(endbyte);
		 output.flush();
		 BufferedReader in = new BufferedReader(new InputStreamReader(  
                    connection.getInputStream()));  
            String line;  
            while ((line = in.readLine()) != null) {  
                System.out.println(line);  
                }
            in.close();
            output.close();
	} catch (IOException e) {
		// TODO 自动生成的 catch 块
		e.printStackTrace();
	}
   
	/*HttpRequest request = HttpRequest.post(url).contentType("multipart/form-data; boundary=---------------------------00content0boundary00")
			.send(file);
 
	LOGGER.info("发送消息...");
	LOGGER.debug("" + request);
	String jj=request.body();
	System.out.println("ddddddddddddd     "+jj);
	request.disconnect();*/

}

直接运行Application报空指针错误

Exception in thread "main" java.lang.NullPointerException at io.github.biezhi.wechat.event.EventManager.<init>(EventManager.java:20) at io.github.biezhi.wechat.WechatRobot.<init>(WechatRobot.java:30) at io.github.biezhi.wechat.Application.main(Application.java:15)

获取联系人时找不到指定路径?

java.io.IOException: 系统找不到指定的路径。
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(File.java:1012)
at me.cncoder.record.RecordCon.writeCon(RecordCon.java:23)
at me.biezhi.wechat.WechatRobot.start(WechatRobot.java:181)
at me.biezhi.wechat.Application.main(Application.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
java.io.FileNotFoundException: record@f7a7c5a106a59239acb0fb58256a072f0335bb54491ef7dbafe78d00567ac606.json (系统找不到指定的路径。)

无法取得群信息

getContact里面调用的getGroup方法无法取得群信息,返回1200,不知道怎么回事。

请问语音消息的接收解决了吗?

在接收到语音消息后提取MsgId,然后根据url(getvoice)请求到的response的Content-length是0,请问这个问题您解决了没有?
另外还有相同情况的问题就是获取头像(geticon),以及获取图片的时候(getimg)

接收到消息之后出现NullPointerException

Java1.8的环境下,接收到消息之后 提示:
2017-06-21 17:34:25.237 [main] INFO io.github.biezhi.wechat.ui.StartUI - 7549854419365009049 未知_fmessage -> Ena: null

Exception in thread "main" java.lang.NullPointerException
at io.github.biezhi.wechat.Utils.unicodeToUtf8(Utils.java:138)
at io.github.biezhi.wechat.api.WechatApi.wxSendMessage(WechatApi.java:724)
at io.github.biezhi.wechat.api.WechatApi.sendText(WechatApi.java:745)
at io.github.biezhi.wechat.model.UserMessage.sendText(UserMessage.java:113)
at io.github.biezhi.wechat.robot.TulingRobot.userMessage(TulingRobot.java:46)
at io.github.biezhi.wechat.ui.StartUI.handle_msg(StartUI.java:254)
at io.github.biezhi.wechat.ui.StartUI.handle(StartUI.java:352)
at io.github.biezhi.wechat.ui.StartUI.listen(StartUI.java:140)
at io.github.biezhi.wechat.ui.StartUI.start(StartUI.java:119)
at io.github.biezhi.wechat.Application.main(Application.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

Exception in thread "listenMsgMode" blade.kit.http.HttpRequestException:

Exception in thread "listenMsgMode" blade.kit.http.HttpRequestException: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
at blade.kit.http.HttpRequest.send(HttpRequest.java:2608)
at me.biezhi.weixin.App.webwxsync(App.java:447)
at me.biezhi.weixin.App$2.run(App.java:572)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:980)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1363)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1391)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1375)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1282)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1257)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
at blade.kit.http.HttpRequest.openOutput(HttpRequest.java:2297)
at blade.kit.http.HttpRequest.send(HttpRequest.java:2605)
... 3 more
Caused by: java.io.EOFException: SSL peer shut down incorrectly
at sun.security.ssl.InputRecord.read(InputRecord.java:505)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:961)
... 13 more

大神,在麻烦您一下,,Python实在看不懂~~

def webwxsendmsgimg(self, user_id, media_id):
url = 'https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxsendmsgimg?fun=async&f=json&pass_ticket=%s' % self.pass_ticket
clientMsgId = str(int(time.time() * 1000)) +
str(random.random())[:5].replace('.', '')
data_json = {
"BaseRequest": self.BaseRequest,
"Msg": {
"Type": 3,
"MediaId": media_id,
"FromUserName": self.User['UserName'],
"ToUserName": user_id,
"LocalID": clientMsgId,
"ClientMsgId": clientMsgId
}
}
headers = {'content-type': 'application/json; charset=UTF-8'}
data = json.dumps(data_json, ensure_ascii=False).encode('utf8')
r = requests.post(url, data=data, headers=headers)
dic = r.json()
return dic['BaseResponse']['Ret'] == 0
实在没看懂他把图片文件怎么POST出去的,URL,Headers,Data,没包含图片数据啊,大神指点一下万分感谢

wechat-listener-thread 报错

Exception in thread "wechat-listener-thread" com.blade.kit.http.HttpRequestException: java.io.IOException: Invalid Http response
at com.blade.kit.http.HttpRequest.stream(HttpRequest.java:1303)
at com.blade.kit.http.HttpRequest.buffer(HttpRequest.java:1288)
at com.blade.kit.http.HttpRequest.body(HttpRequest.java:1209)
at com.blade.kit.http.HttpRequest.body(HttpRequest.java:1224)
at me.biezhi.wechat.service.WechatServiceImpl.syncCheck(WechatServiceImpl.java:337)
at me.biezhi.wechat.service.WechatServiceImpl.syncCheck(WechatServiceImpl.java:303)
at me.biezhi.wechat.listener.WechatListener$1.run(WechatListener.java:24)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.IOException: Invalid Http response
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1926)
at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1921)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1920)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1490)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at com.blade.kit.http.HttpRequest.stream(HttpRequest.java:1301)
... 7 more
Caused by: java.io.IOException: Invalid Http response
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1588)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(HttpURLConnection.java:2982)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getHeaderField(HttpsURLConnectionImpl.java:291)
at com.blade.kit.http.HttpRequest.header(HttpRequest.java:1593)
at com.blade.kit.http.HttpRequest.parameter(HttpRequest.java:1732)
at com.blade.kit.http.HttpRequest.charset(HttpRequest.java:1839)
... 5 more

Process finished with exit code 0

Login related question

It runs very well. Not sure how to use it with my wechat account. Should I replace the appid and the password of my own in the following code? If true, do I need to encode it? If so, how?

HttpRequest request = HttpRequest.get(Constant.JS_LOGIN_URL, true, "appid", "wx782c26e4c19acffb", "fun", "new","lang", "zh_CN", "_", DateKit.getCurrentUnixTime());

Clone到本地IDEA后运行出现一下错误,求解

log4j:WARN No appenders could be found for logger (com.blade.kit.base.Config).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
java.lang.IllegalStateException: InputStream not found: config.properties
at com.blade.kit.base.Config.loadInputStream(Config.java:137)
at com.blade.kit.base.Config.loadClasspath(Config.java:106)
at com.blade.kit.base.Config.loadLoaction(Config.java:68)
at com.blade.kit.base.Config.load(Config.java:62)
at me.biezhi.wechat.Application.main(Application.java:10)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

编译报错

objc[2085]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/java (0x109fd24c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10a0ae4e0). One of the two will be used. Which one is undefined.

关于心跳检测问题

版主你好,我在使用该微信网页版java代码时,遇到 在心跳检测时 private int[] syncCheck(String url, WechatMeta meta),经常会出现无返回的情况,程序死到这个方法,网络无返回。这个问题不知道如何解决,我也设置了超时时间
HttpRequest request = HttpRequest.get(url, true, "r", DateKit.getCurrentUnixTime() + StringKit.getRandomNumber(5), "skey",meta.getSkey(), "uin", meta.getWxuin(), "sid", meta.getWxsid(), "deviceid",meta.getDeviceId(), "synckey", meta.getSynckey(), "_", System.currentTimeMillis())
.header("Cookie", meta.getCookie());

		request.connectTimeout(DEF_CONN_TIMEOUT);
		request.readTimeout(DEF_CONN_TIMEOUT);

		String res = request.body();
		request.disconnect();

在linux下使用过一段时间就出现错误

Exception in thread "listenMsgMode" blade.kit.http.HttpRequestException: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
at blade.kit.http.HttpRequest.send(HttpRequest.java:2608)
at com.everydayratings.util.WeChatRobot.webwxsync(WeChatRobot.java:516)
at com.everydayratings.util.WeChatRobot$1.run(WeChatRobot.java:670)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1343)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1371)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1355)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1281)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1256)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
at blade.kit.http.HttpRequest.openOutput(HttpRequest.java:2297)
at blade.kit.http.HttpRequest.send(HttpRequest.java:2605)
... 3 more
Caused by: java.io.EOFException: SSL peer shut down incorrectly
at sun.security.ssl.InputRecord.read(InputRecord.java:505)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:954)
... 13 more

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.