java 后台设置代理不能推送消息


(Kaller) #1
private JPushClient jpushClient;
    
    private JPushClient getJPushClient(){
        if(jpushClient==null){
            ClientConfig clientConfig = ClientConfig.getInstance();
            HttpProxy proxy=new HttpProxy(proxyHost,proxyPort);
            jpushClient = new JPushClient(masterSecret,appKey, proxy,clientConfig);
            String authCode = ServiceHelper.getBasicAuthorization(appKey,masterSecret);
            ApacheHttpClient httpClient = new ApacheHttpClient(authCode, proxy,clientConfig);
            jpushClient.getPushClient().setHttpClient(httpClient);
            return jpushClient;
        }else {
            return jpushClient;
        }
    }

配置代理如上,之前没设置代理

private JPushClient getJPushClient(){
        if(jpushClient==null){
            ClientConfig clientConfig = ClientConfig.getInstance();
            jpushClient = new JPushClient(masterSecret,appKey, null,clientConfig);
            return jpushClient;
        }else {
            return jpushClient;
        }
    }

这样都是可以发送的


#2

配置代理的问题自己解决,极光对网络的需求:端口 443,域名不被防火墙屏蔽,如需 host 绑定某 IP,对外公开的 IP 地址不保证一直有效


(Kaller) #3

公司走代理访问其他第3方平台,talkingdata、七牛云 都可以访问的,就是极光访问不行,看看是不是代理代码写的问题,有成功的代理推送样例吗?


(KenChoi) #4
if (proxy != null) {
            _proxy = new HttpHost(proxy.getHost(), proxy.getPort());
        }
 ...

 private void configHttpRequest(HttpRequestBase httpRequestBase) {
        RequestConfig requestConfig;
        if (_proxy != null) {
            requestConfig = RequestConfig.custom()
                    .setConnectionRequestTimeout(_connectionRequestTimeout)
                    .setConnectTimeout(_connectionTimeout)
                    .setSocketTimeout(_socketTimeout)
                    .setProxy(_proxy)
                    .build();
        } else {
            requestConfig = RequestConfig.custom()
                    .setConnectionRequestTimeout(_connectionRequestTimeout)
                    .setConnectTimeout(_connectionTimeout)
                    .setSocketTimeout(_socketTimeout)
                    .build();
        }

        httpRequestBase.setConfig(requestConfig);
    }

(Kaller) #5

你应该是误会我意思了,我不是指http代理写的问题,我是指jpushClient设置代理


(Kaller) #6

你上面提供的是在极光jar包已经封装好了的


(KenChoi) #7

JPushClient 设置代理实际上就是 HttpClient 设置代理。


(Kaller) #8

所以我这样写是对的是吗, 现在发送返回:{“msg_id”:0,“sendno”:0,“statusCode”:0} msg_id为0,正常是不会为0的


#9

msgid 为0 ,你没有真正的请求成功,极光服务器并没有收到你的请求。