@Override
    public SyncCheckRet syncCheck() {
        String url = String.format("%s/synccheck", bot.session().getSyncOrUrl());
        try {
            ApiResponse response = this.client.send(new StringRequest(url)
                    .add("r", System.currentTimeMillis())
                    .add("skey", bot.session().getSKey())
                    .add("sid", bot.session().getWxSid())
                    .add("uin", bot.session().getWxUin())
                    .add("deviceid", bot.session().getDeviceId())
                    .add("synckey", bot.session().getSyncKeyStr())
                    .add("_", System.currentTimeMillis())
                    .timeout(30)
            );

            Matcher matcher = SYNC_CHECK_PATTERN.matcher(response.getRawBody());
            if (matcher.find()) {
                if (!"0".equals(matcher.group(1))) {
                    log.debug("Unexpected sync check result: {}", response.getRawBody());
                    return new SyncCheckRet(RetCode.parse(Integer.valueOf(matcher.group(1))), 0);
                }
                return new SyncCheckRet(RetCode.parse(Integer.valueOf(matcher.group(1))), Integer.valueOf(matcher.group(2)));
            }
            return new SyncCheckRet(RetCode.UNKNOWN, 0);
        } catch (Exception e) {
            if (e instanceof SocketTimeoutException) {
                log.warn("心跳检查超时");
                return syncCheck();
            }
            log.error("心跳检查出错", e);
            return new SyncCheckRet(RetCode.UNKNOWN, 0);
        }
    }
@Override
    public SyncCheckRet syncCheck() {
        String url = String.format("%s/synccheck", bot.session().getSyncOrUrl());
        try {
            ApiResponse response = this.client.send(new StringRequest(url)
                    .add("r", System.currentTimeMillis())
                    .add("skey", bot.session().getSKey())
                    .add("sid", bot.session().getWxSid())
                    .add("uin", bot.session().getWxUin())
                    .add("deviceid", bot.session().getDeviceId())
                    .add("synckey", bot.session().getSyncKeyStr())
                    .add("_", System.currentTimeMillis())
                    .timeout(30)
            );

            Matcher matcher = SYNC_CHECK_PATTERN.matcher(response.getRawBody());
            if (matcher.find()) {
                if (!"0".equals(matcher.group(1))) {
                    log.debug("Unexpected sync check result: {}", response.getRawBody());
                    return new SyncCheckRet(RetCode.parse(Integer.valueOf(matcher.group(1))), 0);
                }
                return new SyncCheckRet(RetCode.parse(Integer.valueOf(matcher.group(1))), Integer.valueOf(matcher.group(2)));
            }
            return new SyncCheckRet(RetCode.UNKNOWN, 0);
        } catch (Exception e) {
            if (e instanceof SocketTimeoutException) {
                log.warn("心跳检查超时");
                return syncCheck();
            }
            log.error("心跳检查出错", e);
            return new SyncCheckRet(RetCode.UNKNOWN, 0);
        }
    }
@ Override public SyncCheckRet syncCheck ( ) { String url = String . format ( "%s/synccheck" , bot . session ( ) . getSyncOrUrl ( ) ) ; try { ApiResponse response = this . client . send ( new StringRequest ( url ) . add ( "r" , System . currentTimeMillis ( ) ) . add ( "skey" , bot . session ( ) . getSKey ( ) ) . add ( "sid" , bot . session ( ) . getWxSid ( ) ) . add ( "uin" , bot . session ( ) . getWxUin ( ) ) . add ( "deviceid" , bot . session ( ) . getDeviceId ( ) ) . add ( "synckey" , bot . session ( ) . getSyncKeyStr ( ) ) . add ( "_" , System . currentTimeMillis ( ) ) . timeout ( 30 ) ) ; Matcher matcher = SYNC_CHECK_PATTERN . matcher ( response . getRawBody ( ) ) ; if ( matcher . find ( ) ) { if ( ! "0" . equals ( matcher . group ( 1 ) ) ) { log . debug ( "Unexpected sync check result: {}" , response . getRawBody ( ) ) ; return new SyncCheckRet ( RetCode . parse ( Integer . valueOf ( matcher . group ( 1 ) ) ) , 0 ) ; } return new SyncCheckRet ( RetCode . parse ( Integer . valueOf ( matcher . group ( 1 ) ) ) , Integer . valueOf ( matcher . group ( 2 ) ) ) ; } return new SyncCheckRet ( RetCode . UNKNOWN , 0 ) ; } catch ( Exception e ) { if ( e instanceof SocketTimeoutException ) { log . warn ( "心跳检查超时"); return syncCheck ( ) ; } log . error ( "心跳检查出错", e); return new SyncCheckRet ( RetCode . UNKNOWN , 0 ) ; } }
心跳检查

@return SyncCheckRet
心跳检查